dot-prop
Advanced tools
Comparing version 7.2.0 to 8.0.0
@@ -1,2 +0,2 @@ | ||
import {Get} from 'type-fest'; | ||
import {type Get} from 'type-fest'; | ||
@@ -136,3 +136,3 @@ /** | ||
/** | ||
Returns an array of every path. Plain objects are deeply recursed and are not themselves included. | ||
Returns an array of every path. Non-empty plain objects and arrays are deeply recursed and are not themselves included. | ||
@@ -152,2 +152,4 @@ This can be useful to help flatten an object for an API that only accepts key-value pairs or for a tagged template literal. | ||
}, | ||
activeTasks: [], | ||
currentProject: null | ||
}; | ||
@@ -159,2 +161,4 @@ | ||
//=> name.last: Bendall | ||
//=> activeTasks: [] | ||
//=> currentProject: null | ||
} | ||
@@ -161,0 +165,0 @@ ``` |
22
index.js
@@ -6,2 +6,4 @@ const isObject = value => { | ||
const isEmptyObject = value => isObject(value) && Object.keys(value).length === 0; | ||
const disallowedKeys = new Set([ | ||
@@ -23,3 +25,3 @@ '__proto__', | ||
switch (character) { | ||
case '\\': | ||
case '\\': { | ||
if (currentPart === 'index') { | ||
@@ -40,4 +42,5 @@ throw new Error('Invalid character in an index'); | ||
break; | ||
} | ||
case '.': | ||
case '.': { | ||
if (currentPart === 'index') { | ||
@@ -66,4 +69,5 @@ throw new Error('Invalid character in an index'); | ||
break; | ||
} | ||
case '[': | ||
case '[': { | ||
if (currentPart === 'index') { | ||
@@ -95,4 +99,5 @@ throw new Error('Invalid character in an index'); | ||
break; | ||
} | ||
case ']': | ||
case ']': { | ||
if (currentPart === 'index') { | ||
@@ -110,4 +115,5 @@ parts.push(Number.parseInt(currentSegment, 10)); | ||
// Falls through | ||
} | ||
default: | ||
default: { | ||
if (currentPart === 'index' && !digits.has(character)) { | ||
@@ -131,2 +137,3 @@ throw new Error('Invalid character in an index'); | ||
currentSegment += character; | ||
} | ||
} | ||
@@ -159,3 +166,3 @@ } | ||
} | ||
// No default | ||
// No default | ||
} | ||
@@ -288,2 +295,3 @@ | ||
// TODO: Backslashes with no effect should not be escaped | ||
export function escapePath(path) { | ||
@@ -322,3 +330,3 @@ if (typeof path !== 'string') { | ||
function * deepKeysIterator(object, currentPath = []) { | ||
if (!isObject(object)) { | ||
if (!isObject(object) || isEmptyObject(object)) { | ||
if (currentPath.length > 0) { | ||
@@ -325,0 +333,0 @@ yield stringifyPath(currentPath); |
{ | ||
"name": "dot-prop", | ||
"version": "7.2.0", | ||
"version": "8.0.0", | ||
"description": "Get, set, or delete a property from a nested object using a dot path", | ||
@@ -16,3 +16,3 @@ "license": "MIT", | ||
"engines": { | ||
"node": "^12.20.0 || ^14.13.1 || >=16.0.0" | ||
"node": ">=16" | ||
}, | ||
@@ -41,11 +41,11 @@ "scripts": { | ||
"dependencies": { | ||
"type-fest": "^2.11.2" | ||
"type-fest": "^3.8.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^4.0.1", | ||
"ava": "^5.2.0", | ||
"benchmark": "^2.1.4", | ||
"expect-type": "^0.13.0", | ||
"typescript": "^4.5.5", | ||
"xo": "^0.48.0" | ||
"expect-type": "^0.15.0", | ||
"typescript": "^5.0.4", | ||
"xo": "^0.54.1" | ||
} | ||
} |
@@ -46,3 +46,3 @@ # dot-prop | ||
setProperty(object, 'foo.biz.0', 'a'); | ||
setProperty(object, 'foo.biz[0]', 'a'); | ||
console.log(object); | ||
@@ -114,3 +114,3 @@ //=> {foo: {bar: 'b', baz: 'x', biz: ['a']}} | ||
Returns an array of every path. Plain objects are deeply recursed and are not themselves included. | ||
Returns an array of every path. Non-empty plain objects and arrays are deeply recursed and are not themselves included. | ||
@@ -127,2 +127,4 @@ This can be useful to help flatten an object for an API that only accepts key-value pairs or for a tagged template literal. | ||
}, | ||
activeTasks: [], | ||
currentProject: null | ||
}; | ||
@@ -134,2 +136,4 @@ | ||
//=> name.last: Bendall | ||
//=> activeTasks: [] | ||
//=> currentProject: null | ||
} | ||
@@ -167,13 +171,1 @@ ``` | ||
Default value. | ||
--- | ||
<div align="center"> | ||
<b> | ||
<a href="https://tidelift.com/subscription/pkg/npm-dot-prop?utm_source=npm-dot-prop&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a> | ||
</b> | ||
<br> | ||
<sub> | ||
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies. | ||
</sub> | ||
</div> |
390
16646
167
+ Addedtype-fest@3.13.1(transitive)
- Removedtype-fest@2.19.0(transitive)
Updatedtype-fest@^3.8.0