Refactor, units, tests
This commit is contained in:
parent
519c34bc60
commit
cd90705ba1
24 changed files with 1221 additions and 1222 deletions
14
src/utils.js
14
src/utils.js
|
@ -2,7 +2,7 @@ const m = require('makerjs')
|
|||
|
||||
exports.deepcopy = (value) => JSON.parse(JSON.stringify(value))
|
||||
|
||||
const deep_assign = exports.deep_assign = (obj, key, val) => {
|
||||
const deep = exports.deep = (obj, key, val) => {
|
||||
const levels = key.split('.')
|
||||
const last = levels.pop()
|
||||
let step = obj
|
||||
|
@ -10,21 +10,11 @@ const deep_assign = exports.deep_assign = (obj, key, val) => {
|
|||
step[level] = step[level] || {}
|
||||
step = step[level]
|
||||
}
|
||||
if (val === undefined) return step[last]
|
||||
step[last] = val
|
||||
return obj
|
||||
}
|
||||
|
||||
const expand_nested_keys = exports.expand_nested_keys = (config) => {
|
||||
if (typeof config == 'object') {
|
||||
const result = {}
|
||||
for (const [key, val] of Object.entries(config)) {
|
||||
deep_assign(result, key, expand_nested_keys(val))
|
||||
}
|
||||
return result
|
||||
}
|
||||
return config
|
||||
}
|
||||
|
||||
const eq = exports.eq = (a=[], b=[]) => {
|
||||
return a[0] === b[0] && a[1] === b[1]
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue