Comparing version 2.3.2 to 2.4.0
@@ -44,3 +44,3 @@ 'use strict'; | ||
// If the given heading is empty, then we set the heading to be the subKey, otherwise set it as a nested heading w/ a dot | ||
let keyName = buildKeyName(heading, currentKey); | ||
let keyName = buildKeyName(heading, escapeNestedDotsIfSpecified(currentKey, options)); | ||
@@ -82,3 +82,3 @@ // If we have another nested document, recur on the sub-document to retrieve the full key name | ||
} | ||
return schemaKeys.map((subKey) => buildKeyName(currentKeyPath, subKey)); | ||
return schemaKeys.map((subKey) => buildKeyName(currentKeyPath, escapeNestedDotsIfSpecified(subKey, options))); | ||
}); | ||
@@ -90,2 +90,9 @@ | ||
function escapeNestedDotsIfSpecified(key, options) { | ||
if (options.escapeNestedDots) { | ||
return key.replace('.', '\\.'); | ||
} | ||
return key; | ||
} | ||
/** | ||
@@ -135,4 +142,5 @@ * Function used to generate the key path | ||
ignoreEmptyArraysWhenExpanding: false, | ||
escapeNestedDots: false, | ||
...options || {} | ||
}; | ||
} |
@@ -5,8 +5,3 @@ 'use strict'; | ||
// underscore replacements: | ||
isString, | ||
isNull, | ||
isError, | ||
isDate, | ||
isFunction, | ||
isUndefined, | ||
isObject, | ||
@@ -21,6 +16,2 @@ unique, | ||
function isString(value) { | ||
return typeof value === 'string'; | ||
} | ||
function isObject(value) { | ||
@@ -30,6 +21,2 @@ return typeof value === 'object'; | ||
function isFunction(value) { | ||
return typeof value === 'function'; | ||
} | ||
function isNull(value) { | ||
@@ -39,14 +26,2 @@ return value === null; | ||
function isDate(value) { | ||
return value instanceof Date; | ||
} | ||
function isUndefined(value) { | ||
return typeof value === 'undefined'; | ||
} | ||
function isError(value) { | ||
return Object.prototype.toString.call(value) === '[object Error]'; | ||
} | ||
function unique(array) { | ||
@@ -53,0 +28,0 @@ return [...new Set(array)]; |
{ | ||
"name": "deeks", | ||
"version": "2.3.2", | ||
"version": "2.4.0", | ||
"description": "Retrieve all keys and nested keys from objects and arrays of objects.", | ||
@@ -41,4 +41,4 @@ "main": "lib/deeks.js", | ||
"engines": { | ||
"node": ">= 10" | ||
"node": ">= 12" | ||
} | ||
} |
@@ -92,2 +92,15 @@ # deeks - Deep Object Key Extraction | ||
- ignoreEmptyArraysWhenExpanding = `true` results in: `['features.name']` | ||
- escapeNestedDots - `Boolean` (Default: `false`) - Should `.` characters that appear in keys be escaped with a preceding `\` character. | ||
- Example: | ||
```json | ||
{ | ||
"a.a": "1", | ||
"a.b": { | ||
"c": "2", | ||
"c.d": "3" | ||
} | ||
} | ||
``` | ||
- escapeNestedDots = `false` results in: `['a.a', 'a.b.c', 'a.b.c.d']` | ||
- escapeNestedDots = `true` results in: `['a\\.a', 'a\\.b.c', 'a\\.b.c\\.d']` | ||
@@ -133,4 +146,19 @@ Returns: `Array[String]` | ||
``` | ||
- ignoreEmptyArraysWhenExpanding = `false` results in: `['features.name', 'features']` | ||
- ignoreEmptyArraysWhenExpanding = `true` results in: `['features.name']` | ||
- ignoreEmptyArraysWhenExpanding = `false` results in: `[ ['features.name', 'features'] ]` | ||
- ignoreEmptyArraysWhenExpanding = `true` results in: `[ ['features.name'] ]` | ||
- escapeNestedDots - `Boolean` (Default: `false`) - Should `.` characters that appear in keys be escaped with a preceding `\` character. | ||
- Example: | ||
```json | ||
[ | ||
{ | ||
"a.a": "1", | ||
"a.b": { | ||
"c": "2", | ||
"c.d": "3" | ||
} | ||
} | ||
] | ||
``` | ||
- escapeNestedDots = `false` results in: `[ ['a.a', 'a.b.c', 'a.b.c.d'] ]` | ||
- escapeNestedDots = `true` results in: `[ ['a\\.a', 'a\\.b.c', 'a\\.b.c\\.d'] ]` | ||
@@ -147,2 +175,4 @@ Returns: `Array[Array[String]]` | ||
Additionally, `doc-path@>=3` works with the keys returned when the `escapeNestedDots` option is specified. | ||
Here's an example of how this works: | ||
@@ -187,6 +217,6 @@ | ||
``` | ||
Statements : 100% ( 46/46 ) | ||
Branches : 100% ( 30/30 ) | ||
Functions : 100% ( 9/9 ) | ||
Lines : 100% ( 45/45 ) | ||
Statements : 100% ( 45/45 ) | ||
Branches : 100% ( 32/32 ) | ||
Functions : 100% ( 18/18 ) | ||
Lines : 100% ( 44/44 ) | ||
``` |
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
12050
219
149