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 19446c0 commit b8ebe92
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 50 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@ jobs:
node-version:
- 14
- 12
- 10
- 8
- 6
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
26 changes: 10 additions & 16 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
declare namespace parseMilliseconds {
interface Parsed {
days: number;
hours: number;
minutes: number;
seconds: number;
milliseconds: number;
microseconds: number;
nanoseconds: number;
}
export interface TimeComponents {
days: number;
hours: number;
minutes: number;
seconds: number;
milliseconds: number;
microseconds: number;
nanoseconds: number;
}

/**
Parse milliseconds into an object.
@example
```
import parseMilliseconds = require('parse-ms');
import parseMilliseconds from 'parse-ms';
parseMilliseconds(1337000001);
// {
Expand All @@ -29,8 +27,4 @@ parseMilliseconds(1337000001);
// }
```
*/
declare function parseMilliseconds(
milliseconds: number
): parseMilliseconds.Parsed;

export = parseMilliseconds;
export default function parseMilliseconds(milliseconds: number): TimeComponents;
5 changes: 2 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict';
module.exports = milliseconds => {
export default function parseMilliseconds(milliseconds) {
if (typeof milliseconds !== 'number') {
throw new TypeError('Expected a number');
}
Expand All @@ -15,4 +14,4 @@ module.exports = milliseconds => {
microseconds: roundTowardsZero(milliseconds * 1000) % 1000,
nanoseconds: roundTowardsZero(milliseconds * 1e6) % 1000
};
};
}
18 changes: 9 additions & 9 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {expectType} from 'tsd';
import parseMilliseconds = require('.');
import parseMilliseconds, {TimeComponents} from './index.js';

const parsed: parseMilliseconds.Parsed = parseMilliseconds(3000);
const components: TimeComponents = parseMilliseconds(3000);

expectType<number>(parsed.days);
expectType<number>(parsed.hours);
expectType<number>(parsed.minutes);
expectType<number>(parsed.seconds);
expectType<number>(parsed.milliseconds);
expectType<number>(parsed.microseconds);
expectType<number>(parsed.nanoseconds);
expectType<number>(components.days);
expectType<number>(components.hours);
expectType<number>(components.minutes);
expectType<number>(components.seconds);
expectType<number>(components.milliseconds);
expectType<number>(components.microseconds);
expectType<number>(components.nanoseconds);
2 changes: 1 addition & 1 deletion license
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) Sindre Sorhus <[email protected]> (sindresorhus.com)
Copyright (c) Sindre Sorhus <[email protected]> (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
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
"description": "Parse milliseconds into an object",
"license": "MIT",
"repository": "sindresorhus/parse-ms",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {
"name": "Sindre Sorhus",
"email": "[email protected]",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=6"
"node": ">=12"
},
"scripts": {
"test": "xo && ava && tsd"
Expand All @@ -33,8 +36,8 @@
"interval"
],
"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"
}
}
10 changes: 1 addition & 9 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@

> Parse milliseconds into an object

## Install

```
$ npm install parse-ms
```


## Usage

```js
const parseMilliseconds = require('parse-ms');
import parseMilliseconds from 'parse-ms';

parseMilliseconds(1337000001);
/*
Expand All @@ -29,13 +27,7 @@ parseMilliseconds(1337000001);
*/
```


## Related

- [to-milliseconds](https://github.com/sindresorhus/to-milliseconds) - The inverse of this module
- [pretty-ms](https://github.com/sindresorhus/pretty-ms) - Convert milliseconds to a human readable string


## License

MIT © [Sindre Sorhus](https://sindresorhus.com)
6 changes: 3 additions & 3 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from 'ava';
import parseMilliseconds from '.';
import parseMilliseconds from './index.js';

test('parse milliseconds into an object', t => {
t.deepEqual(parseMilliseconds(1000 + 400), {
Expand Down Expand Up @@ -113,8 +113,8 @@ test('handle negative millisecond values', t => {
];

const times = [
0.000500,
0.300,
0.0005,
0.3,
100 + 400,
1000 * 55,
1000 * 67,
Expand Down

0 comments on commit b8ebe92

Please sign in to comment.