Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: sindresorhus/dot-prop
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v7.1.0
Choose a base ref
...
head repository: sindresorhus/dot-prop
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v7.1.1
Choose a head ref
  • 2 commits
  • 3 files changed
  • 2 contributors

Commits on Jan 22, 2022

  1. Verified

    This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    d363922 View commit details
  2. 7.1.1

    sindresorhus committed Jan 22, 2022
    Copy the full SHA
    bf3c2a6 View commit details
Showing with 8 additions and 5 deletions.
  1. +2 −4 index.js
  2. +1 −1 package.json
  3. +5 −0 test.js
6 changes: 2 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -219,12 +219,10 @@ export function setProperty(object, path, value) {

assertNotStringIndex(object, key);

if (!isObject(object[key])) {
object[key] = typeof pathArray[index + 1] === 'number' ? [] : {};
}

if (index === pathArray.length - 1) {
object[key] = value;
} else if (!isObject(object[key])) {
object[key] = typeof pathArray[index + 1] === 'number' ? [] : {};
}

object = object[key];
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dot-prop",
"version": "7.1.0",
"version": "7.1.1",
"description": "Get, set, or delete a property from a nested object using a dot path",
"license": "MIT",
"repository": "sindresorhus/dot-prop",
5 changes: 5 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -245,6 +245,11 @@ test('setProperty', t => {
bar: true,
}],
});

const fixture7 = {foo: ['bar', 'baz']};
setProperty(fixture7, 'foo.length', 1);
t.is(fixture7.foo.length, 1);
t.deepEqual(fixture7, {foo: ['bar']});
});

test('deleteProperty', t => {