Skip to content

Commit

Permalink
Require Node.js 18
Browse files Browse the repository at this point in the history
Closes #115
  • Loading branch information
sindresorhus committed May 9, 2024
1 parent 3dd188c commit 3b67964
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 67 deletions.
4 changes: 0 additions & 4 deletions .github/funding.yml

This file was deleted.

5 changes: 2 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 24 additions & 19 deletions benchmark.js
Original file line number Diff line number Diff line change
@@ -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();

Expand Down Expand Up @@ -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');
Expand All @@ -52,7 +57,7 @@ suite
getProperty(undefined, 'foo.bar', false);
})
.add('setProperty', () => {
const func = () => 'test';
const function_ = () => 'test';
let fixture1 = {};

setProperty(fixture1, 'foo', 2);
Expand All @@ -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};
Expand All @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion index.test-d.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
18 changes: 11 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
}
75 changes: 44 additions & 31 deletions test.js
Original file line number Diff line number Diff line change
@@ -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}};
Expand All @@ -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\\'));

Expand All @@ -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);
Expand Down Expand Up @@ -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,
Expand All @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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: {
Expand All @@ -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);

Expand Down Expand Up @@ -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'));
Expand All @@ -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'));
});

Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"lib": [
"es2021"
"es2022"
],
"strict": true,
"noEmit": true
Expand Down

0 comments on commit 3b67964

Please sign in to comment.