-
Notifications
You must be signed in to change notification settings - Fork 8
Transform
James edited this page May 30, 2017
·
3 revisions
🤖 transform
🎼
tap a value with a function
new Chain()
.set('eh', 'eh')
.tap('eh', x => x + '!')
.get('eh') === 'eh!'
this replaced the previous .concat
and .append
in this simple example, when the existing value for key
is an array or a string, append val
to it
const {str, arr} = new Chain()
.set('str', 'emptyish')
.tap('str', str => str + '+')
.set('arr', [1])
.tap('arr', arr => arr.concat([2]))
.entries()
str == 'emptyish+'
arr == [1, 2]
const chain = new Chain()
.remapKeys()
.remapKey('dis', 'dat') // dis -> dat
.from({dis: 1, other: true})
.get('dat') === 1
- modified js-traverse
traverse any data type deeply, match values &||
keys, optional callback .onMatch
const eh = {
notme: 1,
nested: {
really: {
deep: {
super: false,
canada: true,
modules: [{parser: 'moose'}],
},
matchme: 'minime',
},
},
}
const cleaned = new Chain()
.merge(eh)
.traverse(false)
.keys([/super/, /parser/])
.vals([/minime/])
.call(true)
cleaned === {
notme: 1,
nested: {
really: {
// stripped matchme: minime
deep: {
// stripped out super
canada: true,
modules: [], // stripped out parser
},
},
},
}