Comparing version 2.1.1 to 2.1.2
@@ -8,3 +8,3 @@ # Change Log | ||
- `tree` option added to [eachDeep](#eachdeep-foreachdeep) method. | ||
- `tree` option added to [eachDeep](/#eachdeep-foreachdeep) method. | ||
Now it's much easier to iterate over tree with known `children` collection field name / path | ||
@@ -17,10 +17,16 @@ | ||
## v2-0-0 | ||
*(2019-02-21)* | ||
**Breaking Changes** | ||
- [iteratee/predicate](#iteratee) arguments order/structure changed to mimic native js array predicates | ||
- [iteratee/predicate](/#iteratee) arguments order/structure changed to mimic native js array predicates | ||
**Features added** | ||
- checkCircular option added to [eachDeep](#eachdeep-foreachdeep) method. | ||
- [pickDeep](#peekdeep) method implemented. | ||
- checkCircular option added to [eachDeep](/#eachdeep-foreachdeep) method. | ||
- [pickDeep](/#peekdeep) method implemented. | ||
## v1-9-5 | ||
*(2019-02-09)* | ||
*no changelog earlier, sorry* |
@@ -206,3 +206,10 @@ # Deepdash | ||
```js | ||
_.eachDeep( obj, iteratee=_.identity, options={ checkCircular: false, pathFormat: 'string' }) => object | ||
_.eachDeep( obj, iteratee=_.identity, options={ | ||
checkCircular: false, | ||
pathFormat: 'string', | ||
tree:{ | ||
rootIsChildren: true, | ||
children: 'children' | ||
} | ||
}) => object | ||
``` | ||
@@ -215,2 +222,5 @@ | ||
- `pathFormat` ('string') - specifies `'string'` or `'array'` format of paths passed to the iteratee. | ||
- `tree` (false) - treat the `obj` as a "tree" of nodes with `children` collections. Can be boolean or object. Only elements of such collections will be passed into iteratee. | ||
- `children` ('children') - children collection's field name, path, path's regex or array of any of this. | ||
- `rootIsChildren` (true) - treat `obj` as top-level children collection, so its elements will be passed into iteratee without parent path check (so you don't need to specify empty path as `tree.children` option) | ||
* `returns` - source object | ||
@@ -229,3 +239,10 @@ | ||
- `path` - path to the current value | ||
- `parent` - an object with the current parent's `value`, `key|index`, `path` and `parent` fields | ||
- `parent` - an object of the current parent | ||
- `value` - value of the parent, equivalent of `parentValue` argument. | ||
- `key` - parent key|index | ||
- `path` - parent path | ||
- `parent` - grandparent with the same structure. | ||
- next `parent` fields are available if `tree` option was activated: | ||
- `isTreeChildren` - true if this parent is `children` collection. | ||
- `treeChildrenPath` - contains matched `children` path (specific one from `tree.children` option array) | ||
- `parents` - an array with all parent objects starting from the root level. `parent` object listed above is just the last element of this array | ||
@@ -259,2 +276,60 @@ - `obj` - source object | ||
``` | ||
```js | ||
let children = [ | ||
{ | ||
name: 'grand 1', | ||
children: [ | ||
{ | ||
name: 'parent 1.1', | ||
children: [{ name: 'child 1.1.1' }, { name: 'child 1.1.2' }], | ||
}, | ||
{ | ||
name: 'parent 1.2', | ||
children: [{ name: 'child 1.2.1' }, { name: 'child 1.2.2' }], | ||
}, | ||
], | ||
}, | ||
{ | ||
name: 'grand 2', | ||
children: [ | ||
{ | ||
name: 'parent 2.1', | ||
children: [{ name: 'child 2.1.1' }, { name: 'child 2.1.2' }], | ||
}, | ||
{ | ||
name: 'parent 2.2', | ||
children: [{ name: 'child 2.2.1' }, { name: 'child 2.2.2' }], | ||
}, | ||
], | ||
}, | ||
]; | ||
let total = 0; | ||
_.eachDeep( | ||
children, | ||
(child, i, parent, ctx) => { | ||
console.log(_.repeat(' ', ctx.depth) + child.name); | ||
total++; | ||
}, | ||
{ tree: true } | ||
); | ||
console.log('total nodes: ' + total); | ||
``` | ||
Console: | ||
``` | ||
grand 1 | ||
parent 1.1 | ||
child 1.1.1 | ||
child 1.1.2 | ||
parent 1.2 | ||
child 1.2.1 | ||
child 1.2.2 | ||
grand 2 | ||
parent 2.1 | ||
child 2.1.1 | ||
child 2.1.2 | ||
parent 2.2 | ||
child 2.2.1 | ||
child 2.2.2 | ||
total nodes: 14 | ||
``` | ||
## exists | ||
@@ -261,0 +336,0 @@ |
{ | ||
"name": "deepdash", | ||
"version": "2.1.1", | ||
"version": "2.1.2", | ||
"description": "➔ 𝐃eep extension for 𝐋odash: ✓ eachDeep ✓ filterDeep ✓ pickDeep ✓ omitDeep ✓ keysDeep ✓ indexate ✓ condenseDeep ⋮ Parent nodes tracking ⋮ Circular references check ⋮ Leaves only mode ⋮ Path as a valid js string or an array ⋮", | ||
@@ -5,0 +5,0 @@ "main": "deepdash.js", |
@@ -82,2 +82,43 @@ 'use strict'; | ||
}); | ||
it('eachDeep tree', () => { | ||
let children = [ | ||
{ | ||
name: 'grand 1', | ||
children: [ | ||
{ | ||
name: 'parent 1.1', | ||
children: [{ name: 'child 1.1.1' }, { name: 'child 1.1.2' }], | ||
}, | ||
{ | ||
name: 'parent 1.2', | ||
children: [{ name: 'child 1.2.1' }, { name: 'child 1.2.2' }], | ||
}, | ||
], | ||
}, | ||
{ | ||
name: 'grand 2', | ||
children: [ | ||
{ | ||
name: 'parent 2.1', | ||
children: [{ name: 'child 2.1.1' }, { name: 'child 2.1.2' }], | ||
}, | ||
{ | ||
name: 'parent 2.2', | ||
children: [{ name: 'child 2.2.1' }, { name: 'child 2.2.2' }], | ||
}, | ||
], | ||
}, | ||
]; | ||
let total = 0; | ||
_.eachDeep( | ||
children, | ||
(child, i, parent, ctx) => { | ||
// console.log(_.repeat(' ', ctx.depth) + child.name); | ||
total++; | ||
}, | ||
{ tree: true } | ||
); | ||
// console.log('total nodes: ' + total); | ||
expect(total).equal(14); | ||
}); | ||
it('indexate', () => { | ||
@@ -84,0 +125,0 @@ let index = _.indexate( |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
152928
3229