Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
โ ๐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 โฎ
Looking for eachDeep, filterDeep, omitDeep, keysDeep etc? Tree traversal extension for Lodash.
In a browser load script after Lodash:
<script src="https://cdn.jsdelivr.net/npm/lodash/lodash.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/deepdash/deepdash.min.js"></script>
Using npm:
npm i --save deepdash
In Node.js (same for the Angular component):
//mixin new methods into Lodash object
const _ = require('deepdash')(require('lodash'));
Or as ECMAScript Module:
import lodash from "lodash";
import deepdash from "deepdash";
const _ = deepdash(lodash);
Example react+redux app with nested comments filtered by Deepdash.(play with code here)
children example collection is here
let children = [/* ... */];
function displayField(val, key, parent, context) {
if (_.isArray(parent)) {
key = '[' + key + ']';
}
console.log(
_.repeat(' ', context.depth) +
'โ ' +
key +
': ' +
(_.isArray(val)
? '[' + val.length + ']'
: _.isObject(val)
? '{' + (val.name || '') + '}'
: val)
);
}
console.log('\n = Iterate over tree (each child object) = \n');
_.eachDeep(children, displayField, { tree: true });
console.log('\n = Iterate over object (each field) = \n');
_.eachDeep(children, displayField);
Console:
= Iterate over tree (each child object) =
โ [0]: {node 1}
โ [0]: {node 1.1}
โ [1]: {node 1.2}
โ [2]: {node 1.3}
โ [1]: {node 2}
โ [0]: {node 2.1}
โ [1]: {node 2.2}
โ [2]: {node 2.3}
โ [2]: {node 3}
โ [0]: {node 3.1}
โ [1]: {node 3.2}
โ [2]: {node 3.3}
= Iterate over object (each field) =
โ [0]: {node 1}
โ description: description for node 1
โ comment: comment for node 1
โ note: note for node 1
โ name: node 1
โ bad: false
โ children: [3]
โ [0]: {node 1.1}
โ description: description for node 1.1
โ comment: comment for node 1.1
โ note: note for node 1.1
โ name: node 1.1
โ bad: false
โ [1]: {node 1.2}
โ description: description for node 1.2
โ comment: comment for node 1.2
โ note: note for node 1.2
โ name: node 1.2
โ good: true
โ [2]: {node 1.3}
โ description: description for node 1.3
โ comment: comment for node 1.3
โ note: note for node 1.3
โ name: node 1.3
โ bad: true
โ good: false
โ [1]: {node 2}
โ description: description for node 2
โ comment: comment for node 2
โ note: note for node 2
โ name: node 2
โ good: true
โ children: [3]
โ [0]: {node 2.1}
โ description: description for node 2.1
โ comment: comment for node 2.1
โ note: note for node 2.1
โ name: node 2.1
โ bad: false
โ [1]: {node 2.2}
โ description: description for node 2.2
โ comment: comment for node 2.2
โ note: note for node 2.2
โ name: node 2.2
โ good: true
โ [2]: {node 2.3}
โ description: description for node 2.3
โ comment: comment for node 2.3
โ note: note for node 2.3
โ name: node 2.3
โ bad: true
โ good: false
โ [2]: {node 3}
โ description: description for node 3
โ comment: comment for node 3
โ note: note for node 3
โ name: node 3
โ bad: true
โ good: false
โ children: [3]
โ [0]: {node 3.1}
โ description: description for node 3.1
โ comment: comment for node 3.1
โ note: note for node 3.1
โ name: node 3.1
โ bad: false
โ [1]: {node 3.2}
โ description: description for node 3.2
โ comment: comment for node 3.2
โ note: note for node 3.2
โ name: node 3.2
โ good: true
โ [2]: {node 3.3}
โ description: description for node 3.3
โ comment: comment for node 3.3
โ note: note for node 3.3
โ name: node 3.3
โ bad: true
โ good: false
children example collection is here
let children = [/* ... */];
console.log('\n = Filter tree (good children) = \n');
console.log(
_.filterDeep(children, 'good', { tree: true })
);
console.log('\n = Filter object (names of good children) = \n');
console.log(
_.filterDeep(children, (val, key, parent) => {
if (key == 'name' && parent.good) return true;
})
);
Console:
= Filter tree (good children) =
[
{
"description": "description for node 1",
"comment": "comment for node 1",
"note": "note for node 1",
"name": "node 1",
"bad": false,
"children": [
{
"description": "description for node 1.2",
"comment": "comment for node 1.2",
"note": "note for node 1.2",
"name": "node 1.2",
"good": true
}
]
},
{
"description": "description for node 2",
"comment": "comment for node 2",
"note": "note for node 2",
"name": "node 2",
"good": true,
"children": [
{
"description": "description for node 2.2",
"comment": "comment for node 2.2",
"note": "note for node 2.2",
"name": "node 2.2",
"good": true
}
]
},
{
"description": "description for node 3",
"comment": "comment for node 3",
"note": "note for node 3",
"name": "node 3",
"bad": true,
"good": false,
"children": [
{
"description": "description for node 3.2",
"comment": "comment for node 3.2",
"note": "note for node 3.2",
"name": "node 3.2",
"good": true
}
]
}
]
= Filter object (names of good children) =
[
{
"children": [
{
"name": "node 1.2"
}
]
},
{
"name": "node 2",
"children": [
{
"name": "node 2.2"
}
]
},
{
"children": [
{
"name": "node 3.2"
}
]
}
]
children example collection is here
let children = [/* ... */];
console.log('\n = Pick name and description only = \n');
console.log(
_.pickDeep(children, ['name', 'description'])
);
Console:
= Pick name and description only =
[
{
"description": "description for node 1",
"name": "node 1",
"children": [
{
"description": "description for node 1.1",
"name": "node 1.1"
},
{
"description": "description for node 1.2",
"name": "node 1.2"
},
{
"description": "description for node 1.3",
"name": "node 1.3"
}
]
},
{
"description": "description for node 2",
"name": "node 2",
"children": [
{
"description": "description for node 2.1",
"name": "node 2.1"
},
{
"description": "description for node 2.2",
"name": "node 2.2"
},
{
"description": "description for node 2.3",
"name": "node 2.3"
}
]
},
{
"description": "description for node 3",
"name": "node 3",
"children": [
{
"description": "description for node 3.1",
"name": "node 3.1"
},
{
"description": "description for node 3.2",
"name": "node 3.2"
},
{
"description": "description for node 3.3",
"name": "node 3.3"
}
]
}
]
children example collection is here
let children = [/* ... */];
console.log('\n = Omit paths not ending with "e" = \n');
console.log(
_.omitDeep(children, /[^e]$/i, { onMatch: { skipChildren: false } }),
);
Console:
= Omit paths not ending with "e" =
[
{
"note": "note for node 1",
"name": "node 1",
"children": [
{
"note": "note for node 1.1",
"name": "node 1.1"
},
{
"note": "note for node 1.2",
"name": "node 1.2"
},
{
"note": "note for node 1.3",
"name": "node 1.3"
}
]
},
{
"note": "note for node 2",
"name": "node 2",
"children": [
{
"note": "note for node 2.1",
"name": "node 2.1"
},
{
"note": "note for node 2.2",
"name": "node 2.2"
},
{
"note": "note for node 2.3",
"name": "node 2.3"
}
]
},
{
"note": "note for node 3",
"name": "node 3",
"children": [
{
"note": "note for node 3.1",
"name": "node 3.1"
},
{
"note": "note for node 3.2",
"name": "node 3.2"
},
{
"note": "note for node 3.3",
"name": "node 3.3"
}
]
}
]
let index = _.indexate(
{
a: {
b: {
c: [1, 2, 3],
'hello world': {},
},
},
},
{ leavesOnly: true }
);
console.log(index);
Console:
{ 'a.b.c[0]': 1,
'a.b.c[1]': 2,
'a.b.c[2]': 3,
'a.b["hello world"]': {} }
let paths = _.paths(
{
a: {
b: {
c: [1, 2, 3],
'hello world': {},
},
},
},
{ leavesOnly: false }
);
console.log(paths);
Console:
[ 'a',
'a.b',
'a.b.c',
'a.b.c[0]',
'a.b.c[1]',
'a.b.c[2]',
'a.b["hello world"]' ]
let arr = ['a', 'b', 'c', 'd', 'e'];
delete arr[1];
console.log(arr);
delete arr[3];
console.log(arr);
_.condense(arr);
console.log(arr);
Console:
[ 'a', <1 empty item>, 'c', 'd', 'e' ]
[ 'a', <1 empty item>, 'c', <1 empty item>, 'e' ]
[ 'a', 'c', 'e' ]
let obj = { arr: ['a', 'b', { c: [1, , 2, , 3] }, 'd', 'e'] };
delete obj.arr[1];
delete obj.arr[3];
_.condenseDeep(obj);
console.log(obj);
Console:
{ arr: [ 'a', { c: [ 1, 2, 3 ] }, 'e' ] }
_.has
but returns false
for empty array slots (๐ docs) var obj = [, { a: [, 'b'] }];
console.log(_.exists(obj, 0)); // false
console.log(_.exists(obj, 1)); // true
console.log(_.exists(obj, '[1].a[0]')); // false
console.log(_.exists(obj, '[1].a[1]')); // true
console.log(_.pathToString(['a', 'b', 'c', 'defg', 0, '1', 2.3]));
// a.b.c.defg[0][1]["2.3"]
console.log(_.pathToString(['"', '"', '"']));
// ["\\""]["\\""]["\\""]
console.log(_.pathToString('it.s.a.string'));
// it.s.a.string
let children = [
{
description: 'description for node 1',
comment: 'comment for node 1',
note: 'note for node 1',
name: 'node 1',
bad: false,
children: [
{
description: 'description for node 1.1',
comment: 'comment for node 1.1',
note: 'note for node 1.1',
name: 'node 1.1',
bad: false,
},
{
description: 'description for node 1.2',
comment: 'comment for node 1.2',
note: 'note for node 1.2',
name: 'node 1.2',
good: true,
},
{
description: 'description for node 1.3',
comment: 'comment for node 1.3',
note: 'note for node 1.3',
name: 'node 1.3',
bad: true,
good: false,
},
],
},
{
description: 'description for node 2',
comment: 'comment for node 2',
note: 'note for node 2',
name: 'node 2',
good: true,
children: [
{
description: 'description for node 2.1',
comment: 'comment for node 2.1',
note: 'note for node 2.1',
name: 'node 2.1',
bad: false,
},
{
description: 'description for node 2.2',
comment: 'comment for node 2.2',
note: 'note for node 2.2',
name: 'node 2.2',
good: true,
},
{
description: 'description for node 2.3',
comment: 'comment for node 2.3',
note: 'note for node 2.3',
name: 'node 2.3',
bad: true,
good: false,
},
],
},
{
description: 'description for node 3',
comment: 'comment for node 3',
note: 'note for node 3',
name: 'node 3',
bad: true,
good: false,
children: [
{
description: 'description for node 3.1',
comment: 'comment for node 3.1',
note: 'note for node 3.1',
name: 'node 3.1',
bad: false,
},
{
description: 'description for node 3.2',
comment: 'comment for node 3.2',
note: 'note for node 3.2',
name: 'node 3.2',
good: true,
},
{
description: 'description for node 3.3',
comment: 'comment for node 3.3',
note: 'note for node 3.3',
name: 'node 3.3',
bad: true,
good: false,
},
],
},
];
FAQs
โ ๐eep standalone lib / ๐odash extension: โ eachDeep โ filterDeep โ mapDeep โ reduceDeep โ pickDeep โ omitDeep โ keysDeep โ index โ condenseDeep โฎ Parents stack โฎ Circular check โฎ Leaves only mode โฎ Children mode โฎ cherry-pick โฎ esm
We found that deepdash demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.ย It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.