New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

deepdash

Package Overview
Dependencies
Maintainers
1
Versions
112
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deepdash - npm Package Compare versions

Comparing version

to
3.1.3

2

package.json
{
"name": "deepdash",
"version": "3.1.2",
"version": "3.1.3",
"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",

@@ -30,3 +30,6 @@ <img src="deepdash.svg?sanitize=true" width="64px"/>

```
## Demo
[Example react+redux app](https://kw0zox7r.codesandbox.io/) with nested comments filtered by Deepdash.([play with code here](https://codesandbox.io/s/kw0zox7r))
## Methods

@@ -671,2 +674,2 @@

### See [full docs](https://deepdash.io) for details.
### See [full docs](https://deepdash.io) for details.

@@ -11,3 +11,3 @@ 'use strict';

describe('stackoverflow', () => {
//https://stackoverflow.com/questions/41610948/lodash-find-deep-in-array-of-object
// https://stackoverflow.com/questions/41610948/lodash-find-deep-in-array-of-object
it('lodash-find-deep-in-array-of-object', () => {

@@ -125,3 +125,3 @@ let obj = [

//https://stackoverflow.com/questions/48270845/deep-filtering-array-of-objects-javascript
// https://stackoverflow.com/questions/48270845/deep-filtering-array-of-objects-javascript
it('deep-filtering-array-of-objects-javascript', () => {

@@ -542,2 +542,353 @@ var types = [

});
// https://stackoverflow.com/questions/49179891/filter-deeply-nested-data-and-return-all-parent-immediate-child-items-js
it('filter-deeply-nested-data-and-return-all-parent-immediate-child-items-js', () => {
const data = {
level: 'Level 1',
items: [
{
name: 'Some Business Name',
id: '123',
data: null,
child: {
level: 'Level 2',
items: [
{
name: 'Some Sub-Business Name',
id: '1234',
data: null,
child: {
level: 'Level 3',
items: [
{
name: 'Some Area Name',
id: '12345',
data: null,
child: {
level: 'Level 4',
items: [
{
name: 'Some Local Name',
id: '123456',
data: null,
child: {
level: 'Level 5',
items: [
{
name: 'Some Product Name',
id: '1234567',
data: [2, 35, 235, 35554, 55554],
child: null,
},
{
name: 'Some Product Name 2',
id: '12345678',
data: [9, 5, 35, 5764, 335],
child: null,
},
],
},
},
{
name: 'Some Local Name 2',
id: '123456',
data: null,
child: {
level: 'Level 5',
items: [
{
name: 'Some Product Name 3',
id: '1234567',
data: [2, 35, 235, 35554, 55554],
child: null,
},
{
name: 'Some Product Name 4',
id: '12345678',
data: [9, 5, 35, 5764, 335],
child: null,
},
],
},
},
],
},
},
{
name: 'Some Area Name 2',
id: '12345',
data: null,
child: {
level: 'Level 4',
items: [
{
name: 'Some Local Name 3',
id: '123456',
data: null,
child: {
level: 'Level 5',
items: [
{
name: 'Some Product Name 5',
id: '1234567',
data: [2, 35, 235, 35554, 55554],
child: null,
},
],
},
},
],
},
},
],
},
},
],
},
},
{
name: 'Some Business Name 2',
id: '123',
data: null,
child: {
level: 'Level 2',
items: [
{
name: 'Some Sub-Business Name 2',
id: '1234',
data: null,
child: {
level: 'Level 3',
items: [
{
name: 'Some Area Name 3',
id: '12345',
data: null,
child: {
level: 'Level 4',
items: [
{
name: 'Some Local Name 4',
id: '123456',
data: null,
child: {
level: 'Level 5',
items: [
{
name: 'Some Product Name 6',
id: '1234567',
data: [2, 35, 235, 35554, 55554],
child: null,
},
{
name: 'Some Product Name 7',
id: '12345678',
data: [9, 5, 35, 5764, 335],
child: null,
},
],
},
},
],
},
},
],
},
},
{
name: 'Some Sub-Business Name 3',
id: '1234',
data: null,
child: {
level: 'Level 3',
items: [
{
name: 'Some Area Name 5',
id: '12345',
data: null,
child: {
level: 'Level 4',
items: [
{
name: 'Some Local Name 5',
id: '123456',
data: null,
child: {
level: 'Level 5',
items: [
{
name: 'Some Product Name 8',
id: '1234567',
data: [2, 35, 235, 35554, 55554],
child: null,
},
],
},
},
],
},
},
],
},
},
],
},
},
],
};
const filterList = [
'Some Business Name',
'Some Business Name 2',
'Some Sub-Business Name',
'Some Sub-Business Name 2',
'Some Area Name',
'Some Area Name 3',
'Some Local Name 2',
'Some Local Name 4',
];
// filter by name
let arr = _.filterDeep(
data,
(item, key, parentVal, ctx) => {
return (
_.includes(filterList, item.name) ||
(ctx.parent &&
_.includes(
filterList,
_.get(ctx, 'parent.parent.parent.value.name')
))
);
},
{
tree: { children: 'items' },
}
);
// remove empty 'child'
arr = _.filterDeep(
arr,
(val, key) => {
return key != 'child' || (val !== null && val.items.length > 0);
},
{ leavesOnly: false, onTrue: { skipChildren: false } }
);
// console.log(JSON.stringify(arr, null, 2));
expect(arr).to.deep.equal({
items: [
{
name: 'Some Business Name',
id: '123',
data: null,
child: {
level: 'Level 2',
items: [
{
name: 'Some Sub-Business Name',
id: '1234',
data: null,
child: {
level: 'Level 3',
items: [
{
name: 'Some Area Name',
id: '12345',
data: null,
child: {
level: 'Level 4',
items: [
{
name: 'Some Local Name',
id: '123456',
data: null,
},
{
name: 'Some Local Name 2',
id: '123456',
data: null,
child: {
level: 'Level 5',
items: [
{
name: 'Some Product Name 3',
id: '1234567',
data: [2, 35, 235, 35554, 55554],
},
{
name: 'Some Product Name 4',
id: '12345678',
data: [9, 5, 35, 5764, 335],
},
],
},
},
],
},
},
{
name: 'Some Area Name 2',
id: '12345',
data: null,
},
],
},
},
],
},
},
{
name: 'Some Business Name 2',
id: '123',
data: null,
child: {
level: 'Level 2',
items: [
{
name: 'Some Sub-Business Name 2',
id: '1234',
data: null,
child: {
level: 'Level 3',
items: [
{
name: 'Some Area Name 3',
id: '12345',
data: null,
child: {
level: 'Level 4',
items: [
{
name: 'Some Local Name 4',
id: '123456',
data: null,
child: {
level: 'Level 5',
items: [
{
name: 'Some Product Name 6',
id: '1234567',
data: [2, 35, 235, 35554, 55554],
},
{
name: 'Some Product Name 7',
id: '12345678',
data: [9, 5, 35, 5764, 335],
},
],
},
},
],
},
},
],
},
},
{
name: 'Some Sub-Business Name 3',
id: '1234',
data: null,
},
],
},
},
],
});
});
});