@oliversalzburg/js-utils 0.0.30-dev.17 → 0.0.30-dev.19
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/format/bytes.d.ts +120 -0
- package/format/bytes.js +100 -0
- package/format/bytes.js.map +1 -0
- package/format/bytes.test.js +138 -0
- package/format/bytes.test.js.map +1 -0
- package/format/index.d.ts +3 -0
- package/format/index.js +4 -0
- package/format/index.js.map +1 -0
- package/format/milliseconds.d.ts +102 -0
- package/format/milliseconds.js +193 -0
- package/format/milliseconds.js.map +1 -0
- package/format/milliseconds.test.d.ts +1 -0
- package/format/milliseconds.test.js +343 -0
- package/format/milliseconds.test.js.map +1 -0
- package/{string-formatter.d.ts → format/string.d.ts} +2 -0
- package/{string-formatter.js → format/string.js} +3 -1
- package/format/string.js.map +1 -0
- package/format/string.test.d.ts +1 -0
- package/{string-formatter.test.js → format/string.test.js} +2 -2
- package/format/string.test.js.map +1 -0
- package/index.d.ts +0 -1
- package/index.js +0 -1
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/string-formatter.js.map +0 -1
- package/string-formatter.test.js.map +0 -1
- /package/{string-formatter.test.d.ts → format/bytes.test.d.ts} +0 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was derived from https://github.com/sindresorhus/pretty-bytes/tree/71d686a4cefb314c13b57107de5add5789753900.
|
|
3
|
+
* It is available under the MIT license.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Options for the `prettyBytes` function.
|
|
7
|
+
* @group Formatting
|
|
8
|
+
*/
|
|
9
|
+
export interface FormatBytesOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Include plus sign for positive numbers. If the difference is exactly zero a space character will be prepended instead for better alignment.
|
|
12
|
+
*/
|
|
13
|
+
signed?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* - If `false`: Output won't be localized.
|
|
16
|
+
* - If `true`: Localize the output using the system/browser locale.
|
|
17
|
+
* - If `string`: Expects a [BCP 47 language tag](https://en.wikipedia.org/wiki/IETF_language_tag) (For example: `en`, `de`, …)
|
|
18
|
+
* - If `string[]`: Expects a list of [BCP 47 language tags](https://en.wikipedia.org/wiki/IETF_language_tag) (For example: `en`, `de`, …)
|
|
19
|
+
*/
|
|
20
|
+
locale?: boolean | string | ReadonlyArray<string>;
|
|
21
|
+
/**
|
|
22
|
+
* Format the number as [bits](https://en.wikipedia.org/wiki/Bit) instead of [bytes](https://en.wikipedia.org/wiki/Byte). This can be useful when, for example, referring to [bit rate](https://en.wikipedia.org/wiki/Bit_rate).
|
|
23
|
+
* @example
|
|
24
|
+
* ```
|
|
25
|
+
* import prettyBytes from 'pretty-bytes';
|
|
26
|
+
*
|
|
27
|
+
* prettyBytes(1337, {bits: true});
|
|
28
|
+
* //=> '1.34 kbit'
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
bits?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Format the number using the [Binary Prefix](https://en.wikipedia.org/wiki/Binary_prefix) instead of the [SI Prefix](https://en.wikipedia.org/wiki/SI_prefix). This can be useful for presenting memory amounts. However, this should not be used for presenting file sizes.
|
|
34
|
+
* @example
|
|
35
|
+
* ```
|
|
36
|
+
* import prettyBytes from 'pretty-bytes';
|
|
37
|
+
*
|
|
38
|
+
* prettyBytes(1000, {binary: true});
|
|
39
|
+
* //=> '1000 bit'
|
|
40
|
+
*
|
|
41
|
+
* prettyBytes(1024, {binary: true});
|
|
42
|
+
* //=> '1 kiB'
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
binary?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* The minimum number of fraction digits to display.
|
|
48
|
+
*
|
|
49
|
+
* If neither `minimumFractionDigits` or `maximumFractionDigits` are set, the default behavior is to round to 3 significant digits.
|
|
50
|
+
* @example
|
|
51
|
+
* ```
|
|
52
|
+
* import prettyBytes from 'pretty-bytes';
|
|
53
|
+
*
|
|
54
|
+
* // Show the number with at least 3 fractional digits
|
|
55
|
+
* prettyBytes(1900, {minimumFractionDigits: 3});
|
|
56
|
+
* //=> '1.900 kB'
|
|
57
|
+
*
|
|
58
|
+
* prettyBytes(1900);
|
|
59
|
+
* //=> '1.9 kB'
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
minimumFractionDigits?: number;
|
|
63
|
+
/**
|
|
64
|
+
* The maximum number of fraction digits to display.
|
|
65
|
+
*
|
|
66
|
+
* If neither `minimumFractionDigits` or `maximumFractionDigits` are set, the default behavior is to round to 3 significant digits.
|
|
67
|
+
* @example
|
|
68
|
+
* ```
|
|
69
|
+
* import prettyBytes from 'pretty-bytes';
|
|
70
|
+
*
|
|
71
|
+
* // Show the number with at most 1 fractional digit
|
|
72
|
+
* prettyBytes(1920, {maximumFractionDigits: 1});
|
|
73
|
+
* //=> '1.9 kB'
|
|
74
|
+
*
|
|
75
|
+
* prettyBytes(1920);
|
|
76
|
+
* //=> '1.92 kB'
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
maximumFractionDigits?: number;
|
|
80
|
+
/**
|
|
81
|
+
* Put a space between the number and unit.
|
|
82
|
+
* @example
|
|
83
|
+
* ```
|
|
84
|
+
* import prettyBytes from 'pretty-bytes';
|
|
85
|
+
*
|
|
86
|
+
* prettyBytes(1920, {space: false});
|
|
87
|
+
* //=> '1.9kB'
|
|
88
|
+
*
|
|
89
|
+
* prettyBytes(1920);
|
|
90
|
+
* //=> '1.92 kB'
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
space?: boolean;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Convert bytes to a human readable string: `1337` → `1.34 kB`.
|
|
97
|
+
* @param number - The number to format.
|
|
98
|
+
* @param options - The options for formatting the number.
|
|
99
|
+
* @returns The formatted string.
|
|
100
|
+
* @group Formatting
|
|
101
|
+
* @example
|
|
102
|
+
* ```
|
|
103
|
+
* import prettyBytes from '@oliversalzburg/js-utils/format/bytes.js';
|
|
104
|
+
*
|
|
105
|
+
* prettyBytes(1337);
|
|
106
|
+
* //=> '1.34 kB'
|
|
107
|
+
*
|
|
108
|
+
* prettyBytes(100);
|
|
109
|
+
* //=> '100 B'
|
|
110
|
+
*
|
|
111
|
+
* // Display file size differences
|
|
112
|
+
* prettyBytes(42, {signed: true});
|
|
113
|
+
* //=> '+42 B'
|
|
114
|
+
*
|
|
115
|
+
* // Localized output using German locale
|
|
116
|
+
* prettyBytes(1337, {locale: 'de'});
|
|
117
|
+
* //=> '1,34 kB'
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
export declare const formatBytes: (number: number, options?: Readonly<FormatBytesOptions>) => string;
|
package/format/bytes.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was derived from https://github.com/sindresorhus/pretty-bytes/tree/71d686a4cefb314c13b57107de5add5789753900.
|
|
3
|
+
* It is available under the MIT license.
|
|
4
|
+
*/
|
|
5
|
+
const BYTE_UNITS = ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
|
|
6
|
+
const BIBYTE_UNITS = ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"];
|
|
7
|
+
const BIT_UNITS = ["b", "kbit", "Mbit", "Gbit", "Tbit", "Pbit", "Ebit", "Zbit", "Ybit"];
|
|
8
|
+
const BIBIT_UNITS = ["b", "kibit", "Mibit", "Gibit", "Tibit", "Pibit", "Eibit", "Zibit", "Yibit"];
|
|
9
|
+
/**
|
|
10
|
+
* Formats the given number using `Number#toLocaleString`.
|
|
11
|
+
* - If locale is a string, the value is expected to be a locale-key (for example: `de`).
|
|
12
|
+
* - If locale is true, the system default locale is used for translation.
|
|
13
|
+
* - If no value for locale is specified, the number is returned unmodified.
|
|
14
|
+
* @param number - The number to be formatted.
|
|
15
|
+
* @param locale - The locale to use for formatting.
|
|
16
|
+
* @param options - Formatting options.
|
|
17
|
+
* @returns The formatted number.
|
|
18
|
+
*/
|
|
19
|
+
const toLocaleString = (number, locale, options) => {
|
|
20
|
+
let result = number;
|
|
21
|
+
if (typeof locale === "string" || Array.isArray(locale)) {
|
|
22
|
+
result = number.toLocaleString(locale, options);
|
|
23
|
+
}
|
|
24
|
+
else if (locale === true || options !== undefined) {
|
|
25
|
+
result = number.toLocaleString(undefined, options);
|
|
26
|
+
}
|
|
27
|
+
return result.toString();
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Convert bytes to a human readable string: `1337` → `1.34 kB`.
|
|
31
|
+
* @param number - The number to format.
|
|
32
|
+
* @param options - The options for formatting the number.
|
|
33
|
+
* @returns The formatted string.
|
|
34
|
+
* @group Formatting
|
|
35
|
+
* @example
|
|
36
|
+
* ```
|
|
37
|
+
* import prettyBytes from '@oliversalzburg/js-utils/format/bytes.js';
|
|
38
|
+
*
|
|
39
|
+
* prettyBytes(1337);
|
|
40
|
+
* //=> '1.34 kB'
|
|
41
|
+
*
|
|
42
|
+
* prettyBytes(100);
|
|
43
|
+
* //=> '100 B'
|
|
44
|
+
*
|
|
45
|
+
* // Display file size differences
|
|
46
|
+
* prettyBytes(42, {signed: true});
|
|
47
|
+
* //=> '+42 B'
|
|
48
|
+
*
|
|
49
|
+
* // Localized output using German locale
|
|
50
|
+
* prettyBytes(1337, {locale: 'de'});
|
|
51
|
+
* //=> '1,34 kB'
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export const formatBytes = (number, options = { binary: false, bits: false, space: true }) => {
|
|
55
|
+
if (!Number.isFinite(number)) {
|
|
56
|
+
throw new TypeError(`Expected a finite number, got ${typeof number}: ${number.toString()}`);
|
|
57
|
+
}
|
|
58
|
+
options = {
|
|
59
|
+
bits: false,
|
|
60
|
+
binary: false,
|
|
61
|
+
space: true,
|
|
62
|
+
...options,
|
|
63
|
+
};
|
|
64
|
+
const UNITS = options.bits
|
|
65
|
+
? options.binary
|
|
66
|
+
? BIBIT_UNITS
|
|
67
|
+
: BIT_UNITS
|
|
68
|
+
: options.binary
|
|
69
|
+
? BIBYTE_UNITS
|
|
70
|
+
: BYTE_UNITS;
|
|
71
|
+
const separator = options.space ? " " : "";
|
|
72
|
+
if (options.signed && number === 0) {
|
|
73
|
+
return ` 0${separator}${UNITS[0]}`;
|
|
74
|
+
}
|
|
75
|
+
const isNegative = number < 0;
|
|
76
|
+
const prefix = isNegative ? "-" : options.signed ? "+" : "";
|
|
77
|
+
if (isNegative) {
|
|
78
|
+
number = -number;
|
|
79
|
+
}
|
|
80
|
+
let localeOptions;
|
|
81
|
+
if (options.minimumFractionDigits !== undefined) {
|
|
82
|
+
localeOptions = { minimumFractionDigits: options.minimumFractionDigits };
|
|
83
|
+
}
|
|
84
|
+
if (options.maximumFractionDigits !== undefined) {
|
|
85
|
+
localeOptions = { maximumFractionDigits: options.maximumFractionDigits, ...localeOptions };
|
|
86
|
+
}
|
|
87
|
+
if (number < 1) {
|
|
88
|
+
const numberString = toLocaleString(number, options.locale, localeOptions);
|
|
89
|
+
return prefix + numberString + separator + UNITS[0];
|
|
90
|
+
}
|
|
91
|
+
const exponent = Math.min(Math.floor(options.binary ? Math.log(number) / Math.log(1024) : Math.log10(number) / 3), UNITS.length - 1);
|
|
92
|
+
number /= (options.binary ? 1024 : 1000) ** exponent;
|
|
93
|
+
if (!localeOptions) {
|
|
94
|
+
number = Number(number.toPrecision(3));
|
|
95
|
+
}
|
|
96
|
+
const numberString = toLocaleString(number, options.locale, localeOptions);
|
|
97
|
+
const unit = UNITS[exponent];
|
|
98
|
+
return prefix + numberString + separator + unit;
|
|
99
|
+
};
|
|
100
|
+
//# sourceMappingURL=bytes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bytes.js","sourceRoot":"","sources":["../../source/format/bytes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAmGH,MAAM,UAAU,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI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|
5
|
+
expect(() => {
|
|
6
|
+
formatBytes("");
|
|
7
|
+
}).to.throw();
|
|
8
|
+
expect(() => {
|
|
9
|
+
formatBytes("1");
|
|
10
|
+
}).to.throw();
|
|
11
|
+
expect(() => {
|
|
12
|
+
formatBytes(Number.NaN);
|
|
13
|
+
}).to.throw();
|
|
14
|
+
expect(() => {
|
|
15
|
+
formatBytes(true);
|
|
16
|
+
}).to.throw();
|
|
17
|
+
expect(() => {
|
|
18
|
+
formatBytes(Number.POSITIVE_INFINITY);
|
|
19
|
+
}).to.throw();
|
|
20
|
+
expect(() => {
|
|
21
|
+
formatBytes(Number.NEGATIVE_INFINITY);
|
|
22
|
+
}).to.throw();
|
|
23
|
+
expect(() => {
|
|
24
|
+
formatBytes(null);
|
|
25
|
+
}).to.throw();
|
|
26
|
+
});
|
|
27
|
+
it("converts bytes to human readable strings", () => {
|
|
28
|
+
expect(formatBytes(0)).to.equal("0 B");
|
|
29
|
+
expect(formatBytes(0.4)).to.equal("0.4 B");
|
|
30
|
+
expect(formatBytes(0.7)).to.equal("0.7 B");
|
|
31
|
+
expect(formatBytes(10)).to.equal("10 B");
|
|
32
|
+
expect(formatBytes(10.1)).to.equal("10.1 B");
|
|
33
|
+
expect(formatBytes(999)).to.equal("999 B");
|
|
34
|
+
expect(formatBytes(1001)).to.equal("1 kB");
|
|
35
|
+
expect(formatBytes(1e16)).to.equal("10 PB");
|
|
36
|
+
expect(formatBytes(1e30)).to.equal("1000000 YB");
|
|
37
|
+
});
|
|
38
|
+
it("supports negative number", () => {
|
|
39
|
+
expect(formatBytes(-0.4)).to.equal("-0.4 B");
|
|
40
|
+
expect(formatBytes(-0.7)).to.equal("-0.7 B");
|
|
41
|
+
expect(formatBytes(-10.1)).to.equal("-10.1 B");
|
|
42
|
+
expect(formatBytes(-999)).to.equal("-999 B");
|
|
43
|
+
expect(formatBytes(-1001)).to.equal("-1 kB");
|
|
44
|
+
});
|
|
45
|
+
it("locale option", () => {
|
|
46
|
+
expect(formatBytes(-0.4, { locale: "de" })).to.equal("-0,4 B");
|
|
47
|
+
expect(formatBytes(0.4, { locale: "de" })).to.equal("0,4 B");
|
|
48
|
+
expect(formatBytes(1001, { locale: "de" })).to.equal("1 kB");
|
|
49
|
+
expect(formatBytes(10.1, { locale: "de" })).to.equal("10,1 B");
|
|
50
|
+
expect(formatBytes(1e30, { locale: "de" })).to.equal("1.000.000 YB");
|
|
51
|
+
expect(formatBytes(-0.4, { locale: "en" })).to.equal("-0.4 B");
|
|
52
|
+
expect(formatBytes(0.4, { locale: "en" })).to.equal("0.4 B");
|
|
53
|
+
expect(formatBytes(1001, { locale: "en" })).to.equal("1 kB");
|
|
54
|
+
expect(formatBytes(10.1, { locale: "en" })).to.equal("10.1 B");
|
|
55
|
+
expect(formatBytes(1e30, { locale: "en" })).to.equal("1,000,000 YB");
|
|
56
|
+
expect(formatBytes(-0.4, { locale: ["unknown", "de", "en"] })).to.equal("-0,4 B");
|
|
57
|
+
expect(formatBytes(0.4, { locale: ["unknown", "de", "en"] })).to.equal("0,4 B");
|
|
58
|
+
expect(formatBytes(1001, { locale: ["unknown", "de", "en"] })).to.equal("1 kB");
|
|
59
|
+
expect(formatBytes(10.1, { locale: ["unknown", "de", "en"] })).to.equal("10,1 B");
|
|
60
|
+
expect(formatBytes(1e30, { locale: ["unknown", "de", "en"] })).to.equal("1.000.000 YB");
|
|
61
|
+
expect(formatBytes(-0.4, { locale: true })).to.equal("-0.4 B");
|
|
62
|
+
expect(formatBytes(0.4, { locale: true })).to.equal("0.4 B");
|
|
63
|
+
expect(formatBytes(1001, { locale: true })).to.equal("1 kB");
|
|
64
|
+
expect(formatBytes(10.1, { locale: true })).to.equal("10.1 B");
|
|
65
|
+
expect(formatBytes(1e30, { locale: true })).to.equal("1,000,000 YB");
|
|
66
|
+
expect(formatBytes(-0.4, { locale: false })).to.equal("-0.4 B");
|
|
67
|
+
expect(formatBytes(0.4, { locale: false })).to.equal("0.4 B");
|
|
68
|
+
expect(formatBytes(1001, { locale: false })).to.equal("1 kB");
|
|
69
|
+
expect(formatBytes(10.1, { locale: false })).to.equal("10.1 B");
|
|
70
|
+
expect(formatBytes(1e30, { locale: false })).to.equal("1000000 YB");
|
|
71
|
+
expect(formatBytes(-0.4, { locale: undefined })).to.equal("-0.4 B");
|
|
72
|
+
expect(formatBytes(0.4, { locale: undefined })).to.equal("0.4 B");
|
|
73
|
+
expect(formatBytes(1001, { locale: undefined })).to.equal("1 kB");
|
|
74
|
+
expect(formatBytes(10.1, { locale: undefined })).to.equal("10.1 B");
|
|
75
|
+
expect(formatBytes(1e30, { locale: undefined })).to.equal("1000000 YB");
|
|
76
|
+
});
|
|
77
|
+
it("signed option", () => {
|
|
78
|
+
expect(formatBytes(42, { signed: true })).to.equal("+42 B");
|
|
79
|
+
expect(formatBytes(-13, { signed: true })).to.equal("-13 B");
|
|
80
|
+
expect(formatBytes(0, { signed: true })).to.equal(" 0 B");
|
|
81
|
+
});
|
|
82
|
+
it("bits option", () => {
|
|
83
|
+
expect(formatBytes(0, { bits: true })).to.equal("0 b");
|
|
84
|
+
expect(formatBytes(0.4, { bits: true })).to.equal("0.4 b");
|
|
85
|
+
expect(formatBytes(0.7, { bits: true })).to.equal("0.7 b");
|
|
86
|
+
expect(formatBytes(10, { bits: true })).to.equal("10 b");
|
|
87
|
+
expect(formatBytes(10.1, { bits: true })).to.equal("10.1 b");
|
|
88
|
+
expect(formatBytes(999, { bits: true })).to.equal("999 b");
|
|
89
|
+
expect(formatBytes(1001, { bits: true })).to.equal("1 kbit");
|
|
90
|
+
expect(formatBytes(1001, { bits: true })).to.equal("1 kbit");
|
|
91
|
+
expect(formatBytes(1e16, { bits: true })).to.equal("10 Pbit");
|
|
92
|
+
expect(formatBytes(1e30, { bits: true })).to.equal("1000000 Ybit");
|
|
93
|
+
});
|
|
94
|
+
it("binary option", () => {
|
|
95
|
+
expect(formatBytes(0, { binary: true })).to.equal("0 B");
|
|
96
|
+
expect(formatBytes(4, { binary: true })).to.equal("4 B");
|
|
97
|
+
expect(formatBytes(10, { binary: true })).to.equal("10 B");
|
|
98
|
+
expect(formatBytes(10.1, { binary: true })).to.equal("10.1 B");
|
|
99
|
+
expect(formatBytes(999, { binary: true })).to.equal("999 B");
|
|
100
|
+
expect(formatBytes(1025, { binary: true })).to.equal("1 KiB");
|
|
101
|
+
expect(formatBytes(1001, { binary: true })).to.equal("1000 B");
|
|
102
|
+
expect(formatBytes(1e16, { binary: true })).to.equal("8.88 PiB");
|
|
103
|
+
expect(formatBytes(1e30, { binary: true })).to.equal("827000 YiB");
|
|
104
|
+
});
|
|
105
|
+
it("bits and binary option", () => {
|
|
106
|
+
expect(formatBytes(0, { bits: true, binary: true })).to.equal("0 b");
|
|
107
|
+
expect(formatBytes(4, { bits: true, binary: true })).to.equal("4 b");
|
|
108
|
+
expect(formatBytes(10, { bits: true, binary: true })).to.equal("10 b");
|
|
109
|
+
expect(formatBytes(999, { bits: true, binary: true })).to.equal("999 b");
|
|
110
|
+
expect(formatBytes(1025, { bits: true, binary: true })).to.equal("1 kibit");
|
|
111
|
+
expect(formatBytes(1e6, { bits: true, binary: true })).to.equal("977 kibit");
|
|
112
|
+
});
|
|
113
|
+
it("fractional digits options", () => {
|
|
114
|
+
expect(formatBytes(1900, { maximumFractionDigits: 1 })).to.equal("1.9 kB");
|
|
115
|
+
expect(formatBytes(1900, { minimumFractionDigits: 3 })).to.equal("1.900 kB");
|
|
116
|
+
expect(formatBytes(1911, { maximumFractionDigits: 1 })).to.equal("1.9 kB");
|
|
117
|
+
expect(formatBytes(1111, { maximumFractionDigits: 2 })).to.equal("1.11 kB");
|
|
118
|
+
expect(formatBytes(1019, { maximumFractionDigits: 3 })).to.equal("1.019 kB");
|
|
119
|
+
expect(formatBytes(1001, { maximumFractionDigits: 3 })).to.equal("1.001 kB");
|
|
120
|
+
expect(formatBytes(1000, { minimumFractionDigits: 1, maximumFractionDigits: 3 })).to.equal("1.0 kB");
|
|
121
|
+
expect(formatBytes(3942, { minimumFractionDigits: 1, maximumFractionDigits: 2 })).to.equal("3.94 kB");
|
|
122
|
+
expect(formatBytes(4001, { maximumFractionDigits: 3, binary: true })).to.equal("3.907 KiB");
|
|
123
|
+
expect(formatBytes(18_717, { maximumFractionDigits: 2, binary: true })).to.equal("18.28 KiB");
|
|
124
|
+
expect(formatBytes(18_717, { maximumFractionDigits: 4, binary: true })).to.equal("18.2783 KiB");
|
|
125
|
+
expect(formatBytes(32_768, { minimumFractionDigits: 2, maximumFractionDigits: 3, binary: true })).to.equal("32.00 KiB");
|
|
126
|
+
expect(formatBytes(65_536, { minimumFractionDigits: 1, maximumFractionDigits: 3, binary: true })).to.equal("64.0 KiB");
|
|
127
|
+
});
|
|
128
|
+
it("space option", () => {
|
|
129
|
+
expect(formatBytes(0)).to.equal("0 B");
|
|
130
|
+
expect(formatBytes(0, { space: false })).to.equal("0B");
|
|
131
|
+
expect(formatBytes(999)).to.equal("999 B");
|
|
132
|
+
expect(formatBytes(999, { space: false })).to.equal("999B");
|
|
133
|
+
expect(formatBytes(-13, { signed: true })).to.equal("-13 B");
|
|
134
|
+
expect(formatBytes(-13, { signed: true, space: false })).to.equal("-13B");
|
|
135
|
+
expect(formatBytes(42, { signed: true })).to.equal("+42 B");
|
|
136
|
+
expect(formatBytes(42, { signed: true, space: false })).to.equal("+42B");
|
|
137
|
+
});
|
|
138
|
+
//# sourceMappingURL=bytes.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bytes.test.js","sourceRoot":"","sources":["../../source/format/bytes.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,EAAE,CAAC,yBAAyB,EAAE,GAAG,EAAE;IACjC,MAAM,CAAC,GAAG,EAAE;QACV,WAAW,CAAC,EAAuB,CAAC,CAAC;IACv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AAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAC1E,MAAM,CAAC,WAAW,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC5D,MAAM,CAAC,WAAW,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;AAC3E,CAAC,CAAC,CAAC"}
|
package/format/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../source/format/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,102 @@
|
|
|
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
|
+
* @group Formatting
|
|
9
|
+
*/
|
|
10
|
+
export interface FormatMillisecondsOptions {
|
|
11
|
+
/**
|
|
12
|
+
* Number of digits to appear after the seconds decimal point.
|
|
13
|
+
*/
|
|
14
|
+
secondsDecimalDigits?: number;
|
|
15
|
+
/**
|
|
16
|
+
* Number of digits to appear after the milliseconds decimal point.
|
|
17
|
+
*
|
|
18
|
+
* Useful in combination with [`process.hrtime()`](https://nodejs.org/api/process.html#process_process_hrtime).
|
|
19
|
+
*/
|
|
20
|
+
millisecondsDecimalDigits?: number;
|
|
21
|
+
/**
|
|
22
|
+
* Keep milliseconds on whole seconds: `13s` → `13.0s`.
|
|
23
|
+
*
|
|
24
|
+
* 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.
|
|
25
|
+
*/
|
|
26
|
+
keepDecimalsOnWholeSeconds?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Only show the first unit: `1h 10m` → `1h`.
|
|
29
|
+
*
|
|
30
|
+
* Also ensures that `millisecondsDecimalDigits` and `secondsDecimalDigits` are both set to `0`.
|
|
31
|
+
*/
|
|
32
|
+
compact?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Number of units to show. Setting `compact` to `true` overrides this option.
|
|
35
|
+
*/
|
|
36
|
+
unitCount?: number;
|
|
37
|
+
/**
|
|
38
|
+
* Use full-length units: `5h 1m 45s` → `5 hours 1 minute 45 seconds`.
|
|
39
|
+
*/
|
|
40
|
+
verbose?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Show milliseconds separately. This means they won't be included in the decimal part of the seconds.
|
|
43
|
+
*/
|
|
44
|
+
separateMilliseconds?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Show microseconds and nanoseconds.
|
|
47
|
+
*/
|
|
48
|
+
formatSubMilliseconds?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Display time using colon notation: `5h 1m 45s` → `5:01:45`. Always shows time in at least minutes: `1s` → `0:01`
|
|
51
|
+
*
|
|
52
|
+
* Useful when you want to display time without the time units, similar to a digital watch.
|
|
53
|
+
*
|
|
54
|
+
* Setting `colonNotation` to `true` overrides the following options to `false`:
|
|
55
|
+
* - `compact`
|
|
56
|
+
* - `formatSubMilliseconds`
|
|
57
|
+
* - `separateMilliseconds`
|
|
58
|
+
* - `verbose`
|
|
59
|
+
*/
|
|
60
|
+
colonNotation?: boolean;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Convert milliseconds to a human readable string: `1337000000` → `15d 11h 23m 20s`.
|
|
64
|
+
* @param milliseconds - Milliseconds to humanize.
|
|
65
|
+
* @param options - Options for humanizing the milliseconds.
|
|
66
|
+
* @returns The humanized string.
|
|
67
|
+
* @group Formatting
|
|
68
|
+
* @example
|
|
69
|
+
* ```
|
|
70
|
+
* import formatMilliseconds from 'pretty-ms';
|
|
71
|
+
*
|
|
72
|
+
* formatMilliseconds(1337000000);
|
|
73
|
+
* //=> '15d 11h 23m 20s'
|
|
74
|
+
*
|
|
75
|
+
* formatMilliseconds(1337);
|
|
76
|
+
* //=> '1.3s'
|
|
77
|
+
*
|
|
78
|
+
* formatMilliseconds(133);
|
|
79
|
+
* //=> '133ms'
|
|
80
|
+
*
|
|
81
|
+
* // `compact` option
|
|
82
|
+
* formatMilliseconds(1337, {compact: true});
|
|
83
|
+
* //=> '1s'
|
|
84
|
+
*
|
|
85
|
+
* // `verbose` option
|
|
86
|
+
* formatMilliseconds(1335669000, {verbose: true});
|
|
87
|
+
* //=> '15 days 11 hours 1 minute 9 seconds'
|
|
88
|
+
*
|
|
89
|
+
* // `colonNotation` option
|
|
90
|
+
* formatMilliseconds(95500, {colonNotation: true});
|
|
91
|
+
* //=> '1:35.5'
|
|
92
|
+
*
|
|
93
|
+
* // `formatSubMilliseconds` option
|
|
94
|
+
* formatMilliseconds(100.400080, {formatSubMilliseconds: true})
|
|
95
|
+
* //=> '100ms 400µs 80ns'
|
|
96
|
+
*
|
|
97
|
+
* // Can be useful for time durations
|
|
98
|
+
* formatMilliseconds(new Date(2014, 0, 1, 10, 40) - new Date(2014, 0, 1, 10, 5))
|
|
99
|
+
* //=> '35m'
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export declare const formatMilliseconds: (milliseconds: number | bigint, options?: Readonly<FormatMillisecondsOptions>) => string;
|
|
@@ -0,0 +1,193 @@
|
|
|
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
|
+
minutes: Math.trunc((milliseconds / 60_000) % 60),
|
|
12
|
+
seconds: Math.trunc((milliseconds / 1000) % 60),
|
|
13
|
+
milliseconds: Math.trunc(milliseconds % 1000),
|
|
14
|
+
microseconds: Math.trunc(toZeroIfInfinity(milliseconds * 1000) % 1000),
|
|
15
|
+
nanoseconds: Math.trunc(toZeroIfInfinity(milliseconds * 1e6) % 1000),
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
const parseBigint = (milliseconds) => {
|
|
19
|
+
return {
|
|
20
|
+
days: milliseconds / 86400000n,
|
|
21
|
+
hours: (milliseconds / 3600000n) % 24n,
|
|
22
|
+
minutes: (milliseconds / 60000n) % 60n,
|
|
23
|
+
seconds: (milliseconds / 1000n) % 60n,
|
|
24
|
+
milliseconds: milliseconds % 1000n,
|
|
25
|
+
microseconds: 0n,
|
|
26
|
+
nanoseconds: 0n,
|
|
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
|
+
* @group Formatting
|
|
54
|
+
* @example
|
|
55
|
+
* ```
|
|
56
|
+
* import formatMilliseconds from 'pretty-ms';
|
|
57
|
+
*
|
|
58
|
+
* formatMilliseconds(1337000000);
|
|
59
|
+
* //=> '15d 11h 23m 20s'
|
|
60
|
+
*
|
|
61
|
+
* formatMilliseconds(1337);
|
|
62
|
+
* //=> '1.3s'
|
|
63
|
+
*
|
|
64
|
+
* formatMilliseconds(133);
|
|
65
|
+
* //=> '133ms'
|
|
66
|
+
*
|
|
67
|
+
* // `compact` option
|
|
68
|
+
* formatMilliseconds(1337, {compact: true});
|
|
69
|
+
* //=> '1s'
|
|
70
|
+
*
|
|
71
|
+
* // `verbose` option
|
|
72
|
+
* formatMilliseconds(1335669000, {verbose: true});
|
|
73
|
+
* //=> '15 days 11 hours 1 minute 9 seconds'
|
|
74
|
+
*
|
|
75
|
+
* // `colonNotation` option
|
|
76
|
+
* formatMilliseconds(95500, {colonNotation: true});
|
|
77
|
+
* //=> '1:35.5'
|
|
78
|
+
*
|
|
79
|
+
* // `formatSubMilliseconds` option
|
|
80
|
+
* formatMilliseconds(100.400080, {formatSubMilliseconds: true})
|
|
81
|
+
* //=> '100ms 400µs 80ns'
|
|
82
|
+
*
|
|
83
|
+
* // Can be useful for time durations
|
|
84
|
+
* formatMilliseconds(new Date(2014, 0, 1, 10, 40) - new Date(2014, 0, 1, 10, 5))
|
|
85
|
+
* //=> '35m'
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
export const formatMilliseconds = (milliseconds, options = {
|
|
89
|
+
colonNotation: false,
|
|
90
|
+
compact: false,
|
|
91
|
+
formatSubMilliseconds: false,
|
|
92
|
+
keepDecimalsOnWholeSeconds: false,
|
|
93
|
+
millisecondsDecimalDigits: 0,
|
|
94
|
+
secondsDecimalDigits: 1,
|
|
95
|
+
separateMilliseconds: false,
|
|
96
|
+
unitCount: Infinity,
|
|
97
|
+
verbose: false,
|
|
98
|
+
}) => {
|
|
99
|
+
const isBigInt = typeof milliseconds === "bigint";
|
|
100
|
+
if (!isBigInt && !Number.isFinite(milliseconds)) {
|
|
101
|
+
throw new TypeError("Expected a finite number or bigint");
|
|
102
|
+
}
|
|
103
|
+
const optionsAdjusted = { ...options };
|
|
104
|
+
if (optionsAdjusted.colonNotation) {
|
|
105
|
+
optionsAdjusted.compact = false;
|
|
106
|
+
optionsAdjusted.formatSubMilliseconds = false;
|
|
107
|
+
optionsAdjusted.separateMilliseconds = false;
|
|
108
|
+
optionsAdjusted.verbose = false;
|
|
109
|
+
}
|
|
110
|
+
if (optionsAdjusted.compact) {
|
|
111
|
+
optionsAdjusted.unitCount = 1;
|
|
112
|
+
optionsAdjusted.secondsDecimalDigits = 0;
|
|
113
|
+
optionsAdjusted.millisecondsDecimalDigits = 0;
|
|
114
|
+
}
|
|
115
|
+
let result = [];
|
|
116
|
+
const floorDecimals = (value, decimalDigits) => {
|
|
117
|
+
const flooredInterimValue = Math.floor(value * 10 ** decimalDigits + SECOND_ROUNDING_EPSILON);
|
|
118
|
+
const flooredValue = Math.round(flooredInterimValue) / 10 ** decimalDigits;
|
|
119
|
+
return flooredValue.toFixed(decimalDigits);
|
|
120
|
+
};
|
|
121
|
+
const add = (value, long, short, valueString) => {
|
|
122
|
+
if ((result.length === 0 || !optionsAdjusted.colonNotation) &&
|
|
123
|
+
isZero(value) &&
|
|
124
|
+
!(optionsAdjusted.colonNotation && short === "m")) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
valueString ??= String(value);
|
|
128
|
+
if (optionsAdjusted.colonNotation) {
|
|
129
|
+
const wholeDigits = valueString.includes(".")
|
|
130
|
+
? valueString.split(".")[0].length
|
|
131
|
+
: valueString.length;
|
|
132
|
+
const minLength = result.length > 0 ? 2 : 1;
|
|
133
|
+
valueString = "0".repeat(Math.max(0, minLength - wholeDigits)) + valueString;
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
valueString += optionsAdjusted.verbose ? " " + pluralize(long, value) : short;
|
|
137
|
+
}
|
|
138
|
+
result.push(valueString);
|
|
139
|
+
};
|
|
140
|
+
const parsed = parseMilliseconds(milliseconds);
|
|
141
|
+
const days = BigInt(parsed.days);
|
|
142
|
+
add(days / 365n, "year", "y");
|
|
143
|
+
add(days % 365n, "day", "d");
|
|
144
|
+
add(Number(parsed.hours), "hour", "h");
|
|
145
|
+
add(Number(parsed.minutes), "minute", "m");
|
|
146
|
+
if (optionsAdjusted.separateMilliseconds ||
|
|
147
|
+
optionsAdjusted.formatSubMilliseconds ||
|
|
148
|
+
(!optionsAdjusted.colonNotation && milliseconds < 1000)) {
|
|
149
|
+
const seconds = Number(parsed.seconds);
|
|
150
|
+
const milliseconds = Number(parsed.milliseconds);
|
|
151
|
+
const microseconds = Number(parsed.microseconds);
|
|
152
|
+
const nanoseconds = Number(parsed.nanoseconds);
|
|
153
|
+
add(seconds, "second", "s");
|
|
154
|
+
if (optionsAdjusted.formatSubMilliseconds) {
|
|
155
|
+
add(milliseconds, "millisecond", "ms");
|
|
156
|
+
add(microseconds, "microsecond", "µs");
|
|
157
|
+
add(nanoseconds, "nanosecond", "ns");
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
const millisecondsAndBelow = milliseconds + microseconds / 1000 + nanoseconds / 1e6;
|
|
161
|
+
const millisecondsDecimalDigits = typeof optionsAdjusted.millisecondsDecimalDigits === "number"
|
|
162
|
+
? optionsAdjusted.millisecondsDecimalDigits
|
|
163
|
+
: 0;
|
|
164
|
+
const roundedMilliseconds = millisecondsAndBelow >= 1
|
|
165
|
+
? Math.round(millisecondsAndBelow)
|
|
166
|
+
: Math.ceil(millisecondsAndBelow);
|
|
167
|
+
const millisecondsString = millisecondsDecimalDigits
|
|
168
|
+
? millisecondsAndBelow.toFixed(millisecondsDecimalDigits)
|
|
169
|
+
: roundedMilliseconds.toString();
|
|
170
|
+
add(Number.parseFloat(millisecondsString), "millisecond", "ms", millisecondsString);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
const seconds = ((isBigInt ? Number(milliseconds % ONE_DAY_IN_MILLISECONDS) : milliseconds) / 1000) % 60;
|
|
175
|
+
const secondsDecimalDigits = typeof optionsAdjusted.secondsDecimalDigits === "number"
|
|
176
|
+
? optionsAdjusted.secondsDecimalDigits
|
|
177
|
+
: 1;
|
|
178
|
+
const secondsFixed = floorDecimals(seconds, secondsDecimalDigits);
|
|
179
|
+
const secondsString = optionsAdjusted.keepDecimalsOnWholeSeconds
|
|
180
|
+
? secondsFixed
|
|
181
|
+
: secondsFixed.replace(/\.0+$/, "");
|
|
182
|
+
add(Number.parseFloat(secondsString), "second", "s", secondsString);
|
|
183
|
+
}
|
|
184
|
+
if (result.length === 0) {
|
|
185
|
+
return "0" + (optionsAdjusted.verbose ? " milliseconds" : "ms");
|
|
186
|
+
}
|
|
187
|
+
const separator = optionsAdjusted.colonNotation ? ":" : " ";
|
|
188
|
+
if (typeof optionsAdjusted.unitCount === "number") {
|
|
189
|
+
result = result.slice(0, Math.max(optionsAdjusted.unitCount, 1));
|
|
190
|
+
}
|
|
191
|
+
return result.join(separator);
|
|
192
|
+
};
|
|
193
|
+
//# sourceMappingURL=milliseconds.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"milliseconds.js","sourceRoot":"","sources":["../../source/format/milliseconds.ts"],"names":[],"mappings":"AAA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AAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,eAAe,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC;IACnE,CAAC;IAED,OAAO,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;AAChC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { it } from "mocha";
|
|
3
|
+
import { formatMilliseconds } from "./milliseconds.js";
|
|
4
|
+
const toBigInt = (milliseconds) => {
|
|
5
|
+
if (typeof milliseconds !== "number") {
|
|
6
|
+
return undefined;
|
|
7
|
+
}
|
|
8
|
+
try {
|
|
9
|
+
return BigInt(milliseconds);
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
function runTests({ title, defaultOptions, cases, }) {
|
|
16
|
+
it(title, () => {
|
|
17
|
+
const format = (milliseconds, options = {}) => formatMilliseconds(milliseconds, { ...defaultOptions, ...options });
|
|
18
|
+
for (const testCase of cases) {
|
|
19
|
+
const [milliseconds, options, expected] = testCase.length === 3 ? testCase : [testCase[0], undefined, testCase[1]];
|
|
20
|
+
expect(format(milliseconds, options)).to.equal(expected, `Number(${milliseconds.toString()})`);
|
|
21
|
+
const bigint = toBigInt(milliseconds);
|
|
22
|
+
if (typeof bigint === "bigint") {
|
|
23
|
+
expect(format(bigint, options)).to.equal(expected, `BigInt(${bigint.toString()}n)`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
runTests({
|
|
29
|
+
title: "prettify milliseconds",
|
|
30
|
+
cases: [
|
|
31
|
+
[0, "0ms"],
|
|
32
|
+
[0.1, "1ms"],
|
|
33
|
+
[1, "1ms"],
|
|
34
|
+
[999, "999ms"],
|
|
35
|
+
[1000, "1s"],
|
|
36
|
+
[1000 + 400, "1.4s"],
|
|
37
|
+
[1000 * 2 + 400, "2.4s"],
|
|
38
|
+
[1000 * 55, "55s"],
|
|
39
|
+
[1000 * 67, "1m 7s"],
|
|
40
|
+
[1000 * 60 * 5, "5m"],
|
|
41
|
+
[1000 * 60 * 67, "1h 7m"],
|
|
42
|
+
[1000 * 60 * 60 * 12, "12h"],
|
|
43
|
+
[1000 * 60 * 60 * 40, "1d 16h"],
|
|
44
|
+
[1000 * 60 * 60 * 999, "41d 15h"],
|
|
45
|
+
[1000 * 60 * 60 * 24 * 465, "1y 100d"],
|
|
46
|
+
[1000 * 60 * 67 * 24 * 465, "1y 154d 6h"],
|
|
47
|
+
[119_999, "1m 59.9s"],
|
|
48
|
+
[120_000, "2m"],
|
|
49
|
+
[Number.MAX_SAFE_INTEGER, "285616y 151d 8h 59m 0.9s"],
|
|
50
|
+
],
|
|
51
|
+
});
|
|
52
|
+
runTests({
|
|
53
|
+
title: "have a compact option",
|
|
54
|
+
defaultOptions: { compact: true },
|
|
55
|
+
cases: [
|
|
56
|
+
[1000 + 4, "1s"],
|
|
57
|
+
[1000 * 60 * 60 * 999, "41d"],
|
|
58
|
+
[1000 * 60 * 60 * 24 * 465, "1y"],
|
|
59
|
+
[1000 * 60 * 67 * 24 * 465, "1y"],
|
|
60
|
+
],
|
|
61
|
+
});
|
|
62
|
+
runTests({
|
|
63
|
+
title: "have a unitCount option",
|
|
64
|
+
cases: [
|
|
65
|
+
[1000 * 60, { unitCount: 0 }, "1m"],
|
|
66
|
+
[1000 * 60, { unitCount: 1 }, "1m"],
|
|
67
|
+
[1000 * 60 * 67, { unitCount: 1 }, "1h"],
|
|
68
|
+
[1000 * 60 * 67, { unitCount: 2 }, "1h 7m"],
|
|
69
|
+
[1000 * 60 * 67 * 24 * 465, { unitCount: 1 }, "1y"],
|
|
70
|
+
[1000 * 60 * 67 * 24 * 465, { unitCount: 2 }, "1y 154d"],
|
|
71
|
+
[1000 * 60 * 67 * 24 * 465, { unitCount: 3 }, "1y 154d 6h"],
|
|
72
|
+
],
|
|
73
|
+
});
|
|
74
|
+
runTests({
|
|
75
|
+
title: "have a secondsDecimalDigits option",
|
|
76
|
+
cases: [
|
|
77
|
+
[10_000, "10s"],
|
|
78
|
+
[33_333, "33.3s"],
|
|
79
|
+
[999, { secondsDecimalDigits: 0 }, "999ms"],
|
|
80
|
+
[1000, { secondsDecimalDigits: 0 }, "1s"],
|
|
81
|
+
[1999, { secondsDecimalDigits: 0 }, "1s"],
|
|
82
|
+
[2000, { secondsDecimalDigits: 0 }, "2s"],
|
|
83
|
+
[33_333, { secondsDecimalDigits: 0 }, "33s"],
|
|
84
|
+
[33_333, { secondsDecimalDigits: 4 }, "33.3330s"],
|
|
85
|
+
],
|
|
86
|
+
});
|
|
87
|
+
runTests({
|
|
88
|
+
title: "have a millisecondsDecimalDigits option",
|
|
89
|
+
cases: [
|
|
90
|
+
[33.333, "33ms"],
|
|
91
|
+
[33.333, { millisecondsDecimalDigits: 0 }, "33ms"],
|
|
92
|
+
[33.333, { millisecondsDecimalDigits: 4 }, "33.3330ms"],
|
|
93
|
+
],
|
|
94
|
+
});
|
|
95
|
+
runTests({
|
|
96
|
+
title: "have a keepDecimalsOnWholeSeconds option",
|
|
97
|
+
defaultOptions: { keepDecimalsOnWholeSeconds: true },
|
|
98
|
+
cases: [
|
|
99
|
+
[1000 * 33, { secondsDecimalDigits: 2 }, "33.00s"],
|
|
100
|
+
[1000 * 33.000_04, { secondsDecimalDigits: 2 }, "33.00s"],
|
|
101
|
+
],
|
|
102
|
+
});
|
|
103
|
+
runTests({
|
|
104
|
+
title: "have a verbose option",
|
|
105
|
+
defaultOptions: { verbose: true },
|
|
106
|
+
cases: [
|
|
107
|
+
[0, "0 milliseconds"],
|
|
108
|
+
[0.1, "1 millisecond"],
|
|
109
|
+
[1, "1 millisecond"],
|
|
110
|
+
[1000, "1 second"],
|
|
111
|
+
[1000 + 400, "1.4 seconds"],
|
|
112
|
+
[1000 * 2 + 400, "2.4 seconds"],
|
|
113
|
+
[1000 * 5, "5 seconds"],
|
|
114
|
+
[1000 * 55, "55 seconds"],
|
|
115
|
+
[1000 * 67, "1 minute 7 seconds"],
|
|
116
|
+
[1000 * 60 * 5, "5 minutes"],
|
|
117
|
+
[1000 * 60 * 67, "1 hour 7 minutes"],
|
|
118
|
+
[1000 * 60 * 60 * 12, "12 hours"],
|
|
119
|
+
[1000 * 60 * 60 * 40, "1 day 16 hours"],
|
|
120
|
+
[1000 * 60 * 60 * 999, "41 days 15 hours"],
|
|
121
|
+
[1000 * 60 * 60 * 24 * 465, "1 year 100 days"],
|
|
122
|
+
[1000 * 60 * 67 * 24 * 465, "1 year 154 days 6 hours"],
|
|
123
|
+
],
|
|
124
|
+
});
|
|
125
|
+
runTests({
|
|
126
|
+
title: "have a separateMilliseconds option",
|
|
127
|
+
cases: [
|
|
128
|
+
[1100, { separateMilliseconds: false }, "1.1s"],
|
|
129
|
+
[1100, { separateMilliseconds: true }, "1s 100ms"],
|
|
130
|
+
],
|
|
131
|
+
});
|
|
132
|
+
runTests({
|
|
133
|
+
title: "have a formatSubMilliseconds option",
|
|
134
|
+
defaultOptions: { formatSubMilliseconds: true },
|
|
135
|
+
cases: [
|
|
136
|
+
[0.4, "400µs"],
|
|
137
|
+
[0.123_571, "123µs 571ns"],
|
|
138
|
+
[0.123_456_789, "123µs 456ns"],
|
|
139
|
+
[60 * 60 * 1000 + 23 * 1000 + 433 + 0.123_456, "1h 23s 433ms 123µs 456ns"],
|
|
140
|
+
],
|
|
141
|
+
});
|
|
142
|
+
runTests({
|
|
143
|
+
title: "work with verbose and compact options",
|
|
144
|
+
defaultOptions: { verbose: true, compact: true },
|
|
145
|
+
cases: [
|
|
146
|
+
[1000, "1 second"],
|
|
147
|
+
[1000 + 400, "1 second"],
|
|
148
|
+
[1000 * 2 + 400, "2 seconds"],
|
|
149
|
+
[1000 * 5, "5 seconds"],
|
|
150
|
+
[1000 * 55, "55 seconds"],
|
|
151
|
+
[1000 * 67, "1 minute"],
|
|
152
|
+
[1000 * 60 * 5, "5 minutes"],
|
|
153
|
+
[1000 * 60 * 67, "1 hour"],
|
|
154
|
+
[1000 * 60 * 60 * 12, "12 hours"],
|
|
155
|
+
[1000 * 60 * 60 * 40, "1 day"],
|
|
156
|
+
[1000 * 60 * 60 * 999, "41 days"],
|
|
157
|
+
[1000 * 60 * 60 * 24 * 465, "1 year"],
|
|
158
|
+
[1000 * 60 * 67 * 24 * 750, "2 years"],
|
|
159
|
+
],
|
|
160
|
+
});
|
|
161
|
+
runTests({
|
|
162
|
+
title: "work with verbose and unitCount options",
|
|
163
|
+
defaultOptions: { verbose: true },
|
|
164
|
+
cases: [
|
|
165
|
+
[1000 * 60, { unitCount: 1 }, "1 minute"],
|
|
166
|
+
[1000 * 60 * 67, { unitCount: 1 }, "1 hour"],
|
|
167
|
+
[1000 * 60 * 67, { unitCount: 2 }, "1 hour 7 minutes"],
|
|
168
|
+
[1000 * 60 * 67 * 24 * 465, { unitCount: 1 }, "1 year"],
|
|
169
|
+
[1000 * 60 * 67 * 24 * 465, { unitCount: 2 }, "1 year 154 days"],
|
|
170
|
+
[1000 * 60 * 67 * 24 * 465, { unitCount: 3 }, "1 year 154 days 6 hours"],
|
|
171
|
+
],
|
|
172
|
+
});
|
|
173
|
+
runTests({
|
|
174
|
+
title: "work with verbose and secondsDecimalDigits options",
|
|
175
|
+
defaultOptions: { verbose: true, secondsDecimalDigits: 4 },
|
|
176
|
+
cases: [
|
|
177
|
+
[1000, "1 second"],
|
|
178
|
+
[1000 + 400, "1.4000 seconds"],
|
|
179
|
+
[1000 * 2 + 400, "2.4000 seconds"],
|
|
180
|
+
[1000 * 5 + 254, "5.2540 seconds"],
|
|
181
|
+
[33_333, "33.3330 seconds"],
|
|
182
|
+
],
|
|
183
|
+
});
|
|
184
|
+
runTests({
|
|
185
|
+
title: "work with verbose and millisecondsDecimalDigits options",
|
|
186
|
+
defaultOptions: { verbose: true, millisecondsDecimalDigits: 4 },
|
|
187
|
+
cases: [
|
|
188
|
+
[1, "1.0000 millisecond"],
|
|
189
|
+
[1 + 0.4, "1.4000 milliseconds"],
|
|
190
|
+
[1 * 2 + 0.4, "2.4000 milliseconds"],
|
|
191
|
+
[1 * 5 + 0.254, "5.2540 milliseconds"],
|
|
192
|
+
[33.333, "33.3330 milliseconds"],
|
|
193
|
+
],
|
|
194
|
+
});
|
|
195
|
+
runTests({
|
|
196
|
+
title: "work with verbose and formatSubMilliseconds options",
|
|
197
|
+
defaultOptions: { formatSubMilliseconds: true, verbose: true },
|
|
198
|
+
cases: [
|
|
199
|
+
[0.4, "400 microseconds"],
|
|
200
|
+
[0.123_571, "123 microseconds 571 nanoseconds"],
|
|
201
|
+
[0.123_456_789, "123 microseconds 456 nanoseconds"],
|
|
202
|
+
[0.001, "1 microsecond"],
|
|
203
|
+
],
|
|
204
|
+
});
|
|
205
|
+
runTests({
|
|
206
|
+
title: "compact option overrides unitCount option",
|
|
207
|
+
defaultOptions: { verbose: true, compact: true },
|
|
208
|
+
cases: [
|
|
209
|
+
[1000 * 60 * 67 * 24 * 465, { unitCount: 1 }, "1 year"],
|
|
210
|
+
[1000 * 60 * 67 * 24 * 465, { unitCount: 2 }, "1 year"],
|
|
211
|
+
[1000 * 60 * 67 * 24 * 465, { unitCount: 3 }, "1 year"],
|
|
212
|
+
],
|
|
213
|
+
});
|
|
214
|
+
runTests({
|
|
215
|
+
title: "work with separateMilliseconds and formatSubMilliseconds options",
|
|
216
|
+
defaultOptions: { separateMilliseconds: true, formatSubMilliseconds: true },
|
|
217
|
+
cases: [
|
|
218
|
+
[1010.340_067, "1s 10ms 340µs 67ns"],
|
|
219
|
+
[60 * 1000 + 34 + 0.000_005, "1m 34ms 5ns"],
|
|
220
|
+
],
|
|
221
|
+
});
|
|
222
|
+
it("throw on invalid", () => {
|
|
223
|
+
expect(() => {
|
|
224
|
+
formatMilliseconds("foo");
|
|
225
|
+
}).to.throw();
|
|
226
|
+
expect(() => {
|
|
227
|
+
formatMilliseconds(Number.NaN);
|
|
228
|
+
}).to.throw();
|
|
229
|
+
expect(() => {
|
|
230
|
+
formatMilliseconds(Number.POSITIVE_INFINITY);
|
|
231
|
+
}).to.throw();
|
|
232
|
+
});
|
|
233
|
+
runTests({
|
|
234
|
+
title: "properly rounds milliseconds with secondsDecimalDigits",
|
|
235
|
+
defaultOptions: { verbose: true, secondsDecimalDigits: 0 },
|
|
236
|
+
cases: [
|
|
237
|
+
[3 * 60 * 1000, "3 minutes"],
|
|
238
|
+
[3 * 60 * 1000 - 1, "2 minutes 59 seconds"],
|
|
239
|
+
[365 * 24 * 3600 * 1e3, "1 year"],
|
|
240
|
+
[365 * 24 * 3600 * 1e3 - 1, "364 days 23 hours 59 minutes 59 seconds"],
|
|
241
|
+
[24 * 3600 * 1e3, "1 day"],
|
|
242
|
+
[24 * 3600 * 1e3 - 1, "23 hours 59 minutes 59 seconds"],
|
|
243
|
+
[3600 * 1e3, "1 hour"],
|
|
244
|
+
[3600 * 1e3 - 1, "59 minutes 59 seconds"],
|
|
245
|
+
[2 * 3600 * 1e3, "2 hours"],
|
|
246
|
+
[2 * 3600 * 1e3 - 1, "1 hour 59 minutes 59 seconds"],
|
|
247
|
+
],
|
|
248
|
+
});
|
|
249
|
+
runTests({
|
|
250
|
+
title: "`colonNotation` option",
|
|
251
|
+
defaultOptions: { colonNotation: true },
|
|
252
|
+
cases: [
|
|
253
|
+
// Default formats
|
|
254
|
+
[1000, "0:01"],
|
|
255
|
+
[1543, "0:01.5"],
|
|
256
|
+
[1000 * 60, "1:00"],
|
|
257
|
+
[1000 * 90, "1:30"],
|
|
258
|
+
[95_543, "1:35.5"],
|
|
259
|
+
[1000 * 60 * 10 + 543, "10:00.5"],
|
|
260
|
+
[1000 * 60 * 59 + 1000 * 59 + 543, "59:59.5"],
|
|
261
|
+
[1000 * 60 * 60 * 15 + 1000 * 60 * 59 + 1000 * 59 + 543, "15:59:59.5"],
|
|
262
|
+
// Together with `secondsDecimalDigits`
|
|
263
|
+
[999, { secondsDecimalDigits: 0 }, "0:00"],
|
|
264
|
+
[999, { secondsDecimalDigits: 1 }, "0:00.9"],
|
|
265
|
+
[999, { secondsDecimalDigits: 2 }, "0:00.99"],
|
|
266
|
+
[999, { secondsDecimalDigits: 3 }, "0:00.999"],
|
|
267
|
+
[1000, { secondsDecimalDigits: 0 }, "0:01"],
|
|
268
|
+
[1000, { secondsDecimalDigits: 1 }, "0:01"],
|
|
269
|
+
[1000, { secondsDecimalDigits: 2 }, "0:01"],
|
|
270
|
+
[1000, { secondsDecimalDigits: 3 }, "0:01"],
|
|
271
|
+
[1001, { secondsDecimalDigits: 0 }, "0:01"],
|
|
272
|
+
[1001, { secondsDecimalDigits: 1 }, "0:01"],
|
|
273
|
+
[1001, { secondsDecimalDigits: 2 }, "0:01"],
|
|
274
|
+
[1001, { secondsDecimalDigits: 3 }, "0:01.001"],
|
|
275
|
+
[1543, { secondsDecimalDigits: 0 }, "0:01"],
|
|
276
|
+
[1543, { secondsDecimalDigits: 1 }, "0:01.5"],
|
|
277
|
+
[1543, { secondsDecimalDigits: 2 }, "0:01.54"],
|
|
278
|
+
[1543, { secondsDecimalDigits: 3 }, "0:01.543"],
|
|
279
|
+
[95_543, { secondsDecimalDigits: 0 }, "1:35"],
|
|
280
|
+
[95_543, { secondsDecimalDigits: 1 }, "1:35.5"],
|
|
281
|
+
[95_543, { secondsDecimalDigits: 2 }, "1:35.54"],
|
|
282
|
+
[95_543, { secondsDecimalDigits: 3 }, "1:35.543"],
|
|
283
|
+
[1000 * 60 * 10 + 543, { secondsDecimalDigits: 3 }, "10:00.543"],
|
|
284
|
+
[
|
|
285
|
+
1000 * 60 * 60 * 15 + 1000 * 60 * 59 + 1000 * 59 + 543,
|
|
286
|
+
{ secondsDecimalDigits: 3 },
|
|
287
|
+
"15:59:59.543",
|
|
288
|
+
],
|
|
289
|
+
// Together with `keepDecimalsOnWholeSeconds`
|
|
290
|
+
[999, { secondsDecimalDigits: 0, keepDecimalsOnWholeSeconds: true }, "0:00"],
|
|
291
|
+
[999, { secondsDecimalDigits: 1, keepDecimalsOnWholeSeconds: true }, "0:00.9"],
|
|
292
|
+
[999, { secondsDecimalDigits: 2, keepDecimalsOnWholeSeconds: true }, "0:00.99"],
|
|
293
|
+
[999, { secondsDecimalDigits: 3, keepDecimalsOnWholeSeconds: true }, "0:00.999"],
|
|
294
|
+
[1000, { keepDecimalsOnWholeSeconds: true }, "0:01.0"],
|
|
295
|
+
[1000, { secondsDecimalDigits: 0, keepDecimalsOnWholeSeconds: true }, "0:01"],
|
|
296
|
+
[1000, { secondsDecimalDigits: 1, keepDecimalsOnWholeSeconds: true }, "0:01.0"],
|
|
297
|
+
[1000, { secondsDecimalDigits: 3, keepDecimalsOnWholeSeconds: true }, "0:01.000"],
|
|
298
|
+
[1000 * 90, { keepDecimalsOnWholeSeconds: true }, "1:30.0"],
|
|
299
|
+
[1000 * 90, { secondsDecimalDigits: 3, keepDecimalsOnWholeSeconds: true }, "1:30.000"],
|
|
300
|
+
[1000 * 60 * 10, { secondsDecimalDigits: 3, keepDecimalsOnWholeSeconds: true }, "10:00.000"],
|
|
301
|
+
// Together with `unitCount`
|
|
302
|
+
[1000 * 90, { secondsDecimalDigits: 0, unitCount: 1 }, "1"],
|
|
303
|
+
[1000 * 90, { secondsDecimalDigits: 0, unitCount: 2 }, "1:30"],
|
|
304
|
+
[1000 * 60 * 90, { secondsDecimalDigits: 0, unitCount: 3 }, "1:30:00"],
|
|
305
|
+
[95_543, { secondsDecimalDigits: 1, unitCount: 1 }, "1"],
|
|
306
|
+
[95_543, { secondsDecimalDigits: 1, unitCount: 2 }, "1:35.5"],
|
|
307
|
+
[95_543 + 1000 * 60 * 60, { secondsDecimalDigits: 1, unitCount: 3 }, "1:01:35.5"],
|
|
308
|
+
// Make sure incompatible options fall back to `colonNotation`
|
|
309
|
+
[1000 * 60 * 59 + 1000 * 59 + 543, { formatSubMilliseconds: true }, "59:59.5"],
|
|
310
|
+
[1000 * 60 * 59 + 1000 * 59 + 543, { separateMilliseconds: true }, "59:59.5"],
|
|
311
|
+
[1000 * 60 * 59 + 1000 * 59 + 543, { verbose: true }, "59:59.5"],
|
|
312
|
+
[1000 * 60 * 59 + 1000 * 59 + 543, { compact: true }, "59:59.5"],
|
|
313
|
+
// Big numbers
|
|
314
|
+
[Number.MAX_SAFE_INTEGER, "285616:151:08:59:00.9"],
|
|
315
|
+
],
|
|
316
|
+
});
|
|
317
|
+
it("Big numbers", () => {
|
|
318
|
+
expect(formatMilliseconds(Number.MAX_VALUE)).to.equal("5700447535712568547083700427941645003808085225292279557374304680873482979681895890593452082909683139015032646149857723394516742095667500822861020052921074432454921864096959420926519725467567456931340929884912090099277441972878147362726992943838905852030073647982034630974035871792165820638724934142y 218d 8h 8m 48s");
|
|
319
|
+
expect(formatMilliseconds(BigInt(Number.MAX_VALUE))).to.equal("5700447535712568836077099940756733789893155997141203595856084373514626483384973958669126034778249561502424497511237394223564222694364034207523704550467323597984839883832803211448677387442583997465622415920063861691545637902816557209722493636863373550063350653353143175061459195234630260059944318435y 207d 22h 14m 18.3s");
|
|
320
|
+
const duration = 0n +
|
|
321
|
+
// 1ms
|
|
322
|
+
1n +
|
|
323
|
+
// 2s
|
|
324
|
+
2n * 1000n +
|
|
325
|
+
// 3m
|
|
326
|
+
3n * 1000n * 60n +
|
|
327
|
+
// 4h
|
|
328
|
+
4n * 1000n * 60n * 60n +
|
|
329
|
+
// Days
|
|
330
|
+
BigInt(Number.MAX_VALUE) * 1000n * 60n * 60n * 24n;
|
|
331
|
+
expect(formatMilliseconds(duration)).to.equal("492518667085565947437061434881381799446768678152999990681965689871663728164461750029012489404840762113809476584970910860915948840793052555530048073160376758865890165963154197469165726275039257381029776735493517650149543114803350542920023450224995474725473496449711570325310074468272054469179189112833218790y 18d 4h 3m 2s");
|
|
332
|
+
expect(formatMilliseconds(duration, { colonNotation: true })).to.equal("492518667085565947437061434881381799446768678152999990681965689871663728164461750029012489404840762113809476584970910860915948840793052555530048073160376758865890165963154197469165726275039257381029776735493517650149543114803350542920023450224995474725473496449711570325310074468272054469179189112833218790:18:04:03:02");
|
|
333
|
+
});
|
|
334
|
+
it("pure", () => {
|
|
335
|
+
const runTest = (options) => {
|
|
336
|
+
const copy = { ...options };
|
|
337
|
+
formatMilliseconds(1, options);
|
|
338
|
+
expect(options).to.deep.equal(copy);
|
|
339
|
+
};
|
|
340
|
+
runTest({ colonNotation: true });
|
|
341
|
+
runTest({ compact: true });
|
|
342
|
+
});
|
|
343
|
+
//# sourceMappingURL=milliseconds.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"milliseconds.test.js","sourceRoot":"","sources":["../../source/format/milliseconds.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAC3B,OAAO,EAAE,kBAAkB,EAA6B,MAAM,mBAAmB,CAAC;AAElF,MAAM,QAAQ,GAAG,CAAC,YAAoB,EAAsB,EAAE;IAC5D,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE,CAAC;QACrC,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,YAAY,CAAC,CAAC;IAC9B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC,CAAC;AAEF,SAAS,QAAQ,CAAC,EAChB,KAAK,EACL,cAAc,EACd,KAAK,GAKN;IACC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;QACb,MAAM,MAAM,GAAG,CAAC,YAA6B,EAAE,UAAqC,EAAE,EAAE,EAAE,CACxF,kBAAkB,CAAC,YAAY,EAAE,EAAE,GAAG,cAAc,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;QAEtE,KAAK,MAAM,QAAQ,IAAI,KAAK,EAAE,CAAC;YAC7B,MAAM,CAAC,YAAY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C,KAAK,CAC3D,gUAAgU,CACjU,CAAC;IAEF,MAAM,QAAQ,GACZ,EAAE;QACF,MAAM;QACN,EAAE;QACF,KAAK;QACL,EAAE,GAAG,KAAK;QACV,KAAK;QACL,EAAE,GAAG,KAAK,GAAG,GAAG;QAChB,KAAK;QACL,EAAE,GAAG,KAAK,GAAG,GAAG,GAAG,GAAG;QACtB,OAAO;QACP,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,KAAK,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;IACrD,MAAM,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAC3C,kUAAkU,CACnU,CAAC;IACF,MAAM,CAAC,kBAAkB,CAAC,QAAQ,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CACpE,gUAAgU,CACjU,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE;IACd,MAAM,OAAO,GAAG,CAAC,OAAkC,EAAE,EAAE;QACrD,MAAM,IAAI,GAAG,EAAE,GAAG,OAAO,EAAE,CAAC;QAC5B,kBAAkB,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;QAC/B,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC,CAAC;IAEF,OAAO,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;IACjC,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;AAC7B,CAAC,CAAC,CAAC"}
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
* @param formatArguments - An array of strings to place into the placeholders.
|
|
10
10
|
* @returns The formatted string.
|
|
11
11
|
* @group Strings
|
|
12
|
+
* @group Formatting
|
|
12
13
|
*/
|
|
13
14
|
export declare const formatString: (string: string, ...formatArguments: Array<string>) => string;
|
|
14
15
|
/**
|
|
@@ -22,5 +23,6 @@ export declare const formatString: (string: string, ...formatArguments: Array<st
|
|
|
22
23
|
* @param parameters - A hash of parameters to place in the placeholders.
|
|
23
24
|
* @returns The formatted string.
|
|
24
25
|
* @group Strings
|
|
26
|
+
* @group Formatting
|
|
25
27
|
*/
|
|
26
28
|
export declare const formatStringTemplate: (string: string, parameters: Record<string, string | undefined>) => string;
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
* @param formatArguments - An array of strings to place into the placeholders.
|
|
10
10
|
* @returns The formatted string.
|
|
11
11
|
* @group Strings
|
|
12
|
+
* @group Formatting
|
|
12
13
|
*/
|
|
13
14
|
export const formatString = (string, ...formatArguments) => {
|
|
14
15
|
return string.replace(/{(\d+)}/g, (match, matchedDigits) => typeof formatArguments[matchedDigits] !== "undefined" ? formatArguments[matchedDigits] : match);
|
|
@@ -24,9 +25,10 @@ export const formatString = (string, ...formatArguments) => {
|
|
|
24
25
|
* @param parameters - A hash of parameters to place in the placeholders.
|
|
25
26
|
* @returns The formatted string.
|
|
26
27
|
* @group Strings
|
|
28
|
+
* @group Formatting
|
|
27
29
|
*/
|
|
28
30
|
export const formatStringTemplate = (string, parameters) => {
|
|
29
31
|
string = string.replace(/#{[\w.]+}/g, query => parameters[query.slice(2, query.length - 1)] ?? "<missing parameter>");
|
|
30
32
|
return string;
|
|
31
33
|
};
|
|
32
|
-
//# sourceMappingURL=string
|
|
34
|
+
//# sourceMappingURL=string.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string.js","sourceRoot":"","sources":["../../source/format/string.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,MAAc,EAAE,GAAG,eAA8B,EAAU,EAAE;IACxF,OAAO,MAAM,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,KAAK,EAAE,aAAqB,EAAU,EAAE,CACzE,OAAO,eAAe,CAAC,aAAa,CAAC,KAAK,WAAW,CAAC,CAAC,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,KAAK,CAC/F,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,MAAc,EACd,UAA8C,EACtC,EAAE;IACV,MAAM,GAAG,MAAM,CAAC,OAAO,CACrB,YAAY,EACZ,KAAK,CAAC,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,IAAI,qBAAqB,CAC/E,CAAC;IACF,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { expect } from "chai";
|
|
2
2
|
import { it } from "mocha";
|
|
3
|
-
import { formatString, formatStringTemplate } from "./string
|
|
3
|
+
import { formatString, formatStringTemplate } from "./string.js";
|
|
4
4
|
it("formats index-based template strings", () => {
|
|
5
5
|
expect(formatString("'{0}'", "foo")).to.equal("'foo'");
|
|
6
6
|
expect(formatString("'{0}': {1}", "foo", "bar")).to.equal("'foo': bar");
|
|
@@ -14,4 +14,4 @@ it("formats literal-based template strings", () => {
|
|
|
14
14
|
it("treats empty string appropriately", () => {
|
|
15
15
|
expect(formatString("'{0}'", "")).to.equal("''");
|
|
16
16
|
});
|
|
17
|
-
//# sourceMappingURL=string
|
|
17
|
+
//# sourceMappingURL=string.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string.test.js","sourceRoot":"","sources":["../../source/format/string.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAC9B,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,oBAA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ources":["../source/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../source/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC"}
|
package/package.json
CHANGED
package/string-formatter.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"string-formatter.js","sourceRoot":"","sources":["../source/string-formatter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,MAAc,EAAE,GAAG,eAA8B,EAAU,EAAE;IACxF,OAAO,MAAM,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,KAAK,EAAE,aAAqB,EAAU,EAAE,CACzE,OAAO,eAAe,CAAC,aAAa,CAAC,KAA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