From 3b67964f070b1fb2e7dd41c92e0dafbd479b397b Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Fri, 10 May 2024 03:23:48 +0700 Subject: [PATCH 1/2] Require Node.js 18 Closes #115 --- .github/funding.yml | 4 -- .github/workflows/main.yml | 5 +-- benchmark.js | 43 ++++++++++++---------- index.js | 2 +- index.test-d.ts | 9 ++++- package.json | 18 +++++---- test.js | 75 ++++++++++++++++++++++---------------- tsconfig.json | 2 +- 8 files changed, 91 insertions(+), 67 deletions(-) delete mode 100644 .github/funding.yml diff --git a/.github/funding.yml b/.github/funding.yml deleted file mode 100644 index 784a3a7..0000000 --- a/.github/funding.yml +++ /dev/null @@ -1,4 +0,0 @@ -github: sindresorhus -open_collective: sindresorhus -tidelift: npm/dot-prop -custom: https://sindresorhus.com/donate diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1ed55d5..346585c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,10 +12,9 @@ jobs: node-version: - 20 - 18 - - 16 steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - run: npm install diff --git a/benchmark.js b/benchmark.js index f868e30..df1c26a 100644 --- a/benchmark.js +++ b/benchmark.js @@ -1,5 +1,10 @@ import Benchmark from 'benchmark'; -import {getProperty, setProperty, hasProperty, deleteProperty} from './index.js'; +import { + getProperty, + setProperty, + hasProperty, + deleteProperty, +} from './index.js'; const suite = new Benchmark.Suite(); @@ -34,11 +39,11 @@ suite getProperty(fixture2, 'foo'); getProperty({}, 'hasOwnProperty'); - function fn() {} - fn.foo = {bar: 1}; - getProperty(fn); - getProperty(fn, 'foo'); - getProperty(fn, 'foo.bar'); + function function_() {} + function_.foo = {bar: 1}; + getProperty(function_); + getProperty(function_, 'foo'); + getProperty(function_, 'foo.bar'); const fixture3 = {foo: null}; getProperty(fixture3, 'foo.bar'); @@ -52,7 +57,7 @@ suite getProperty(undefined, 'foo.bar', false); }) .add('setProperty', () => { - const func = () => 'test'; + const function_ = () => 'test'; let fixture1 = {}; setProperty(fixture1, 'foo', 2); @@ -72,12 +77,12 @@ suite setProperty(fixture1, 'foo.fake.fake2', 'fake'); - setProperty(fixture1, 'foo.function', func); + setProperty(fixture1, 'foo.function', function_); - function fn() {} - setProperty(fn, 'foo.bar', 1); + function function__() {} + setProperty(function__, 'foo.bar', 1); - fixture1.fn = fn; + fixture1.fn = function__; setProperty(fixture1, 'fn.bar.baz', 2); const fixture2 = {foo: null}; @@ -102,24 +107,24 @@ suite hasProperty({foo: {bar: {baz: null}}}, 'foo.bar.baz'); hasProperty({foo: {bar: 'a'}}, 'foo.fake.fake2'); - function fn() {} - fn.foo = {bar: 1}; - hasProperty(fn); - hasProperty(fn, 'foo'); - hasProperty(fn, 'foo.bar'); + function function_() {} + function_.foo = {bar: 1}; + hasProperty(function_); + hasProperty(function_, 'foo'); + hasProperty(function_, 'foo.bar'); hasProperty({'foo.baz': {bar: true}}, 'foo\\.baz.bar'); hasProperty({'fo.ob.az': {bar: true}}, 'fo\\.ob\\.az.bar'); }) .add('deleteProperty', () => { - const func = () => 'test'; - func.foo = 'bar'; + const function_ = () => 'test'; + function_.foo = 'bar'; const inner = { a: 'a', b: 'b', c: 'c', - func, + func: function_, }; const fixture1 = { diff --git a/index.js b/index.js index acc3a53..bdbeb0c 100644 --- a/index.js +++ b/index.js @@ -290,7 +290,7 @@ export function escapePath(path) { throw new TypeError('Expected a string'); } - return path.replace(/[\\.[]/g, '\\$&'); + return path.replaceAll(/[\\.[]/g, '\\$&'); } // The keys returned by Object.entries() for arrays are strings diff --git a/index.test-d.ts b/index.test-d.ts index 016c7c0..a69363d 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,5 +1,12 @@ import {expectTypeOf} from 'expect-type'; -import {getProperty, setProperty, hasProperty, deleteProperty, escapePath, deepKeys} from './index.js'; +import { + getProperty, + setProperty, + hasProperty, + deleteProperty, + escapePath, + deepKeys, +} from './index.js'; expectTypeOf(getProperty({foo: {bar: 'unicorn'}}, 'foo.bar')).toBeString(); expectTypeOf(getProperty({foo: {bar: 'a'}}, 'foo.notDefined.deep')).toBeUndefined(); diff --git a/package.json b/package.json index 4250f23..34b9df7 100644 --- a/package.json +++ b/package.json @@ -11,9 +11,13 @@ "url": "https://sindresorhus.com" }, "type": "module", - "exports": "./index.js", + "exports": { + "types": "./index.d.ts", + "default": "./index.js" + }, + "sideEffects": false, "engines": { - "node": ">=16" + "node": ">=18" }, "scripts": { "test": "xo && ava && tsc", @@ -37,13 +41,13 @@ "dotty" ], "dependencies": { - "type-fest": "^3.8.0" + "type-fest": "^4.18.2" }, "devDependencies": { - "ava": "^5.2.0", + "ava": "^6.1.3", "benchmark": "^2.1.4", - "expect-type": "^0.15.0", - "typescript": "^5.0.4", - "xo": "^0.54.1" + "expect-type": "^0.19.0", + "typescript": "^5.4.5", + "xo": "^0.58.0" } } diff --git a/test.js b/test.js index b8415c1..17cb0e0 100644 --- a/test.js +++ b/test.js @@ -1,5 +1,12 @@ import test from 'ava'; -import {getProperty, setProperty, hasProperty, deleteProperty, escapePath, deepKeys} from './index.js'; +import { + getProperty, + setProperty, + hasProperty, + deleteProperty, + escapePath, + deepKeys, +} from './index.js'; test('getProperty', t => { const fixture1 = {foo: {bar: 1}}; @@ -25,9 +32,11 @@ test('getProperty', t => { t.true(getProperty({'foo\\bar': true}, 'foo\\bar')); t.true(getProperty({'\\': {foo: true}}, '\\\\.foo')); t.true(getProperty({'bar\\.': true}, 'bar\\\\\\.')); - t.true(getProperty({'foo\\': { - bar: true, - }}, 'foo\\\\.bar')); + t.true(getProperty({ + 'foo\\': { + bar: true, + }, + }, 'foo\\\\.bar')); t.is(getProperty({foo: 1}, 'foo.bar'), undefined); t.true(getProperty({'foo\\': true}, 'foo\\')); @@ -39,11 +48,11 @@ test('getProperty', t => { t.is(getProperty(fixture2, 'foo'), 'bar'); t.is(getProperty({}, 'hasOwnProperty'), Object.prototype.hasOwnProperty); - function fn() {} - fn.foo = {bar: 1}; - t.is(getProperty(fn), fn); - t.is(getProperty(fn, 'foo'), fn.foo); - t.is(getProperty(fn, 'foo.bar'), 1); + function function_() {} + function_.foo = {bar: 1}; + t.is(getProperty(function_), function_); + t.is(getProperty(function_, 'foo'), function_.foo); + t.is(getProperty(function_, 'foo.bar'), 1); const f3 = {foo: null}; t.is(getProperty(f3, 'foo.bar'), undefined); @@ -135,9 +144,11 @@ test('getProperty - with array indexes', t => { t.false(getProperty([true], '0', false)); t.false(getProperty({foo: [true]}, 'foo.0', false)); - t.true(getProperty({foo: { - 0: true, - }}, 'foo.0')); + t.true(getProperty({ + foo: { + 0: true, + }, + }, 'foo.0')); t.true(getProperty([{ '[1]': true, @@ -161,7 +172,7 @@ test('getProperty - with array indexes', t => { }); test('setProperty', t => { - const func = () => 'test'; + const function_ = () => 'test'; let fixture1 = {}; const o1 = setProperty(fixture1, 'foo', 2); @@ -190,14 +201,14 @@ test('setProperty', t => { setProperty(fixture1, 'foo.fake.fake2', 'fake'); t.is(fixture1.foo.fake.fake2, 'fake'); - setProperty(fixture1, 'foo.function', func); - t.is(fixture1.foo.function, func); + setProperty(fixture1, 'foo.function', function_); + t.is(fixture1.foo.function, function_); - function fn() {} - setProperty(fn, 'foo.bar', 1); - t.is(fn.foo.bar, 1); + function function__() {} + setProperty(function__, 'foo.bar', 1); + t.is(function__.foo.bar, 1); - fixture1.fn = fn; + fixture1.fn = function__; setProperty(fixture1, 'fn.bar.baz', 2); t.is(fixture1.fn.bar.baz, 2); @@ -253,14 +264,14 @@ test('setProperty', t => { }); test('deleteProperty', t => { - const func = () => 'test'; - func.foo = 'bar'; + const function_ = () => 'test'; + function_.foo = 'bar'; const inner = { a: 'a', b: 'b', c: 'c', - func, + func: function_, }; const fixture1 = { foo: { @@ -285,7 +296,7 @@ test('deleteProperty', t => { t.true(deleteProperty(fixture1, 'foo.bar.baz.func.foo')); t.is(fixture1.foo.bar.baz.func.foo, undefined); - t.is(fixture1.foo.bar.baz.func, func); + t.is(fixture1.foo.bar.baz.func, function_); t.true(deleteProperty(fixture1, 'foo.bar.baz.func')); t.is(fixture1.foo.bar.baz.func, undefined); @@ -362,11 +373,11 @@ test('hasProperty', t => { t.false(hasProperty({foo: null}, 'foo.bar')); t.false(hasProperty({foo: ''}, 'foo.bar')); - function fn() {} - fn.foo = {bar: 1}; - t.false(hasProperty(fn)); - t.true(hasProperty(fn, 'foo')); - t.true(hasProperty(fn, 'foo.bar')); + function function_() {} + function_.foo = {bar: 1}; + t.false(hasProperty(function_)); + t.true(hasProperty(function_, 'foo')); + t.true(hasProperty(function_, 'foo.bar')); t.true(hasProperty({'foo.baz': {bar: true}}, 'foo\\.baz.bar')); t.true(hasProperty({'fo.ob.az': {bar: true}}, 'fo\\.ob\\.az.bar')); @@ -382,9 +393,11 @@ test('hasProperty', t => { foo: [{bar: ['bar', 'bizz']}], }, 'foo[1].bar.1')); t.true(hasProperty({ - foo: [{bar: { - 1: 'bar', - }}], + foo: [{ + bar: { + 1: 'bar', + }, + }], }, 'foo[0].bar.1')); }); diff --git a/tsconfig.json b/tsconfig.json index 1c6f054..23816d3 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "lib": [ - "es2021" + "es2022" ], "strict": true, "noEmit": true From 35eda392c035264bed686463ff625a750f6a82df Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Fri, 10 May 2024 03:30:08 +0700 Subject: [PATCH 2/2] 9.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 34b9df7..27a1d2a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dot-prop", - "version": "8.0.2", + "version": "9.0.0", "description": "Get, set, or delete a property from a nested object using a dot path", "license": "MIT", "repository": "sindresorhus/dot-prop",