First upload version 0.0.1
This commit is contained in:
157
node_modules/pretty-ms/index.d.ts
generated
vendored
Normal file
157
node_modules/pretty-ms/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,157 @@
|
||||
export type Options = {
|
||||
/**
|
||||
Number of digits to appear after the seconds decimal point.
|
||||
|
||||
@default 1
|
||||
*/
|
||||
readonly secondsDecimalDigits?: number;
|
||||
|
||||
/**
|
||||
Number of digits to appear after the milliseconds decimal point.
|
||||
|
||||
Useful in combination with [`process.hrtime()`](https://nodejs.org/api/process.html#process_process_hrtime).
|
||||
|
||||
@default 0
|
||||
*/
|
||||
readonly millisecondsDecimalDigits?: number;
|
||||
|
||||
/**
|
||||
Keep milliseconds on whole seconds: `13s` → `13.0s`.
|
||||
|
||||
Useful when you are showing a number of seconds spent on an operation and don't want the width of the output to change when hitting a whole number.
|
||||
|
||||
@default false
|
||||
*/
|
||||
readonly keepDecimalsOnWholeSeconds?: boolean;
|
||||
|
||||
/**
|
||||
Only show the first unit: `1h 10m` → `1h`.
|
||||
|
||||
Also ensures that `millisecondsDecimalDigits` and `secondsDecimalDigits` are both set to `0`.
|
||||
|
||||
@default false
|
||||
*/
|
||||
readonly compact?: boolean;
|
||||
|
||||
/**
|
||||
Number of units to show. Setting `compact` to `true` overrides this option.
|
||||
|
||||
@default Infinity
|
||||
*/
|
||||
readonly unitCount?: number;
|
||||
|
||||
/**
|
||||
Use full-length units: `5h 1m 45s` → `5 hours 1 minute 45 seconds`.
|
||||
|
||||
@default false
|
||||
*/
|
||||
readonly verbose?: boolean;
|
||||
|
||||
/**
|
||||
Show milliseconds separately. This means they won't be included in the decimal part of the seconds.
|
||||
|
||||
@default false
|
||||
*/
|
||||
readonly separateMilliseconds?: boolean;
|
||||
|
||||
/**
|
||||
Show microseconds and nanoseconds.
|
||||
|
||||
@default false
|
||||
*/
|
||||
readonly formatSubMilliseconds?: boolean;
|
||||
|
||||
/**
|
||||
Display time using colon notation: `5h 1m 45s` → `5:01:45`. Always shows time in at least minutes: `1s` → `0:01`
|
||||
|
||||
Useful when you want to display time without the time units, similar to a digital watch.
|
||||
|
||||
Setting `colonNotation` to `true` overrides the following options to `false`:
|
||||
- `compact`
|
||||
- `formatSubMilliseconds`
|
||||
- `separateMilliseconds`
|
||||
- `verbose`
|
||||
|
||||
@default false
|
||||
*/
|
||||
readonly colonNotation?: boolean;
|
||||
|
||||
/**
|
||||
Hides the year and shows the hidden year additionally as days (365 per year): `1y 3d 5h 1m 45s` → `368d 5h 1m 45s`.
|
||||
|
||||
@default false
|
||||
*/
|
||||
readonly hideYear?: boolean;
|
||||
|
||||
/**
|
||||
Hides the year and days and shows the hidden values additionally as hours: `1y 3d 5h 1m 45s` → `8837h 1m 45s`.
|
||||
|
||||
@default false
|
||||
*/
|
||||
readonly hideYearAndDays?: boolean;
|
||||
|
||||
/**
|
||||
Hides the seconds: `1y 3d 5h 1m 45s` → `1y 3d 5h 1m`.
|
||||
|
||||
@default false
|
||||
*/
|
||||
readonly hideSeconds?: boolean;
|
||||
|
||||
/**
|
||||
Show sub-second values as decimal seconds: `900ms` → `0.9s`.
|
||||
|
||||
Useful for progress indicators where you want consistent unit format to prevent flickering.
|
||||
|
||||
@default false
|
||||
*/
|
||||
readonly subSecondsAsDecimals?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
Convert milliseconds to a human readable string: `1337000000` → `15d 11h 23m 20s`.
|
||||
|
||||
@param milliseconds - Milliseconds to humanize.
|
||||
|
||||
@example
|
||||
```
|
||||
import prettyMilliseconds from 'pretty-ms';
|
||||
|
||||
prettyMilliseconds(1337000000);
|
||||
//=> '15d 11h 23m 20s'
|
||||
|
||||
prettyMilliseconds(1337);
|
||||
//=> '1.3s'
|
||||
|
||||
prettyMilliseconds(133);
|
||||
//=> '133ms'
|
||||
|
||||
// `compact` option
|
||||
prettyMilliseconds(1337, {compact: true});
|
||||
//=> '1s'
|
||||
|
||||
// `verbose` option
|
||||
prettyMilliseconds(1335669000, {verbose: true});
|
||||
//=> '15 days 11 hours 1 minute 9 seconds'
|
||||
|
||||
// `colonNotation` option
|
||||
prettyMilliseconds(95500, {colonNotation: true});
|
||||
//=> '1:35.5'
|
||||
|
||||
// `formatSubMilliseconds` option
|
||||
prettyMilliseconds(100.400080, {formatSubMilliseconds: true})
|
||||
//=> '100ms 400µs 80ns'
|
||||
|
||||
// `subSecondsAsDecimals` option
|
||||
prettyMilliseconds(900, {subSecondsAsDecimals: true});
|
||||
//=> '0.9s'
|
||||
|
||||
// Can be useful for time durations
|
||||
prettyMilliseconds(new Date(2014, 0, 1, 10, 40) - new Date(2014, 0, 1, 10, 5))
|
||||
//=> '35m'
|
||||
```
|
||||
*/
|
||||
export default function prettyMilliseconds(
|
||||
milliseconds: number | bigint,
|
||||
options?: Options
|
||||
): string;
|
||||
|
||||
149
node_modules/pretty-ms/index.js
generated
vendored
Normal file
149
node_modules/pretty-ms/index.js
generated
vendored
Normal file
@@ -0,0 +1,149 @@
|
||||
import parseMilliseconds from 'parse-ms';
|
||||
|
||||
const isZero = value => value === 0 || value === 0n;
|
||||
const pluralize = (word, count) => (count === 1 || count === 1n) ? word : `${word}s`;
|
||||
|
||||
const SECOND_ROUNDING_EPSILON = 0.000_000_1;
|
||||
const ONE_DAY_IN_MILLISECONDS = 24n * 60n * 60n * 1000n;
|
||||
|
||||
export default function prettyMilliseconds(milliseconds, options) {
|
||||
const isBigInt = typeof milliseconds === 'bigint';
|
||||
if (!isBigInt && !Number.isFinite(milliseconds)) {
|
||||
throw new TypeError('Expected a finite number or bigint');
|
||||
}
|
||||
|
||||
options = {...options};
|
||||
|
||||
const sign = milliseconds < 0 ? '-' : '';
|
||||
milliseconds = milliseconds < 0 ? -milliseconds : milliseconds; // Cannot use `Math.abs()` because of BigInt support.
|
||||
|
||||
if (options.colonNotation) {
|
||||
options.compact = false;
|
||||
options.formatSubMilliseconds = false;
|
||||
options.separateMilliseconds = false;
|
||||
options.verbose = false;
|
||||
}
|
||||
|
||||
if (options.compact) {
|
||||
options.unitCount = 1;
|
||||
options.secondsDecimalDigits = 0;
|
||||
options.millisecondsDecimalDigits = 0;
|
||||
}
|
||||
|
||||
let result = [];
|
||||
|
||||
const floorDecimals = (value, decimalDigits) => {
|
||||
const flooredInterimValue = Math.floor((value * (10 ** decimalDigits)) + SECOND_ROUNDING_EPSILON);
|
||||
const flooredValue = Math.round(flooredInterimValue) / (10 ** decimalDigits);
|
||||
return flooredValue.toFixed(decimalDigits);
|
||||
};
|
||||
|
||||
const add = (value, long, short, valueString) => {
|
||||
if (
|
||||
(result.length === 0 || !options.colonNotation)
|
||||
&& isZero(value)
|
||||
&& !(options.colonNotation && short === 'm')) {
|
||||
return;
|
||||
}
|
||||
|
||||
valueString ??= String(value);
|
||||
if (options.colonNotation) {
|
||||
const wholeDigits = valueString.includes('.') ? valueString.split('.')[0].length : valueString.length;
|
||||
const minLength = result.length > 0 ? 2 : 1;
|
||||
valueString = '0'.repeat(Math.max(0, minLength - wholeDigits)) + valueString;
|
||||
} else {
|
||||
valueString += options.verbose ? ' ' + pluralize(long, value) : short;
|
||||
}
|
||||
|
||||
result.push(valueString);
|
||||
};
|
||||
|
||||
const parsed = parseMilliseconds(milliseconds);
|
||||
const days = BigInt(parsed.days);
|
||||
|
||||
if (options.hideYearAndDays) {
|
||||
add((BigInt(days) * 24n) + BigInt(parsed.hours), 'hour', 'h');
|
||||
} else {
|
||||
if (options.hideYear) {
|
||||
add(days, 'day', 'd');
|
||||
} else {
|
||||
add(days / 365n, 'year', 'y');
|
||||
add(days % 365n, 'day', 'd');
|
||||
}
|
||||
|
||||
add(Number(parsed.hours), 'hour', 'h');
|
||||
}
|
||||
|
||||
add(Number(parsed.minutes), 'minute', 'm');
|
||||
|
||||
if (!options.hideSeconds) {
|
||||
if (
|
||||
options.separateMilliseconds
|
||||
|| options.formatSubMilliseconds
|
||||
|| (!options.colonNotation && milliseconds < 1000 && !options.subSecondsAsDecimals)
|
||||
) {
|
||||
const seconds = Number(parsed.seconds);
|
||||
const milliseconds = Number(parsed.milliseconds);
|
||||
const microseconds = Number(parsed.microseconds);
|
||||
const nanoseconds = Number(parsed.nanoseconds);
|
||||
|
||||
add(seconds, 'second', 's');
|
||||
|
||||
if (options.formatSubMilliseconds) {
|
||||
add(milliseconds, 'millisecond', 'ms');
|
||||
add(microseconds, 'microsecond', 'µs');
|
||||
add(nanoseconds, 'nanosecond', 'ns');
|
||||
} else {
|
||||
const millisecondsAndBelow
|
||||
= milliseconds
|
||||
+ (microseconds / 1000)
|
||||
+ (nanoseconds / 1e6);
|
||||
|
||||
const millisecondsDecimalDigits
|
||||
= typeof options.millisecondsDecimalDigits === 'number'
|
||||
? options.millisecondsDecimalDigits
|
||||
: 0;
|
||||
|
||||
const roundedMilliseconds = millisecondsAndBelow >= 1
|
||||
? Math.round(millisecondsAndBelow)
|
||||
: Math.ceil(millisecondsAndBelow);
|
||||
|
||||
const millisecondsString = millisecondsDecimalDigits
|
||||
? millisecondsAndBelow.toFixed(millisecondsDecimalDigits)
|
||||
: roundedMilliseconds;
|
||||
|
||||
add(
|
||||
Number.parseFloat(millisecondsString),
|
||||
'millisecond',
|
||||
'ms',
|
||||
millisecondsString,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
const seconds = (
|
||||
(isBigInt ? Number(milliseconds % ONE_DAY_IN_MILLISECONDS) : milliseconds)
|
||||
/ 1000
|
||||
) % 60;
|
||||
const secondsDecimalDigits
|
||||
= typeof options.secondsDecimalDigits === 'number'
|
||||
? options.secondsDecimalDigits
|
||||
: 1;
|
||||
const secondsFixed = floorDecimals(seconds, secondsDecimalDigits);
|
||||
const secondsString = options.keepDecimalsOnWholeSeconds
|
||||
? secondsFixed
|
||||
: secondsFixed.replace(/\.0+$/, '');
|
||||
add(Number.parseFloat(secondsString), 'second', 's', secondsString);
|
||||
}
|
||||
}
|
||||
|
||||
if (result.length === 0) {
|
||||
return sign + '0' + (options.verbose ? ' milliseconds' : 'ms');
|
||||
}
|
||||
|
||||
const separator = options.colonNotation ? ':' : ' ';
|
||||
if (typeof options.unitCount === 'number') {
|
||||
result = result.slice(0, Math.max(options.unitCount, 1));
|
||||
}
|
||||
|
||||
return sign + result.join(separator);
|
||||
}
|
||||
9
node_modules/pretty-ms/license
generated
vendored
Normal file
9
node_modules/pretty-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.
|
||||
55
node_modules/pretty-ms/package.json
generated
vendored
Normal file
55
node_modules/pretty-ms/package.json
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
{
|
||||
"name": "pretty-ms",
|
||||
"version": "9.3.0",
|
||||
"description": "Convert milliseconds to a human readable string: `1337000000` → `15d 11h 23m 20s`",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/pretty-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": [
|
||||
"pretty",
|
||||
"prettify",
|
||||
"human",
|
||||
"humanize",
|
||||
"humanized",
|
||||
"readable",
|
||||
"time",
|
||||
"ms",
|
||||
"milliseconds",
|
||||
"duration",
|
||||
"period",
|
||||
"range",
|
||||
"text",
|
||||
"string",
|
||||
"number",
|
||||
"hrtime"
|
||||
],
|
||||
"dependencies": {
|
||||
"parse-ms": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ava": "^6.2.0",
|
||||
"tsd": "^0.31.2",
|
||||
"xo": "^0.59.3"
|
||||
}
|
||||
}
|
||||
179
node_modules/pretty-ms/readme.md
generated
vendored
Normal file
179
node_modules/pretty-ms/readme.md
generated
vendored
Normal file
@@ -0,0 +1,179 @@
|
||||
# pretty-ms
|
||||
|
||||
> Convert milliseconds to a human readable string: `1337000000` → `15d 11h 23m 20s`
|
||||
|
||||
## Install
|
||||
|
||||
```sh
|
||||
npm install pretty-ms
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
import prettyMilliseconds from 'pretty-ms';
|
||||
|
||||
prettyMilliseconds(1337000000);
|
||||
//=> '15d 11h 23m 20s'
|
||||
|
||||
prettyMilliseconds(1337000000n);
|
||||
//=> '15d 11h 23m 20s'
|
||||
|
||||
prettyMilliseconds(1337);
|
||||
//=> '1.3s'
|
||||
|
||||
prettyMilliseconds(133);
|
||||
//=> '133ms'
|
||||
|
||||
// `compact` option
|
||||
prettyMilliseconds(1337, {compact: true});
|
||||
//=> '1s'
|
||||
|
||||
// `verbose` option
|
||||
prettyMilliseconds(1335669000, {verbose: true});
|
||||
//=> '15 days 11 hours 1 minute 9 seconds'
|
||||
|
||||
// `colonNotation` option
|
||||
prettyMilliseconds(95500, {colonNotation: true});
|
||||
//=> '1:35.5'
|
||||
|
||||
// `formatSubMilliseconds` option
|
||||
prettyMilliseconds(100.400080, {formatSubMilliseconds: true})
|
||||
//=> '100ms 400µs 80ns'
|
||||
|
||||
// `subSecondsAsDecimals` option
|
||||
prettyMilliseconds(900, {subSecondsAsDecimals: true});
|
||||
//=> '0.9s'
|
||||
|
||||
// Can be useful for time durations
|
||||
prettyMilliseconds(new Date(2014, 0, 1, 10, 40) - new Date(2014, 0, 1, 10, 5))
|
||||
//=> '35m'
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### prettyMilliseconds(milliseconds, options?)
|
||||
|
||||
#### milliseconds
|
||||
|
||||
Type: `number | bigint`
|
||||
|
||||
Milliseconds to humanize.
|
||||
|
||||
#### options
|
||||
|
||||
Type: `object`
|
||||
|
||||
##### secondsDecimalDigits
|
||||
|
||||
Type: `number`\
|
||||
Default: `1`
|
||||
|
||||
Number of digits to appear after the seconds decimal point.
|
||||
|
||||
##### millisecondsDecimalDigits
|
||||
|
||||
Type: `number`\
|
||||
Default: `0`
|
||||
|
||||
Number of digits to appear after the milliseconds decimal point.
|
||||
|
||||
Useful in combination with [`process.hrtime()`](https://nodejs.org/api/process.html#process_process_hrtime_time).
|
||||
|
||||
##### keepDecimalsOnWholeSeconds
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `false`
|
||||
|
||||
Keep milliseconds on whole seconds: `13s` → `13.0s`.
|
||||
|
||||
Useful when you are showing a number of seconds spent on an operation and don't want the width of the output to change when hitting a whole number.
|
||||
|
||||
##### compact
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `false`
|
||||
|
||||
Only show the first unit: `1h 10m` → `1h`.
|
||||
|
||||
Also ensures that `millisecondsDecimalDigits` and `secondsDecimalDigits` are both set to `0`.
|
||||
|
||||
##### unitCount
|
||||
|
||||
Type: `number`\
|
||||
Default: `Infinity`
|
||||
|
||||
Number of units to show. Setting `compact` to `true` overrides this option.
|
||||
|
||||
##### verbose
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `false`
|
||||
|
||||
Use full-length units: `5h 1m 45s` → `5 hours 1 minute 45 seconds`
|
||||
|
||||
##### separateMilliseconds
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `false`
|
||||
|
||||
Show milliseconds separately. This means they won't be included in the decimal part of the seconds.
|
||||
|
||||
##### formatSubMilliseconds
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `false`
|
||||
|
||||
Show microseconds and nanoseconds.
|
||||
|
||||
##### colonNotation
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `false`
|
||||
|
||||
Display time using colon notation: `5h 1m 45s` → `5:01:45`. Always shows time in at least minutes: `1s` → `0:01`
|
||||
|
||||
Useful when you want to display time without the time units, similar to a digital watch.
|
||||
|
||||
Setting `colonNotation` to `true` overrides the following options to `false`:
|
||||
- `compact`
|
||||
- `formatSubMilliseconds`
|
||||
- `separateMilliseconds`
|
||||
- `verbose`
|
||||
|
||||
##### hideYear
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `false`
|
||||
|
||||
Hides the year and shows the hidden year additionally as days (365 per year): `1y 3d 5h 1m 45s` → `368d 5h 1m 45s`.
|
||||
|
||||
##### hideYearAndDays
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `false`
|
||||
|
||||
Hides the year and days and shows the hidden values additionally as hours: `1y 3d 5h 1m 45s` → `8837h 1m 45s`.
|
||||
|
||||
##### hideSeconds
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `false`
|
||||
|
||||
Hides the seconds: `1y 3d 5h 1m 45s` → `1y 3d 5h 1m`.
|
||||
|
||||
##### subSecondsAsDecimals
|
||||
|
||||
Type: `boolean`\
|
||||
Default: `false`
|
||||
|
||||
Show sub-second values as decimal seconds: `900ms` → `0.9s`.
|
||||
|
||||
Useful for progress indicators where you want consistent unit format to prevent flickering.
|
||||
|
||||
## Related
|
||||
|
||||
- [pretty-ms-cli](https://github.com/sindresorhus/pretty-ms-cli) - CLI for this module
|
||||
- [parse-ms](https://github.com/sindresorhus/parse-ms) - Parse milliseconds into an object
|
||||
- [to-milliseconds](https://github.com/sindresorhus/to-milliseconds) - Convert an object of time properties to milliseconds
|
||||
- [pretty-bytes](https://github.com/sindresorhus/pretty-bytes) - Convert bytes to a human readable string
|
||||
Reference in New Issue
Block a user