Huge News!Announcing our $40M Series B led by Abstract Ventures.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 1.2.6 to 1.3.1

test/keysDeep.test.js

59

deepdash.js

@@ -22,2 +22,4 @@ 'use strict';

}
if(!_.isObject(obj))
return;
_.forOwn(obj, function(value, key) {

@@ -62,6 +64,5 @@ var okey = key;

if (!_.eachDeep) {
if (!_.eachDeep||!_.forEachDeep) {
function eachDeep(obj, callback, options) {
if (callback === undefined) callback = _.identity;
if (options === undefined) options = {};
options = _.merge(

@@ -71,3 +72,3 @@ {

},
options
options || {}
);

@@ -80,3 +81,5 @@ if (options.track) {

}
_.mixin({ eachDeep: eachDeep });
if(!_.eachDeep){
_.mixin({ eachDeep: eachDeep });
}
if (!_.forEachDeep) {

@@ -87,2 +90,50 @@ _.mixin({ forEachDeep: eachDeep });

if (!_.keysDeep||!_.paths) {
function keysDeep(obj, options) {
options = _.merge(
{
checkCircular: false,
includeCircularPath: true,
},
options || {}
);
var eachDeepOptions = {
track: options.checkCircular,
};
var res = [];
_.eachDeep(
obj,
function(
value,
key,
path,
depth,
parent,
parentKey,
parentPath,
parents
) {
var circular = false;
if (options.checkCircular) {
circular =_.indexOf(parents.values, value) !== -1;
}
if(!circular||options.includeCircularPath){
res.push(path);
}
if(circular){
return false;
}
},
eachDeepOptions
);
return res;
}
if(!_.keysDeep){
_.mixin({ keysDeep: keysDeep });
}
if (!_.paths) {
_.mixin({ paths: keysDeep });
}
}
return _;

@@ -89,0 +140,0 @@ }

3

package.json
{
"name": "deepdash",
"version": "1.2.6",
"version": "1.3.1",
"description": "Object tree traversal for lodash",

@@ -35,2 +35,3 @@ "main": "deepdash.js",

"chai": "^4.2.0",
"chai-asserttype": "^1.0.5",
"eslint": "^5.8.0",

@@ -37,0 +38,0 @@ "mocha": "^5.2.0",

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

### eachDeep (forEachDeep)
`_.eachDeep(object, [iteratee=_.identity])`
`_.eachDeep(object, [iteratee=_.identity], [options={ track: false }])`
Invokes given callback for each field and element of given object or array, nested too.

@@ -143,3 +143,36 @@

### keysDeep (paths)
`_.keysDeep(object, [iteratee=_.identity], [options={ checkCircular: false, includeCircularPath: true }])`
Creates an array of the paths of object or array.
**Arguments:**
- object: (Object) The object to iterate over.
- \[options\]: (Object)
- \[checkCircular\]: (Boolean) option (false by default) to avoid circular references.
- \[includeCircularPath\]: (Boolean) option (true by default) return path to circular reference, if found some, or not.
**Example:**
```js
let keys = _.keysDeep({
a: {
b: {
c: [1, 2, 3],
"hello world":{}
},
},
});
console.log(keys);
```
Console:
```
[ 'a',
'a.b',
'a.b.c',
'a.b.c[0]',
'a.b.c[1]',
'a.b.c[2]',
'a.b["hello world"]' ]
```
### Other traversal methods
Feel free [to request](https://github.com/YuriGor/deepdash/issues/new) other methods implementation.

@@ -75,2 +75,26 @@ 'use strict';

});
it('Array',()=>{
let c = 0;
_.eachDeep(
[demo,demo],
(value, key, path, depth, parent, parentKey, parentPath) => {
if (key == 'skip') return false;
c++;
}
);
expect(c).equal(52);
});
it('String',()=>{
let c = 0;
_.eachDeep(
'Hello?',
(value, key, path, depth, parent, parentKey, parentPath) => {
if (key == 'skip') return false;
c++;
}
);
expect(c).equal(0);
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc