First upload version 0.0.1
This commit is contained in:
30
node_modules/parse-ms/index.d.ts
generated
vendored
Normal file
30
node_modules/parse-ms/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
export type TimeComponents<T extends (number | bigint) = number> = {
|
||||
days: T;
|
||||
hours: T;
|
||||
minutes: T;
|
||||
seconds: T;
|
||||
milliseconds: T;
|
||||
microseconds: T;
|
||||
nanoseconds: T;
|
||||
};
|
||||
|
||||
/**
|
||||
Parse milliseconds into an object.
|
||||
|
||||
@example
|
||||
```
|
||||
import parseMilliseconds from 'parse-ms';
|
||||
|
||||
parseMilliseconds(1337000001);
|
||||
// {
|
||||
// days: 15,
|
||||
// hours: 11,
|
||||
// minutes: 23,
|
||||
// seconds: 20,
|
||||
// milliseconds: 1,
|
||||
// microseconds: 0,
|
||||
// nanoseconds: 0
|
||||
// }
|
||||
```
|
||||
*/
|
||||
export default function parseMilliseconds<T extends number | bigint>(milliseconds: T): TimeComponents<T>;
|
||||
45
node_modules/parse-ms/index.js
generated
vendored
Normal file
45
node_modules/parse-ms/index.js
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
const toZeroIfInfinity = value => Number.isFinite(value) ? value : 0;
|
||||
|
||||
function parseNumber(milliseconds) {
|
||||
return {
|
||||
days: Math.trunc(milliseconds / 86_400_000),
|
||||
hours: Math.trunc(milliseconds / 3_600_000 % 24),
|
||||
minutes: Math.trunc(milliseconds / 60_000 % 60),
|
||||
seconds: Math.trunc(milliseconds / 1000 % 60),
|
||||
milliseconds: Math.trunc(milliseconds % 1000),
|
||||
microseconds: Math.trunc(toZeroIfInfinity(milliseconds * 1000) % 1000),
|
||||
nanoseconds: Math.trunc(toZeroIfInfinity(milliseconds * 1e6) % 1000),
|
||||
};
|
||||
}
|
||||
|
||||
function parseBigint(milliseconds) {
|
||||
return {
|
||||
days: milliseconds / 86_400_000n,
|
||||
hours: milliseconds / 3_600_000n % 24n,
|
||||
minutes: milliseconds / 60_000n % 60n,
|
||||
seconds: milliseconds / 1000n % 60n,
|
||||
milliseconds: milliseconds % 1000n,
|
||||
microseconds: 0n,
|
||||
nanoseconds: 0n,
|
||||
};
|
||||
}
|
||||
|
||||
export default function parseMilliseconds(milliseconds) {
|
||||
switch (typeof milliseconds) {
|
||||
case 'number': {
|
||||
if (Number.isFinite(milliseconds)) {
|
||||
return parseNumber(milliseconds);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 'bigint': {
|
||||
return parseBigint(milliseconds);
|
||||
}
|
||||
|
||||
// No default
|
||||
}
|
||||
|
||||
throw new TypeError('Expected a finite number or bigint');
|
||||
}
|
||||
9
node_modules/parse-ms/license
generated
vendored
Normal file
9
node_modules/parse-ms/license
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
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:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
47
node_modules/parse-ms/package.json
generated
vendored
Normal file
47
node_modules/parse-ms/package.json
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
{
|
||||
"name": "parse-ms",
|
||||
"version": "4.0.0",
|
||||
"description": "Parse milliseconds into an object",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/parse-ms",
|
||||
"funding": "https://github.com/sponsors/sindresorhus",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "https://sindresorhus.com"
|
||||
},
|
||||
"type": "module",
|
||||
"exports": {
|
||||
"types": "./index.d.ts",
|
||||
"default": "./index.js"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava && tsd"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"index.d.ts"
|
||||
],
|
||||
"keywords": [
|
||||
"browser",
|
||||
"parse",
|
||||
"time",
|
||||
"ms",
|
||||
"milliseconds",
|
||||
"microseconds",
|
||||
"nanoseconds",
|
||||
"duration",
|
||||
"period",
|
||||
"range",
|
||||
"interval"
|
||||
],
|
||||
"devDependencies": {
|
||||
"ava": "^6.0.1",
|
||||
"tsd": "^0.30.3",
|
||||
"xo": "^0.56.0"
|
||||
}
|
||||
}
|
||||
46
node_modules/parse-ms/readme.md
generated
vendored
Normal file
46
node_modules/parse-ms/readme.md
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
# parse-ms
|
||||
|
||||
> Parse milliseconds into an object
|
||||
|
||||
## Install
|
||||
|
||||
```sh
|
||||
npm install parse-ms
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
import parseMilliseconds from 'parse-ms';
|
||||
|
||||
parseMilliseconds(1337000001);
|
||||
/*
|
||||
{
|
||||
days: 15,
|
||||
hours: 11,
|
||||
minutes: 23,
|
||||
seconds: 20,
|
||||
milliseconds: 1,
|
||||
microseconds: 0,
|
||||
nanoseconds: 0
|
||||
}
|
||||
*/
|
||||
|
||||
parseMilliseconds(1337000001n);
|
||||
/*
|
||||
{
|
||||
days: 15n,
|
||||
hours: 11n,
|
||||
minutes: 23n,
|
||||
seconds: 20n,
|
||||
milliseconds: 1n,
|
||||
microseconds: 0n,
|
||||
nanoseconds: 0n
|
||||
}
|
||||
*/
|
||||
```
|
||||
|
||||
## 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
|
||||
Reference in New Issue
Block a user