Repository URL to install this package:
|
Version:
1.1.21 ▾
|
deeply merge all data values on a chain with ease
type Mergeable = Obj | Arr interface DopeMergeOptions { arrayMerge?: Fn stringToArray?: boolean = true boolToArray?: boolean = false ignoreTypes?: string[] = ['null', 'undefined', 'NaN'] debug?: boolean = undefined } function dopemerge(obj1: Mergeable, obj2: Mergeable, opts?: DopeMergeOptions): Mergeable class MergeChain extends ChainedMapBase { public onValue(fn?: Fn): MergeChain public onExisting(fn?: Fn): MergeChain public obj(obj: Obj): MergeChain public merge(objToMerge: Obj): MergeChain }
from.merge which works similar, but does not deeply merge objects unless the properties are chainable instancesconst chain = new ChainedMap() chain.merge({ehOh: true}) // same as chain.set('ehOh', true) chain.entries() === {ehOh: true}
const Chain = require('chain-able') class Canada extends Chain { static init(parent) { return new Canada(parent) } constructor(parent) { super('parent') this.extend(['eh']) } } const ls = { get(key) { return JSON.parse(window.localStorage.getItem(key)) }, set(key, value) { window.localStorage.setItem(key, JSON.stringify(value)) } } const canada = Canada.init() .eh('eh!') .merge({canada: true}) .tap('canada', value => '🇨🇦') .setIfEmpty('ooo', 'ahh') ls.set('canada', canada) const hydrated = new Canada().from(ls.get('canada'))
arg is an Iteratable (e.g. Array)arg is an Object.set