Skip to content

Commit

Permalink
fix: nx.del not exist value should work
Browse files Browse the repository at this point in the history
  • Loading branch information
afeiship committed Aug 7, 2024
1 parent 9c2a7c8 commit 2042975
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
7 changes: 7 additions & 0 deletions __tests__/base/nx.del.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const nx = require('../../dist/index');

// /Users/a7/github/next/__tests__/base/nx.del.test.js
describe('nx.get name/path', () => {
test('nx.del should worked', () => {
var obj = { name: 'afeiship', a: { b: { c: 'c-value' } } };
Expand All @@ -10,5 +11,11 @@ describe('nx.get name/path', () => {
expect(obj).toEqual({ name: 'afeiship', a: { b: {} } });
});

test('del path has not exists value should get false', () => {
const obj = { name: 'afei' };
const res1 = nx.del(obj, 'preferences_tag.US');
expect(res1).toBe(false);
});

// https://github.com/sindresorhus/dot-prop/blob/master/test.js
});
3 changes: 2 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ else if (freeModule) {
var path = paths[i];

if (i === paths.length - 1) {
delete inTarget[path];
if (inTarget == null) return false;
if (typeof inTarget === 'object') delete inTarget[path];
return true;
}
inTarget = inTarget[path];
Expand Down
2 changes: 1 addition & 1 deletion dist/index.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@
var path = paths[i];

if (i === paths.length - 1) {
delete inTarget[path];
if (inTarget == null) return false;
if (typeof inTarget === 'object') delete inTarget[path];
return true;
}
inTarget = inTarget[path];
Expand Down

0 comments on commit 2042975

Please sign in to comment.