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 18, 2021
1 parent 6ce6b23 commit bc775dd
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 22 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
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
10 changes: 5 additions & 5 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable import/export */

/**
Generate a random [float](https://en.wikipedia.org/wiki/Floating_point).
Expand All @@ -7,7 +9,7 @@ Generate a random [float](https://en.wikipedia.org/wiki/Floating_point).
@example
```
import randomFloat = require('random-float');
import randomFloat from 'random-float';
randomFloat(5);
//=> 4.401887938147411
Expand All @@ -16,7 +18,5 @@ randomFloat(10, 100);
//=> 72.34217455144972
```
*/
declare function randomFloat(maximum?: number): number;
declare function randomFloat(minimum: number, maximum: number): number;

export = randomFloat;
export default function randomFloat(maximum?: number): number;
export default function randomFloat(minimum: number, maximum: number): number; // eslint-disable-line @typescript-eslint/unified-signatures
6 changes: 2 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

module.exports = (minimum, maximum) => {
export default function randomFloat(minimum, maximum) {
if (maximum === undefined) {
maximum = minimum;
minimum = 0;
Expand All @@ -11,4 +9,4 @@ module.exports = (minimum, maximum) => {
}

return (Math.random() * (maximum - minimum)) + minimum;
};
}
2 changes: 1 addition & 1 deletion index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {expectType} from 'tsd';
import randomFloat = require('.');
import randomFloat from './index.js';

expectType<number>(randomFloat());
expectType<number>(randomFloat(5));
Expand Down
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
"email": "sindresorhus@gmail.com",
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=8"
"node": ">=12"
},
"scripts": {
"test": "xo && ava && tsd"
Expand All @@ -35,11 +37,11 @@
"generator"
],
"devDependencies": {
"ava": "^1.4.1",
"in-range": "^2.0.0",
"number-is-float": "^1.0.0",
"stable-fn": "^2.0.0",
"tsd": "^0.7.2",
"xo": "^0.24.0"
"ava": "^3.15.0",
"in-range": "^3.0.0",
"number-is-float": "^2.0.0",
"stable-fn": "^3.0.0",
"tsd": "^0.14.0",
"xo": "^0.38.2"
}
}
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ $ npm install random-float
## Usage

```js
const randomFloat = require('random-float');
import randomFloat from 'random-float';

randomFloat(5);
//=> 4.401887938147411
Expand Down
2 changes: 1 addition & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import test from 'ava';
import numberIsFloat from 'number-is-float';
import inRange from 'in-range';
import stableFn from 'stable-fn';
import randomFloat from '.';
import randomFloat from './index.js';

const inRangeCheck = ({start, end}) => stableFn(() => inRange(randomFloat(start, end), {start, end}));

Expand Down

0 comments on commit bc775dd

Please sign in to comment.