diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c1870cf..441975c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,12 +10,10 @@ jobs: fail-fast: false matrix: node-version: - - 14 - - 12 - - 10 + - 16 steps: - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 + - uses: actions/setup-node@v2 with: node-version: ${{ matrix.node-version }} - run: npm install diff --git a/index.d.ts b/index.d.ts index 58497fd..45cbbd8 100644 --- a/index.d.ts +++ b/index.d.ts @@ -5,12 +5,10 @@ Randomize the order of items in an array. @example ``` -import arrayShuffle = require('array-shuffle'); +import arrayShuffle from 'array-shuffle'; const shuffled = arrayShuffle([1, 2, 3, 4, 5, 6]); //=> [3, 5, 4, 1, 2, 6] ``` */ -declare function arrayShuffle(array: readonly ElementType[]): ElementType[]; - -export = arrayShuffle; +export default function arrayShuffle(array: readonly ElementType[]): ElementType[]; diff --git a/index.js b/index.js index 06cf093..f3653b1 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,4 @@ -'use strict'; - -module.exports = array => { +export default function arrayShuffle(array) { if (!Array.isArray(array)) { throw new TypeError(`Expected an array, got ${typeof array}`); } @@ -13,4 +11,4 @@ module.exports = array => { } return array; -}; +} diff --git a/index.test-d.ts b/index.test-d.ts index a16dc11..f060f4b 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,5 +1,5 @@ import {expectType} from 'tsd'; -import arrayShuffle = require('.'); +import arrayShuffle from './index.js'; const fixture = [1, 2, 3, 4, 5]; diff --git a/package.json b/package.json index e2ed468..be8efe9 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,10 @@ "email": "sindresorhus@gmail.com", "url": "https://sindresorhus.com" }, + "type": "module", + "exports": "./index.js", "engines": { - "node": ">=10" + "node": ">=12.20" }, "scripts": { "test": "xo && ava && tsd" @@ -32,8 +34,8 @@ "durstenfeld" ], "devDependencies": { - "ava": "^3.13.0", - "tsd": "^0.13.1", - "xo": "^0.35.0" + "ava": "^3.15.0", + "tsd": "^0.17.0", + "xo": "^0.42.0" } } diff --git a/readme.md b/readme.md index ddc7afc..0740397 100644 --- a/readme.md +++ b/readme.md @@ -2,7 +2,7 @@ > Randomize the order of items in an array -Uses the [Durstenfeld algorithm](https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#The_modern_algorithm) based on the [Fisher–Yates algorithm](https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle). +Uses the [Durstenfeld algorithm](https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#The_modern_algorithm) which is based on the [Fisher–Yates algorithm](https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle). ## Install @@ -13,7 +13,7 @@ $ npm install array-shuffle ## Usage ```js -const arrayShuffle = require('array-shuffle'); +import arrayShuffle from 'array-shuffle'; const shuffled = arrayShuffle([1, 2, 3, 4, 5, 6]); //=> [3, 5, 4, 1, 2, 6] diff --git a/test.js b/test.js index a58ae8b..71e5d34 100644 --- a/test.js +++ b/test.js @@ -1,6 +1,5 @@ -'use strict'; -const test = require('ava'); -const arrayShuffle = require('.'); +import test from 'ava'; +import arrayShuffle from './index.js'; test('main', t => { t.notDeepEqual(arrayShuffle([1, 2, 3, 4, 5, 6]), [1, 2, 3, 4, 5, 6]);