Skip to content

Commit eead093

Browse files
committedOct 18, 2020
Use lodash instead of the deprecated utila
1 parent 60b6770 commit eead093

File tree

9 files changed

+92
-81
lines changed

9 files changed

+92
-81
lines changed
 

‎package-lock.json

+58-53
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"css-select": "^1.1.0",
88
"dom-converter": "^0.2",
99
"htmlparser2": "^3.3.0",
10-
"strip-ansi": "^3.0.0",
11-
"utila": "^0.4.0"
10+
"lodash": "^4.17.20",
11+
"strip-ansi": "^3.0.0"
1212
},
1313
"devDependencies": {
1414
"chai": "^4.1.2",

‎src/AnsiPainter.coffee

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
tools = require './tools'
22
tags = require './ansiPainter/tags'
33
styles = require './ansiPainter/styles'
4-
{object} = require 'utila'
54

65
module.exports = class AnsiPainter
76
@tags: tags

‎src/Layout.coffee

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Block = require './layout/Block'
2-
{object} = require 'utila'
2+
{cloneAndMergeDeep} = require './tools'
33
SpecialString = require './layout/SpecialString'
44
terminalWidth = require('./tools').getCols()
55

@@ -18,10 +18,10 @@ module.exports = class Layout
1818
constructor: (config = {}, rootBlockConfig = {}) ->
1919
@_written = []
2020
@_activeBlock = null
21-
@_config = object.append self._defaultConfig, config
21+
@_config = cloneAndMergeDeep self._defaultConfig, config
2222

2323
# Every layout has a root block
24-
rootConfig = object.append self._rootBlockDefaultConfig, rootBlockConfig
24+
rootConfig = cloneAndMergeDeep self._rootBlockDefaultConfig, rootBlockConfig
2525
@_root = new Block @, null, rootConfig, '__root'
2626
@_root._open()
2727

‎src/RenderKid.coffee

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
inlineStyleApplier = require './renderKid/styleApplier/inline'
22
blockStyleApplier = require './renderKid/styleApplier/block'
3+
isPlainObject = require 'lodash/isPlainObject'
4+
{cloneAndMergeDeep} = require './tools'
35
AnsiPainter = require './AnsiPainter'
46
Styles = require './renderKid/Styles'
57
Layout = require './Layout'
68
tools = require './tools'
7-
{object} = require 'utila'
89
stripAnsi = require 'strip-ansi'
910
terminalWidth = require('./tools').getCols()
1011

@@ -19,7 +20,7 @@ module.exports = class RenderKid
1920

2021
constructor: (config = {}) ->
2122
@tools = self.tools
22-
@_config = object.append self._defaultConfig, config
23+
@_config = cloneAndMergeDeep self._defaultConfig, config
2324
do @_initStyles
2425

2526
_initStyles: ->
@@ -37,7 +38,7 @@ module.exports = class RenderKid
3738
_toDom: (input) ->
3839
if typeof input is 'string'
3940
@_parse input
40-
else if object.isBareObject(input) or Array.isArray(input)
41+
else if isPlainObject(input) or Array.isArray(input)
4142
@_objToDom input
4243
else
4344
throw Error "Invalid input type. Only strings, arrays and objects are accepted"

‎src/layout/Block.coffee

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
SpecialString = require './SpecialString'
2-
{object} = require 'utila'
32
terminalWidth = require('../tools').getCols()
3+
{cloneAndMergeDeep} = require '../tools'
44

55
module.exports = class Block
66
self = @
@@ -32,7 +32,7 @@ module.exports = class Block
3232
suffixRaw: ''
3333

3434
constructor: (@_layout, @_parent, config = {}, @_name = '') ->
35-
@_config = object.append self.defaultConfig, config
35+
@_config = cloneAndMergeDeep self.defaultConfig, config
3636
@_closed = no
3737
@_wasOpenOnce = no
3838
@_active = no

‎src/renderKid/styleApplier/block.coffee

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
_common = require './_common'
2-
{object} = require 'utila'
2+
merge = require 'lodash/merge'
33

44
module.exports = blockStyleApplier = self =
55
applyTo: (el, style) ->
@@ -12,19 +12,19 @@ module.exports = blockStyleApplier = self =
1212

1313
_margins: (style, config) ->
1414
if style.marginLeft?
15-
object.appendOnto config, linePrependor:
15+
merge config, linePrependor:
1616
options: amount: parseInt style.marginLeft
1717

1818
if style.marginRight?
19-
object.appendOnto config, lineAppendor:
19+
merge config, lineAppendor:
2020
options: amount: parseInt style.marginRight
2121

2222
if style.marginTop?
23-
object.appendOnto config, blockPrependor:
23+
merge config, blockPrependor:
2424
options: amount: parseInt style.marginTop
2525

2626
if style.marginBottom?
27-
object.appendOnto config, blockAppendor:
27+
merge config, blockAppendor:
2828
options: amount: parseInt style.marginBottom
2929

3030
return
@@ -36,7 +36,7 @@ module.exports = blockStyleApplier = self =
3636
conf.alignment = style.bullet.alignment
3737
{before, after} = _common.getStyleTagsFor color: bullet.color, background: bullet.background
3838
conf.char = before + bullet.char + after
39-
object.appendOnto config, linePrependor:
39+
merge config, linePrependor:
4040
options: bullet: conf
4141

4242
return

‎src/tools.coffee

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
htmlparser = require 'htmlparser2'
2-
{object} = require 'utila'
32
{objectToDom} = require 'dom-converter'
3+
merge = require 'lodash/merge'
4+
cloneDeep = require 'lodash/cloneDeep'
5+
isPlainObject = require 'lodash/isPlainObject'
46

57
module.exports = self =
68
repeatString: (str, times) ->
@@ -10,10 +12,13 @@ module.exports = self =
1012

1113
output
1214

15+
cloneAndMergeDeep: (base, toAppend) ->
16+
merge cloneDeep(base), toAppend
17+
1318
toDom: (subject) ->
1419
if typeof subject is 'string'
1520
self.stringToDom subject
16-
else if object.isBareObject subject
21+
else if isPlainObject subject
1722
self._objectToDom subject
1823
else
1924
throw Error "tools.toDom() only supports strings and objects"
@@ -39,7 +44,7 @@ module.exports = self =
3944

4045
objectToDom: (o) ->
4146
unless Array.isArray(o)
42-
unless object.isBareObject(o)
47+
unless isPlainObject(o)
4348
throw Error "objectToDom() only accepts a bare object or an array"
4449

4550
self._fixQuotesInDom objectToDom o

‎test/layout/Block.coffee

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Layout = require '../../src/Layout'
2-
{object} = require 'utila'
2+
merge = require 'lodash/merge'
3+
{cloneAndMergeDeep} = require '../../src/tools'
34

45
{open, get, conf} = do ->
56
show = (layout) ->
@@ -10,7 +11,7 @@ Layout = require '../../src/Layout'
1011
linePrependor: options: amount: 2
1112

1213
c = (add = {}) ->
13-
object.append defaultBlockConfig, add
14+
cloneAndMergeDeep defaultBlockConfig, add
1415

1516
ret = {}
1617

@@ -29,22 +30,22 @@ Layout = require '../../src/Layout'
2930
ret.conf = (props) ->
3031
config = {}
3132
if props.left?
32-
object.appendOnto config, linePrependor: options: amount: props.left
33+
merge config, linePrependor: options: amount: props.left
3334

3435
if props.right?
35-
object.appendOnto config, lineAppendor: options: amount: props.right
36+
merge config, lineAppendor: options: amount: props.right
3637

3738
if props.top?
38-
object.appendOnto config, blockPrependor: options: amount: props.top
39+
merge config, blockPrependor: options: amount: props.top
3940

4041
if props.bottom?
41-
object.appendOnto config, blockAppendor: options: amount: props.bottom
42+
merge config, blockAppendor: options: amount: props.bottom
4243

4344
if props.width?
44-
object.appendOnto config, width: props.width
45+
merge config, width: props.width
4546

4647
if props.bullet is yes
47-
object.appendOnto config, linePrependor: options: bullet: {char: '-', alignment: 'left'}
48+
merge config, linePrependor: options: bullet: {char: '-', alignment: 'left'}
4849

4950
config
5051

0 commit comments

Comments
 (0)
Please sign in to comment.