Skip to content

Commit

Permalink
fix set function to allow falsy values (sodiray#263)
Browse files Browse the repository at this point in the history
  • Loading branch information
jovanadjuric authored Jun 26, 2023
1 parent 82fea7a commit f2e6948
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cdn/radash.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ const get = (value, path, defaultValue) => {
const set = (initial, path, value) => {
if (!initial)
return {};
if (!path || !value)
if (!path || value === void 0)
return initial;
const segments = path.split(/[\.\[\]]/g).filter((x) => !!x.trim());
const _set = (node) => {
Expand Down
2 changes: 1 addition & 1 deletion cdn/radash.js
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ var radash = (function (exports) {
const set = (initial, path, value) => {
if (!initial)
return {};
if (!path || !value)
if (!path || value === void 0)
return initial;
const segments = path.split(/[\.\[\]]/g).filter((x) => !!x.trim());
const _set = (node) => {
Expand Down
2 changes: 1 addition & 1 deletion src/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export const set = <T extends object, K>(
value: K
): T => {
if (!initial) return {} as T
if (!path || !value) return initial
if (!path || value === undefined) return initial
const segments = path.split(/[\.\[\]]/g).filter(x => !!x.trim())
const _set = (node: any) => {
if (segments.length > 1) {
Expand Down
2 changes: 2 additions & 0 deletions src/tests/object.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,8 @@ describe('object module', () => {
assert.deepEqual(_.set({}, '', null as any), {})
assert.deepEqual(_.set(null as any, '', {}), {})
assert.deepEqual(_.set(null as any, null as any, null as any), {})
assert.deepEqual(_.set({ foo: true }, 'foo', false), { foo: false })
assert.deepEqual(_.set({}, 'foo', 0), { foo: 0 })
})
test('sets deep values correctly', () => {
assert.deepEqual(_.set({}, 'cards.value', 2), {
Expand Down

0 comments on commit f2e6948

Please sign in to comment.