0.1.2 • Published 3 years ago
obj-map-merge v0.1.2
obj-map-merge
Map over an object's key/value pairs and merge (Object.assign) all partial results.
API
This module exports one function:
objMapMerge(func, opt)(obj, dest)
A factory function that produces a mapper function mapper which takes one
argument obj.
The mapper function will iterate over own enumerable properties of obj,
calling func with arguments key, value, obj for each entry.
The results will be shallow-merged into dest (see init below).
opt is an optional options object that supports these optional keys:
init: Where to merge the intermediate results into.false(default): Start with a fresh empty object and merge each batch into that.null: Start with a fresh empty object that has no prototype and merge each batch into that.true: Merge intodest.- a function:
Start with the result of
init(dest, obj)and merge each batch into that. - a string: Start with the result of JSON-parsing the string and merge each batch into that.
sortKeys: Whether to mapobj's keys in sorted order.false(default): Don't sort.true: Sort by key, using the default comparison.- a function: Use this function for comparison.
Usage
see test/usage.mjs.
Known issues
- Needs more/better tests and docs.
License
ISC