@oliversalzburg/js-utils 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/async/async.d.ts +44 -0
- package/lib/async/async.js +76 -0
- package/lib/async/async.js.map +1 -0
- package/lib/async/async.test.d.ts +1 -0
- package/lib/async/async.test.js +26 -0
- package/lib/async/async.test.js.map +1 -0
- package/lib/cli/args.d.ts +9 -0
- package/lib/cli/args.js +49 -0
- package/lib/cli/args.js.map +1 -0
- package/lib/cli/args.test.d.ts +1 -0
- package/lib/cli/args.test.js +31 -0
- package/lib/cli/args.test.js.map +1 -0
- package/lib/core.d.ts +43 -0
- package/lib/core.js +2 -0
- package/lib/core.js.map +1 -0
- package/lib/data/array.d.ts +55 -0
- package/lib/data/array.js +90 -0
- package/lib/data/array.js.map +1 -0
- package/lib/data/nil.d.ts +92 -0
- package/lib/data/nil.js +131 -0
- package/lib/data/nil.js.map +1 -0
- package/lib/data/random.d.ts +111 -0
- package/lib/data/random.js +381 -0
- package/lib/data/random.js.map +1 -0
- package/lib/data/string.d.ts +30 -0
- package/lib/data/string.js +53 -0
- package/lib/data/string.js.map +1 -0
- package/lib/data/tree.d.ts +28 -0
- package/lib/data/tree.js +45 -0
- package/lib/data/tree.js.map +1 -0
- package/lib/device/shake.d.ts +79 -0
- package/lib/device/shake.js +135 -0
- package/lib/device/shake.js.map +1 -0
- package/lib/dom/core.d.ts +21 -0
- package/lib/dom/core.js +41 -0
- package/lib/dom/core.js.map +1 -0
- package/lib/errors/AbstractError.d.ts +29 -0
- package/lib/errors/AbstractError.js +59 -0
- package/lib/errors/AbstractError.js.map +1 -0
- package/lib/errors/InternalError.d.ts +19 -0
- package/lib/errors/InternalError.js +38 -0
- package/lib/errors/InternalError.js.map +1 -0
- package/lib/errors/InvalidArgumentError.d.ts +13 -0
- package/lib/errors/InvalidArgumentError.js +22 -0
- package/lib/errors/InvalidArgumentError.js.map +1 -0
- package/lib/errors/InvalidOperationError.d.ts +13 -0
- package/lib/errors/InvalidOperationError.js +22 -0
- package/lib/errors/InvalidOperationError.js.map +1 -0
- package/lib/errors/NotImplementedError.d.ts +12 -0
- package/lib/errors/NotImplementedError.js +21 -0
- package/lib/errors/NotImplementedError.js.map +1 -0
- package/lib/errors/PermissionViolationError.d.ts +13 -0
- package/lib/errors/PermissionViolationError.js +22 -0
- package/lib/errors/PermissionViolationError.js.map +1 -0
- package/lib/errors/ResourceConflictError.d.ts +12 -0
- package/lib/errors/ResourceConflictError.js +21 -0
- package/lib/errors/ResourceConflictError.js.map +1 -0
- package/lib/errors/UnknownError.d.ts +16 -0
- package/lib/errors/UnknownError.js +25 -0
- package/lib/errors/UnknownError.js.map +1 -0
- package/lib/errors/console.d.ts +7 -0
- package/lib/errors/console.js +13 -0
- package/lib/errors/console.js.map +1 -0
- package/lib/errors/error-serializer.d.ts +45 -0
- package/lib/errors/error-serializer.js +74 -0
- package/lib/errors/error-serializer.js.map +1 -0
- package/lib/errors/error-serializer.test.d.ts +1 -0
- package/lib/errors/error-serializer.test.js +109 -0
- package/lib/errors/error-serializer.test.js.map +1 -0
- package/lib/errors/stream.d.ts +7 -0
- package/lib/errors/stream.js +15 -0
- package/lib/errors/stream.js.map +1 -0
- package/lib/errors/tools.d.ts +10 -0
- package/lib/errors/tools.js +13 -0
- package/lib/errors/tools.js.map +1 -0
- package/lib/events/event.d.ts +9 -0
- package/lib/events/event.js +10 -0
- package/lib/events/event.js.map +1 -0
- package/lib/format/bytes.d.ts +118 -0
- package/lib/format/bytes.js +138 -0
- package/lib/format/bytes.js.map +1 -0
- package/lib/format/bytes.test.d.ts +1 -0
- package/lib/format/bytes.test.js +146 -0
- package/lib/format/bytes.test.js.map +1 -0
- package/lib/format/count.d.ts +14 -0
- package/lib/format/count.js +51 -0
- package/lib/format/count.js.map +1 -0
- package/lib/format/count.test.d.ts +1 -0
- package/lib/format/count.test.js +42 -0
- package/lib/format/count.test.js.map +1 -0
- package/lib/format/milliseconds.d.ts +100 -0
- package/lib/format/milliseconds.js +199 -0
- package/lib/format/milliseconds.js.map +1 -0
- package/lib/format/milliseconds.test.d.ts +1 -0
- package/lib/format/milliseconds.test.js +393 -0
- package/lib/format/milliseconds.test.js.map +1 -0
- package/lib/format/string.d.ts +24 -0
- package/lib/format/string.js +32 -0
- package/lib/format/string.js.map +1 -0
- package/lib/format/string.test.d.ts +1 -0
- package/lib/format/string.test.js +17 -0
- package/lib/format/string.test.js.map +1 -0
- package/lib/graphics/canvas-sandbox-mp.d.ts +258 -0
- package/lib/graphics/canvas-sandbox-mp.js +280 -0
- package/lib/graphics/canvas-sandbox-mp.js.map +1 -0
- package/lib/graphics/canvas-sandbox.d.ts +255 -0
- package/lib/graphics/canvas-sandbox.js +358 -0
- package/lib/graphics/canvas-sandbox.js.map +1 -0
- package/lib/graphics/canvas.d.ts +57 -0
- package/lib/graphics/canvas.js +37 -0
- package/lib/graphics/canvas.js.map +1 -0
- package/lib/graphics/canvas2d-headless.d.ts +85 -0
- package/lib/graphics/canvas2d-headless.js +197 -0
- package/lib/graphics/canvas2d-headless.js.map +1 -0
- package/lib/graphics/canvas2d.d.ts +162 -0
- package/lib/graphics/canvas2d.js +332 -0
- package/lib/graphics/canvas2d.js.map +1 -0
- package/lib/graphics/canvas3d.d.ts +41 -0
- package/lib/graphics/canvas3d.js +67 -0
- package/lib/graphics/canvas3d.js.map +1 -0
- package/lib/graphics/color.d.ts +22 -0
- package/lib/graphics/color.js +38 -0
- package/lib/graphics/color.js.map +1 -0
- package/lib/graphics/core.d.ts +89 -0
- package/lib/graphics/core.js +146 -0
- package/lib/graphics/core.js.map +1 -0
- package/lib/graphics/palette-sampler.d.ts +7 -0
- package/lib/graphics/palette-sampler.js +21 -0
- package/lib/graphics/palette-sampler.js.map +1 -0
- package/lib/graphics/palette.d.ts +120 -0
- package/lib/graphics/palette.js +574 -0
- package/lib/graphics/palette.js.map +1 -0
- package/lib/graphics/palette.test.d.ts +1 -0
- package/lib/graphics/palette.test.js +43 -0
- package/lib/graphics/palette.test.js.map +1 -0
- package/lib/graphics/render-loop.d.ts +76 -0
- package/lib/graphics/render-loop.js +114 -0
- package/lib/graphics/render-loop.js.map +1 -0
- package/lib/graphics/shader.d.ts +56 -0
- package/lib/graphics/shader.js +80 -0
- package/lib/graphics/shader.js.map +1 -0
- package/lib/log/log.d.ts +11 -0
- package/lib/log/log.js +2 -0
- package/lib/log/log.js.map +1 -0
- package/lib/log/report.d.ts +57 -0
- package/lib/log/report.js +88 -0
- package/lib/log/report.js.map +1 -0
- package/lib/math/core.d.ts +85 -0
- package/lib/math/core.js +125 -0
- package/lib/math/core.js.map +1 -0
- package/lib/math/easing.d.ts +204 -0
- package/lib/math/easing.js +366 -0
- package/lib/math/easing.js.map +1 -0
- package/lib/math/euler.d.ts +18 -0
- package/lib/math/euler.js +22 -0
- package/lib/math/euler.js.map +1 -0
- package/lib/math/matrix3.d.ts +227 -0
- package/lib/math/matrix3.js +508 -0
- package/lib/math/matrix3.js.map +1 -0
- package/lib/math/quaternion.d.ts +119 -0
- package/lib/math/quaternion.js +270 -0
- package/lib/math/quaternion.js.map +1 -0
- package/lib/math/transformation.d.ts +26 -0
- package/lib/math/transformation.js +31 -0
- package/lib/math/transformation.js.map +1 -0
- package/lib/math/vector2.d.ts +202 -0
- package/lib/math/vector2.js +310 -0
- package/lib/math/vector2.js.map +1 -0
- package/lib/math/vector3.d.ts +293 -0
- package/lib/math/vector3.js +492 -0
- package/lib/math/vector3.js.map +1 -0
- package/lib/math/vector4.d.ts +182 -0
- package/lib/math/vector4.js +302 -0
- package/lib/math/vector4.js.map +1 -0
- package/lib/measurement/performance.d.ts +13 -0
- package/lib/measurement/performance.js +19 -0
- package/lib/measurement/performance.js.map +1 -0
- package/package.json +5 -7
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was derived from https://github.com/sindresorhus/parse-ms/tree/a18636bb609793326a1bd8d541aad49f715f0a40
|
|
3
|
+
* and https://github.com/sindresorhus/pretty-ms/tree/763fe075d8a62aa8d9ee603bfad2f3107c3a9f02.
|
|
4
|
+
* It is available under the MIT license.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Options for the `formatMilliseconds` function.
|
|
8
|
+
*/
|
|
9
|
+
export interface FormatMillisecondsOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Number of digits to appear after the seconds decimal point.
|
|
12
|
+
*/
|
|
13
|
+
secondsDecimalDigits?: number;
|
|
14
|
+
/**
|
|
15
|
+
* Number of digits to appear after the milliseconds decimal point.
|
|
16
|
+
*
|
|
17
|
+
* Useful in combination with [`process.hrtime()`](https://nodejs.org/api/process.html#process_process_hrtime).
|
|
18
|
+
*/
|
|
19
|
+
millisecondsDecimalDigits?: number;
|
|
20
|
+
/**
|
|
21
|
+
* Keep milliseconds on whole seconds: `13s` → `13.0s`.
|
|
22
|
+
*
|
|
23
|
+
* 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.
|
|
24
|
+
*/
|
|
25
|
+
keepDecimalsOnWholeSeconds?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Only show the first unit: `1h 10m` → `1h`.
|
|
28
|
+
*
|
|
29
|
+
* Also ensures that `millisecondsDecimalDigits` and `secondsDecimalDigits` are both set to `0`.
|
|
30
|
+
*/
|
|
31
|
+
compact?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Number of units to show. Setting `compact` to `true` overrides this option.
|
|
34
|
+
*/
|
|
35
|
+
unitCount?: number;
|
|
36
|
+
/**
|
|
37
|
+
* Use full-length units: `5h 1m 45s` → `5 hours 1 minute 45 seconds`.
|
|
38
|
+
*/
|
|
39
|
+
verbose?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Show milliseconds separately. This means they won't be included in the decimal part of the seconds.
|
|
42
|
+
*/
|
|
43
|
+
separateMilliseconds?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Show microseconds and nanoseconds.
|
|
46
|
+
*/
|
|
47
|
+
formatSubMilliseconds?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Display time using colon notation: `5h 1m 45s` → `5:01:45`. Always shows time in at least minutes: `1s` → `0:01`
|
|
50
|
+
*
|
|
51
|
+
* Useful when you want to display time without the time units, similar to a digital watch.
|
|
52
|
+
*
|
|
53
|
+
* Setting `colonNotation` to `true` overrides the following options to `false`:
|
|
54
|
+
* - `compact`
|
|
55
|
+
* - `formatSubMilliseconds`
|
|
56
|
+
* - `separateMilliseconds`
|
|
57
|
+
* - `verbose`
|
|
58
|
+
*/
|
|
59
|
+
colonNotation?: boolean;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Convert milliseconds to a human readable string: `1337000000` → `15d 11h 23m 20s`.
|
|
63
|
+
* @param milliseconds - Milliseconds to humanize.
|
|
64
|
+
* @param options - Options for humanizing the milliseconds.
|
|
65
|
+
* @returns The humanized string.
|
|
66
|
+
* @example
|
|
67
|
+
* ```
|
|
68
|
+
* import formatMilliseconds from '@oliversalzburg/js-utils/format/milliseconds.js';
|
|
69
|
+
*
|
|
70
|
+
* formatMilliseconds(1337000000);
|
|
71
|
+
* //=> '15d 11h 23m 20s'
|
|
72
|
+
*
|
|
73
|
+
* formatMilliseconds(1337);
|
|
74
|
+
* //=> '1.3s'
|
|
75
|
+
*
|
|
76
|
+
* formatMilliseconds(133);
|
|
77
|
+
* //=> '133ms'
|
|
78
|
+
*
|
|
79
|
+
* // `compact` option
|
|
80
|
+
* formatMilliseconds(1337, {compact: true});
|
|
81
|
+
* //=> '1s'
|
|
82
|
+
*
|
|
83
|
+
* // `verbose` option
|
|
84
|
+
* formatMilliseconds(1335669000, {verbose: true});
|
|
85
|
+
* //=> '15 days 11 hours 1 minute 9 seconds'
|
|
86
|
+
*
|
|
87
|
+
* // `colonNotation` option
|
|
88
|
+
* formatMilliseconds(95500, {colonNotation: true});
|
|
89
|
+
* //=> '1:35.5'
|
|
90
|
+
*
|
|
91
|
+
* // `formatSubMilliseconds` option
|
|
92
|
+
* formatMilliseconds(100.400080, {formatSubMilliseconds: true})
|
|
93
|
+
* //=> '100ms 400µs 80ns'
|
|
94
|
+
*
|
|
95
|
+
* // Can be useful for time durations
|
|
96
|
+
* formatMilliseconds(new Date(2014, 0, 1, 10, 40) - new Date(2014, 0, 1, 10, 5))
|
|
97
|
+
* //=> '35m'
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export declare const formatMilliseconds: (milliseconds: number | bigint, options?: Readonly<FormatMillisecondsOptions>) => string;
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was derived from https://github.com/sindresorhus/parse-ms/tree/a18636bb609793326a1bd8d541aad49f715f0a40
|
|
3
|
+
* and https://github.com/sindresorhus/pretty-ms/tree/763fe075d8a62aa8d9ee603bfad2f3107c3a9f02.
|
|
4
|
+
* It is available under the MIT license.
|
|
5
|
+
*/
|
|
6
|
+
const toZeroIfInfinity = (value) => Number.isFinite(value) ? value : 0;
|
|
7
|
+
const parseNumber = (milliseconds) => {
|
|
8
|
+
return {
|
|
9
|
+
days: Math.trunc(milliseconds / 86_400_000),
|
|
10
|
+
hours: Math.trunc((milliseconds / 3_600_000) % 24),
|
|
11
|
+
microseconds: Math.trunc(toZeroIfInfinity(milliseconds * 1000) % 1000),
|
|
12
|
+
milliseconds: Math.trunc(milliseconds % 1000),
|
|
13
|
+
minutes: Math.trunc((milliseconds / 60_000) % 60),
|
|
14
|
+
nanoseconds: Math.trunc(toZeroIfInfinity(milliseconds * 1e6) % 1000),
|
|
15
|
+
seconds: Math.trunc((milliseconds / 1000) % 60),
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
const parseBigint = (milliseconds) => {
|
|
19
|
+
return {
|
|
20
|
+
days: milliseconds / 86400000n,
|
|
21
|
+
hours: (milliseconds / 3600000n) % 24n,
|
|
22
|
+
microseconds: 0n,
|
|
23
|
+
milliseconds: milliseconds % 1000n,
|
|
24
|
+
minutes: (milliseconds / 60000n) % 60n,
|
|
25
|
+
nanoseconds: 0n,
|
|
26
|
+
seconds: (milliseconds / 1000n) % 60n,
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
const parseMilliseconds = (milliseconds) => {
|
|
30
|
+
switch (typeof milliseconds) {
|
|
31
|
+
case "number": {
|
|
32
|
+
if (Number.isFinite(milliseconds)) {
|
|
33
|
+
return parseNumber(milliseconds);
|
|
34
|
+
}
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
case "bigint": {
|
|
38
|
+
return parseBigint(milliseconds);
|
|
39
|
+
}
|
|
40
|
+
// No default
|
|
41
|
+
}
|
|
42
|
+
throw new TypeError("Expected a finite number or bigint");
|
|
43
|
+
};
|
|
44
|
+
const isZero = (value) => value === 0 || value === 0n;
|
|
45
|
+
const pluralize = (word, count) => count === 1 || count === 1n ? word : `${word}s`;
|
|
46
|
+
const SECOND_ROUNDING_EPSILON = 0.000_000_1;
|
|
47
|
+
const ONE_DAY_IN_MILLISECONDS = 24n * 60n * 60n * 1000n;
|
|
48
|
+
/**
|
|
49
|
+
* Convert milliseconds to a human readable string: `1337000000` → `15d 11h 23m 20s`.
|
|
50
|
+
* @param milliseconds - Milliseconds to humanize.
|
|
51
|
+
* @param options - Options for humanizing the milliseconds.
|
|
52
|
+
* @returns The humanized string.
|
|
53
|
+
* @example
|
|
54
|
+
* ```
|
|
55
|
+
* import formatMilliseconds from '@oliversalzburg/js-utils/format/milliseconds.js';
|
|
56
|
+
*
|
|
57
|
+
* formatMilliseconds(1337000000);
|
|
58
|
+
* //=> '15d 11h 23m 20s'
|
|
59
|
+
*
|
|
60
|
+
* formatMilliseconds(1337);
|
|
61
|
+
* //=> '1.3s'
|
|
62
|
+
*
|
|
63
|
+
* formatMilliseconds(133);
|
|
64
|
+
* //=> '133ms'
|
|
65
|
+
*
|
|
66
|
+
* // `compact` option
|
|
67
|
+
* formatMilliseconds(1337, {compact: true});
|
|
68
|
+
* //=> '1s'
|
|
69
|
+
*
|
|
70
|
+
* // `verbose` option
|
|
71
|
+
* formatMilliseconds(1335669000, {verbose: true});
|
|
72
|
+
* //=> '15 days 11 hours 1 minute 9 seconds'
|
|
73
|
+
*
|
|
74
|
+
* // `colonNotation` option
|
|
75
|
+
* formatMilliseconds(95500, {colonNotation: true});
|
|
76
|
+
* //=> '1:35.5'
|
|
77
|
+
*
|
|
78
|
+
* // `formatSubMilliseconds` option
|
|
79
|
+
* formatMilliseconds(100.400080, {formatSubMilliseconds: true})
|
|
80
|
+
* //=> '100ms 400µs 80ns'
|
|
81
|
+
*
|
|
82
|
+
* // Can be useful for time durations
|
|
83
|
+
* formatMilliseconds(new Date(2014, 0, 1, 10, 40) - new Date(2014, 0, 1, 10, 5))
|
|
84
|
+
* //=> '35m'
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
export const formatMilliseconds = (milliseconds, options = {
|
|
88
|
+
colonNotation: false,
|
|
89
|
+
compact: false,
|
|
90
|
+
formatSubMilliseconds: false,
|
|
91
|
+
keepDecimalsOnWholeSeconds: false,
|
|
92
|
+
millisecondsDecimalDigits: 0,
|
|
93
|
+
secondsDecimalDigits: 1,
|
|
94
|
+
separateMilliseconds: false,
|
|
95
|
+
unitCount: Infinity,
|
|
96
|
+
verbose: false,
|
|
97
|
+
}) => {
|
|
98
|
+
const isBigInt = typeof milliseconds === "bigint";
|
|
99
|
+
if (!isBigInt && !Number.isFinite(milliseconds)) {
|
|
100
|
+
throw new TypeError("Expected a finite number or bigint");
|
|
101
|
+
}
|
|
102
|
+
const optionsAdjusted = { ...options };
|
|
103
|
+
if (optionsAdjusted.colonNotation) {
|
|
104
|
+
optionsAdjusted.compact = false;
|
|
105
|
+
optionsAdjusted.formatSubMilliseconds = false;
|
|
106
|
+
optionsAdjusted.separateMilliseconds = false;
|
|
107
|
+
optionsAdjusted.verbose = false;
|
|
108
|
+
}
|
|
109
|
+
if (optionsAdjusted.compact) {
|
|
110
|
+
optionsAdjusted.unitCount = 1;
|
|
111
|
+
optionsAdjusted.secondsDecimalDigits = 0;
|
|
112
|
+
optionsAdjusted.millisecondsDecimalDigits = 0;
|
|
113
|
+
}
|
|
114
|
+
let result = [];
|
|
115
|
+
const floorDecimals = (value, decimalDigits) => {
|
|
116
|
+
const flooredInterimValue = Math.floor(value * 10 ** decimalDigits + SECOND_ROUNDING_EPSILON);
|
|
117
|
+
const flooredValue = Math.round(flooredInterimValue) / 10 ** decimalDigits;
|
|
118
|
+
return flooredValue.toFixed(decimalDigits);
|
|
119
|
+
};
|
|
120
|
+
const add = (value, long, short, valueString) => {
|
|
121
|
+
if ((result.length === 0 || !optionsAdjusted.colonNotation) &&
|
|
122
|
+
isZero(value) &&
|
|
123
|
+
!(optionsAdjusted.colonNotation && short === "m")) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
valueString ??= String(value);
|
|
127
|
+
if (optionsAdjusted.colonNotation) {
|
|
128
|
+
const wholeDigits = valueString.includes(".")
|
|
129
|
+
? valueString.split(".")[0].length
|
|
130
|
+
: valueString.length;
|
|
131
|
+
const minLength = result.length > 0 ? 2 : 1;
|
|
132
|
+
valueString =
|
|
133
|
+
"0".repeat(Math.max(0, minLength - wholeDigits)) + valueString;
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
valueString += optionsAdjusted.verbose
|
|
137
|
+
? ` ${pluralize(long, value)}`
|
|
138
|
+
: short;
|
|
139
|
+
}
|
|
140
|
+
result.push(valueString);
|
|
141
|
+
};
|
|
142
|
+
const parsed = parseMilliseconds(milliseconds);
|
|
143
|
+
const days = BigInt(parsed.days);
|
|
144
|
+
add(days / 365n, "year", "y");
|
|
145
|
+
add(days % 365n, "day", "d");
|
|
146
|
+
add(Number(parsed.hours), "hour", "h");
|
|
147
|
+
add(Number(parsed.minutes), "minute", "m");
|
|
148
|
+
if (optionsAdjusted.separateMilliseconds ||
|
|
149
|
+
optionsAdjusted.formatSubMilliseconds ||
|
|
150
|
+
(!optionsAdjusted.colonNotation && milliseconds < 1000)) {
|
|
151
|
+
const seconds = Number(parsed.seconds);
|
|
152
|
+
const milliseconds = Number(parsed.milliseconds);
|
|
153
|
+
const microseconds = Number(parsed.microseconds);
|
|
154
|
+
const nanoseconds = Number(parsed.nanoseconds);
|
|
155
|
+
add(seconds, "second", "s");
|
|
156
|
+
if (optionsAdjusted.formatSubMilliseconds) {
|
|
157
|
+
add(milliseconds, "millisecond", "ms");
|
|
158
|
+
add(microseconds, "microsecond", "µs");
|
|
159
|
+
add(nanoseconds, "nanosecond", "ns");
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
const millisecondsAndBelow = milliseconds + microseconds / 1000 + nanoseconds / 1e6;
|
|
163
|
+
const millisecondsDecimalDigits = typeof optionsAdjusted.millisecondsDecimalDigits === "number"
|
|
164
|
+
? optionsAdjusted.millisecondsDecimalDigits
|
|
165
|
+
: 0;
|
|
166
|
+
const roundedMilliseconds = millisecondsAndBelow >= 1
|
|
167
|
+
? Math.round(millisecondsAndBelow)
|
|
168
|
+
: Math.ceil(millisecondsAndBelow);
|
|
169
|
+
const millisecondsString = millisecondsDecimalDigits
|
|
170
|
+
? millisecondsAndBelow.toFixed(millisecondsDecimalDigits)
|
|
171
|
+
: roundedMilliseconds.toString();
|
|
172
|
+
add(Number.parseFloat(millisecondsString), "millisecond", "ms", millisecondsString);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
const seconds = ((isBigInt
|
|
177
|
+
? Number(milliseconds % ONE_DAY_IN_MILLISECONDS)
|
|
178
|
+
: milliseconds) /
|
|
179
|
+
1000) %
|
|
180
|
+
60;
|
|
181
|
+
const secondsDecimalDigits = typeof optionsAdjusted.secondsDecimalDigits === "number"
|
|
182
|
+
? optionsAdjusted.secondsDecimalDigits
|
|
183
|
+
: 1;
|
|
184
|
+
const secondsFixed = floorDecimals(seconds, secondsDecimalDigits);
|
|
185
|
+
const secondsString = optionsAdjusted.keepDecimalsOnWholeSeconds
|
|
186
|
+
? secondsFixed
|
|
187
|
+
: secondsFixed.replace(/\.0+$/, "");
|
|
188
|
+
add(Number.parseFloat(secondsString), "second", "s", secondsString);
|
|
189
|
+
}
|
|
190
|
+
if (result.length === 0) {
|
|
191
|
+
return `0${optionsAdjusted.verbose ? " milliseconds" : "ms"}`;
|
|
192
|
+
}
|
|
193
|
+
const separator = optionsAdjusted.colonNotation ? ":" : " ";
|
|
194
|
+
if (typeof optionsAdjusted.unitCount === "number") {
|
|
195
|
+
result = result.slice(0, Math.max(optionsAdjusted.unitCount, 1));
|
|
196
|
+
}
|
|
197
|
+
return result.join(separator);
|
|
198
|
+
};
|
|
199
|
+
//# sourceMappingURL=milliseconds.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"milliseconds.js","sourceRoot":"","sources":["../../source/format/milliseconds.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAkEH,MAAM,gBAAgB,GAAG,CAAC,KAAa,EAAE,EAAE,CAC1C,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AAEpC,MAAM,WAAW,GAAG,CAAC,YAAoB,EAAE,EAAE;IAC5C,OAAO;QACN,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,YAAY,GAAG,UAAU,CAAC;QAC3C,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,YAAY,GAAG,SAAS,CAAC,GAAG,EAAE,CAAC;QAClD,YAAY,EAAE,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,YAAY,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;QACtE,YAAY,EAAE,IAAI,CAAC,KAAK,CAAC,YAAY,GAAG,IAAI,CAAC;QAC7C,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,YAAY,GAAG,MAAM,CAAC,GAAG,EAAE,CAAC;QACjD,WAAW,EAAE,IAAI,CAAC,KAAK,CAAC,gBAAgB,CA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