Processes each properties of an object deeply.
Apply a function to all (non plain object) properties.
const eachProps = require('each-props');
var obj = { a: 1, b: { c: 'CCC', d: { e: 'EEE' } } };
eachProps(obj, function (value, keyChain, nodeInfo) {
if (keyChain === 'a') {
nodeInfo.parent['a'] = value * 2;
} else if (keyChain === 'b.c') {
nodeInfo.parent['c'] = value.toLowerCase();
} else if (keyChain === 'b.d') {
return true; // stop to dig
-
API of fn function
fn(value, keyChain, nodeInfo) : boolean
This function is applied to all properties in an object.
Parameters:
| Parameter | Type | Description |
|---|
| value | any | A property value. |
| keyChain | string | A string concatenating the hierarchical keys with dots. |
| nodeInfo | object | An object which contains node informations (See below). |
Returns:
True, if stops digging child properties.
Type: boolean
-
Properties of nodeInfo