Comparing version 2.1.0 to 2.2.0
{ | ||
"name": "deeks", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "Retrieve all keys and nested keys from objects and arrays of objects.", | ||
@@ -16,4 +16,6 @@ "main": "src/deeks.js", | ||
"keywords": [ | ||
"get", | ||
"keys", | ||
"object", | ||
"document", | ||
"deep", | ||
@@ -20,0 +22,0 @@ "deeks", |
@@ -35,3 +35,6 @@ # deeks - Deep Object Key Extraction | ||
] | ||
}, {expandArrayObjects: true}); | ||
}, { | ||
expandArrayObjects: true, | ||
ignoreEmptyArraysWhenExpanding: true | ||
}); | ||
// => ['make', 'model', 'trim', 'specifications.mileage', 'specifications.cylinders'] | ||
@@ -81,2 +84,13 @@ | ||
- expandArrayObjects = `true` results in: `['make', 'model', 'trim', 'specifications.mileage', 'specifications.cylinders']` | ||
- ignoreEmptyArraysWhenExpanding - `Boolean` (Default: `false`) - Should empty array keys be ignored when expanding array objects? | ||
- Note: This only has an effect when used with `expandArrayObjects`. | ||
- Example: | ||
```json | ||
{ | ||
"features": [ {"name": "A/C" }], | ||
"rebates": [] | ||
} | ||
``` | ||
- ignoreEmptyArraysWhenExpanding = `false` results in: `['features.name', 'rebates']` | ||
- ignoreEmptyArraysWhenExpanding = `true` results in: `['features.name']` | ||
@@ -113,2 +127,13 @@ Returns: `Array[String]` | ||
- expandArrayObjects = `true` results in: `['make', 'model', 'trim', 'specifications.mileage', 'specifications.cylinders']` | ||
- ignoreEmptyArraysWhenExpanding - `Boolean` (Default: `false`) - Should empty array keys be ignored when expanding array objects? | ||
- Note: This only has an effect when used with `expandArrayObjects`. | ||
- Example: | ||
```json | ||
[ | ||
{ "features": [ {"name": "A/C" }] }, | ||
{ "features": [] } | ||
] | ||
``` | ||
- ignoreEmptyArraysWhenExpanding = `false` results in: `['features.name', 'features']` | ||
- ignoreEmptyArraysWhenExpanding = `true` results in: `['features.name']` | ||
@@ -164,6 +189,6 @@ Returns: `Array[Array[String]]` | ||
``` | ||
Statements : 100% ( 41/41 ) | ||
Branches : 100% ( 24/24 ) | ||
Statements : 100% ( 46/46 ) | ||
Branches : 100% ( 30/30 ) | ||
Functions : 100% ( 9/9 ) | ||
Lines : 100% ( 40/40 ) | ||
Lines : 100% ( 45/45 ) | ||
``` |
@@ -13,2 +13,3 @@ 'use strict'; | ||
* @param object | ||
* @param options | ||
* @returns {Array} | ||
@@ -27,2 +28,3 @@ */ | ||
* @param list | ||
* @param options | ||
* @returns Array[Array[String]] | ||
@@ -51,3 +53,3 @@ */ | ||
// If we have a nested array that we need to recur on | ||
return processArrayKeys(data[currentKey], currentKey); | ||
return processArrayKeys(data[currentKey], currentKey, options); | ||
} | ||
@@ -61,5 +63,20 @@ // Otherwise return this key name since we don't have a sub document | ||
function processArrayKeys(subArray, currentKeyPath) { | ||
let subArrayKeys = deepKeysFromList(subArray) | ||
.map((schemaKeys) => { | ||
/** | ||
* Helper function to handle the processing of arrays when the expandArrayObjects | ||
* option is specified. | ||
* @param subArray | ||
* @param currentKeyPath | ||
* @param options | ||
* @returns {*} | ||
*/ | ||
function processArrayKeys(subArray, currentKeyPath, options) { | ||
let subArrayKeys = deepKeysFromList(subArray); | ||
if (!subArray.length) { | ||
return options.ignoreEmptyArraysWhenExpanding ? [] : [currentKeyPath]; | ||
} else if (subArray.length && _.flatten(subArrayKeys).length === 0) { | ||
// Has items in the array, but no objects | ||
return [currentKeyPath]; | ||
} else { | ||
subArrayKeys = subArrayKeys.map((schemaKeys) => { | ||
if (isEmptyArray(schemaKeys)) { | ||
@@ -71,3 +88,4 @@ return [currentKeyPath]; | ||
return _.uniq(_.flatten(subArrayKeys)); | ||
return _.uniq(_.flatten(subArrayKeys)); | ||
} | ||
} | ||
@@ -94,3 +112,3 @@ | ||
function isDocumentToRecurOn(val) { | ||
return _.isObject(val) && !_.isNull(val) && !_.isArray(val) && Object.keys(val).length; | ||
return _.isObject(val) && !_.isNull(val) && !Array.isArray(val) && Object.keys(val).length; | ||
} | ||
@@ -104,3 +122,3 @@ | ||
function isArrayToRecurOn(val) { | ||
return _.isArray(val) && val.length; | ||
return Array.isArray(val); | ||
} | ||
@@ -119,4 +137,5 @@ | ||
return _.defaults(options || {}, { | ||
expandArrayObjects: false | ||
expandArrayObjects: false, | ||
ignoreEmptyArraysWhenExpanding: false | ||
}); | ||
} |
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
10729
118
191