Skip to content

Commit

Permalink
Require Node.js 12 and move to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Apr 9, 2021
1 parent ef27f5a commit 5db9743
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 37 deletions.
3 changes: 0 additions & 3 deletions .github/funding.yml

This file was deleted.

4 changes: 1 addition & 3 deletions .github/workflows/main.yml
Expand Up @@ -12,11 +12,9 @@ jobs:
node-version:
- 14
- 12
- 10
- 8
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm install
Expand Down
8 changes: 2 additions & 6 deletions index.d.ts
Expand Up @@ -5,16 +5,12 @@ Get consecutively unique elements from an array.
@example
```
import uniqueRandomArray = require('unique-random-array');
import uniqueRandomArray from 'unique-random-array';
const random = uniqueRandomArray([1, 2, 3, 4]);
console.log(random(), random(), random(), random());
//=> 4 2 1 4
```
*/
declare function uniqueRandomArray<ValueType>(
array: readonly ValueType[]
): () => ValueType;

export = uniqueRandomArray;
export default function uniqueRandomArray<T>(array: readonly T[]): () => T;
7 changes: 3 additions & 4 deletions index.js
@@ -1,7 +1,6 @@
'use strict';
const uniqueRandom = require('unique-random');
import uniqueRandom from 'unique-random';

module.exports = array => {
export default function uniqueRandomArray(array) {
const random = uniqueRandom(0, array.length - 1);
return () => array[random()];
};
}
2 changes: 1 addition & 1 deletion index.test-d.ts
@@ -1,5 +1,5 @@
import {expectType} from 'tsd';
import uniqueRandomArray = require('.');
import uniqueRandomArray from './index.js';

expectType<() => number>(uniqueRandomArray([1, 2, 3, 4]));
expectType<() => string | number>(uniqueRandomArray(['1', 2, 3, 4]));
2 changes: 1 addition & 1 deletion license
@@ -1,6 +1,6 @@
MIT License

Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)

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:

Expand Down
15 changes: 9 additions & 6 deletions package.json
Expand Up @@ -4,13 +4,16 @@
"description": "Get consecutively unique elements from an array",
"license": "MIT",
"repository": "sindresorhus/unique-random-array",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=8"
"node": ">=12"
},
"scripts": {
"test": "xo && ava && tsd"
Expand All @@ -31,11 +34,11 @@
"element"
],
"dependencies": {
"unique-random": "^2.1.0"
"unique-random": "^3.0.0"
},
"devDependencies": {
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
"ava": "^3.15.0",
"tsd": "^0.14.0",
"xo": "^0.38.2"
}
}
11 changes: 1 addition & 10 deletions readme.md
Expand Up @@ -4,26 +4,23 @@
Useful for things like slideshows where you don't want to have the same slide twice in a row.


## Install

```
$ npm install unique-random-array
```


## Usage

```js
const uniqueRandomArray = require('unique-random-array');
import uniqueRandomArray from 'unique-random-array';

const random = uniqueRandomArray([1, 2, 3, 4]);

console.log(random(), random(), random(), random());
//=> 4 2 1 4
```


## API

### uniqueRandomArray(array)
Expand All @@ -34,7 +31,6 @@ Returns a function, that when called, will return a random element that's never

Type: `unknown[]`


## Related

- [unique-random](https://github.com/sindresorhus/unique-random) - Generate random numbers that are consecutively unique
Expand All @@ -44,8 +40,3 @@ Type: `unknown[]`
- [random-obj-key](https://github.com/sindresorhus/random-obj-key) - Get a random key from an object
- [random-obj-prop](https://github.com/sindresorhus/random-obj-prop) - Get a random property from an object
- [crypto-random-string](https://github.com/sindresorhus/crypto-random-string) - Generate a cryptographically strong random string


## License

MIT © [Sindre Sorhus](https://sindresorhus.com)
6 changes: 3 additions & 3 deletions test.js
@@ -1,13 +1,13 @@
import test from 'ava';
import uniqueRandomArray from '.';
import uniqueRandomArray from './index.js';

test('main', t => {
const random = uniqueRandomArray([1, 2, 3, 4]);

let current;
let previous;
let i = 100;
while (i--) {
let index = 100;
while (index--) {
current = random();
t.not(current, previous);
previous = current;
Expand Down

0 comments on commit 5db9743

Please sign in to comment.