Skip to content

Commit da0bc0e

Browse files
committed
Require Node.js 12.20 and move to ESM
1 parent 100162b commit da0bc0e

File tree

8 files changed

+22
-33
lines changed

8 files changed

+22
-33
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,10 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
node-version:
13-
- 14
14-
- 12
15-
- 10
16-
- 8
17-
- 6
13+
- 16
1814
steps:
1915
- uses: actions/checkout@v2
20-
- uses: actions/setup-node@v1
16+
- uses: actions/setup-node@v2
2117
with:
2218
node-version: ${{ matrix.node-version }}
2319
- run: npm install

index.d.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Negative array index support `array[-1]` using [ES2015 `Proxy`](https://ponyfoo.
33
44
@example
55
```
6-
import negativeArray = require('negative-array');
6+
import negativeArray from 'negative-array';
77
88
// Adds negative array index support to any given array
99
const unicorn = negativeArray(['🐴', '🎂', '🌈']);
@@ -15,6 +15,4 @@ console.log(unicorn[-1]);
1515
// OMG, YES!
1616
```
1717
*/
18-
declare function negativeArray<T extends readonly unknown[]>(array: T): T;
19-
20-
export = negativeArray;
18+
export default function negativeArray<T extends readonly unknown[]>(array: T): T;

index.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
'use strict';
2-
3-
module.exports = array => {
1+
export default function negativeArray(array) {
42
if (!Array.isArray(array)) {
53
throw new TypeError('Expected an array');
64
}
@@ -33,6 +31,6 @@ module.exports = array => {
3331
target[index < 0 ? target.length + index : index] = value;
3432

3533
return true;
36-
}
34+
},
3735
});
38-
};
36+
}

index.test-d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import {expectType, expectError} from 'tsd';
2-
import negativeArray = require('.');
1+
import {expectType, expectError, expectAssignable} from 'tsd';
2+
import negativeArray from './index.js';
33

44
const readonlyArray = ['🐴', '🎂', '🌈'] as const;
55
const array = ['🐴', '🎂', '🌈'];
66

7-
expectType<readonly string[]>(negativeArray(readonlyArray));
7+
expectAssignable<readonly string[]>(negativeArray(readonlyArray));
88
expectError(negativeArray(readonlyArray).push('🦄'));
99
expectType<string[]>(negativeArray(array));

license

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) Sindre Sorhus <[email protected]> (sindresorhus.com)
3+
Copyright (c) Sindre Sorhus <[email protected]> (https://sindresorhus.com)
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
66

package.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
"description": "Negative array index support `array[-1]` using ES2015 Proxy",
55
"license": "MIT",
66
"repository": "sindresorhus/negative-array",
7+
"funding": "https://github.com/sponsors/sindresorhus",
78
"author": {
89
"name": "Sindre Sorhus",
910
"email": "[email protected]",
10-
"url": "sindresorhus.com"
11+
"url": "https://sindresorhus.com"
1112
},
13+
"type": "module",
14+
"exports": "./index.js",
1215
"engines": {
13-
"node": ">=6"
16+
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
1417
},
1518
"scripts": {
1619
"test": "xo && ava && tsd"
@@ -30,8 +33,8 @@
3033
"es2015"
3134
],
3235
"devDependencies": {
33-
"ava": "^1.4.1",
34-
"tsd": "^0.7.2",
35-
"xo": "^0.24.0"
36+
"ava": "^3.15.0",
37+
"tsd": "^0.17.0",
38+
"xo": "^0.44.0"
3639
}
3740
}

readme.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
55
JavaScript doesn't natively support the use of a negative index to get items backwards from the end, but with [ES2015 Proxy](http://soft.vub.ac.be/~tvcutsem/proxies/) it's possible. Take a look at the [source](index.js) to see how simple it is to implement and read this [short article](http://dailyjs.com/2013/11/15/negative-array/) about it.
66

7+
**Note:** With [Node.js 16.6.0](https://nodejs.org/en/blog/release/v16.6.0/), you can now use `Array#at()` instead of this package.
78

89
## Install
910

1011
```
1112
$ npm install negative-array
1213
```
1314

14-
1515
## Usage
1616

1717
```js
18-
const negativeArray = require('negative-array');
18+
import negativeArray from 'negative-array';
1919

2020
// Adds negative array index support to any given array
2121
const unicorn = negativeArray(['🐴', '🎂', '🌈']);
@@ -27,13 +27,7 @@ console.log(unicorn[-1]);
2727
// OMG, YES!
2828
```
2929

30-
3130
## Related
3231

3332
- [on-change](https://github.com/sindresorhus/on-change) - Watch an object or array for changes (Uses `Proxy` too)
3433
- [known](https://github.com/sindresorhus/known) - Allow only access to known object properties (Uses `Proxy` too)
35-
36-
37-
## License
38-
39-
MIT © [Sindre Sorhus](https://sindresorhus.com)

test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import test from 'ava';
2-
import negativeArray from '.';
2+
import negativeArray from './index.js';
33

44
test('quacks like an array', t => {
55
const fixture = negativeArray(['foo', 'bar', 'baz']);

0 commit comments

Comments
 (0)