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.4.1 to 1.5.0

test/indexate.test.js

55

deepdash.js

@@ -85,5 +85,52 @@ 'use strict';

}
if(!_.indexate){
function indexate(obj, options) {
options = _.merge(
{
checkCircular: false,
includeCircularPath: true,
leafsOnly:false
},
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){
if(options.leafsOnly && res[parentPath]){
delete res[parentPath];
}
res[path]=value;
}
if(circular){
return false;
}
},
eachDeepOptions
);
return res;
}
if(!_.indexate){
_.mixin({ indexate: indexate });
}
}
if (!_.keysDeep||!_.paths) {
function keysDeep(obj, options) {
function paths(obj, options) {
options = _.merge(

@@ -132,6 +179,6 @@ {

if(!_.keysDeep){
_.mixin({ keysDeep: keysDeep });
_.mixin({ keysDeep: paths });
}
if (!_.paths) {
_.mixin({ paths: keysDeep });
_.mixin({ paths: paths });
}

@@ -138,0 +185,0 @@ }

4

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

@@ -20,2 +20,4 @@ "main": "deepdash.js",

"lodash",
"each deep",
"keys deep",
"object",

@@ -22,0 +24,0 @@ "tree",

<img src="deepdash.svg?sanitize=true" width="64px"/>
## deepdash
tree traversal for lodash
Looking for eachDeep, keysDeep etc? Tree traversal extension for lodash.
### Installation

@@ -109,3 +109,3 @@ In a browser load [script](https://raw.githubusercontent.com/YuriGor/deepdash/master/deepdash.js) after lodash:

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

@@ -142,5 +142,38 @@

```
### indexate
`_.indexate(object, [options={ checkCircular: false, includeCircularPath: true, leafsOnly: false }])` <br>
Creates an 'index' flat object with paths as keys and corresponding values.
### keysDeep (paths)
`_.keysDeep(object, [iteratee=_.identity], [options={ checkCircular: false, includeCircularPath: true, leafsOnly: false }])`<br>
**Arguments:**
- object: (Object) The object to iterate over.
- \[options\]: (Object)
- \[checkCircular\]: (Boolean) check each value to not be one of the parents, to avoid circular references.
- \[includeCircularPath\]: (Boolean) if found some circular reference - include path to it into result or skip it. Option ignored if `checkCircular:false`.
- \[leafsOnly\]: (Boolean) return paths to childless values only. By default all the paths will be returned, including parents.
**Example:**
```js
let index = _.indexate(
{
a: {
b: {
c: [1, 2, 3],
'hello world': {},
},
},
},
{ leafsOnly: true }
);
console.log(index);
```
Console:
```
{ 'a.b.c[0]': 1,
'a.b.c[1]': 2,
'a.b.c[2]': 3,
'a.b["hello world"]': {} }
```
### paths (keysDeep)
`_.paths(object, [iteratee=_.identity], [options={ checkCircular: false, includeCircularPath: true, leafsOnly: false }])` <br>
Creates an array of the paths of object or array.

@@ -152,3 +185,3 @@

- \[checkCircular\]: (Boolean) check each value to not be one of the parents, to avoid circular references.
- \[includeCircularPath\]: (Boolean) include path to circular reference, if found some, or skip it. Option ignored if `checkCircular:false`.
- \[includeCircularPath\]: (Boolean) if found some circular reference - include path to it into result or skip it. Option ignored if `checkCircular:false`.
- \[leafsOnly\]: (Boolean) return paths to childless values only. By default all the paths will be returned, including parents.

@@ -158,3 +191,3 @@

```js
let keys = _.keysDeep({
let paths = _.paths({
a: {

@@ -167,4 +200,4 @@ b: {

});
console.log(keys);
keys = _.keysDeep({
console.log(paths);
paths = _.paths({
a: {

@@ -177,3 +210,3 @@ b: {

},{ leafsOnly: true });
console.log(keys);
console.log(paths);
```

@@ -180,0 +213,0 @@ Console:

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