@openclaw/qqbot 2026.7.1-beta.6 → 2026.7.2-beta.1

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.
Files changed (41) hide show
  1. package/dist/api.js +8 -7
  2. package/dist/{channel-D1UztsnG.js → channel-BbwpkiY3.js} +99 -54
  3. package/dist/{channel-entry-C5YdhX3Y.js → channel-entry-Cj1lWXpt.js} +4 -4
  4. package/dist/channel-entry-api.js +1 -1
  5. package/dist/channel-plugin-api.js +1 -1
  6. package/dist/{channel.setup-2ItDYKhz.js → channel.setup-DfhritPL.js} +1 -1
  7. package/dist/{config-C1qZbh0K.js → config-CpOXnoEc.js} +2 -2
  8. package/dist/{config-schema-JZEf1dvB.js → config-schema-B5Mle_87.js} +38 -47
  9. package/dist/doctor-contract-api.js +1 -1
  10. package/dist/{gateway-pJQppxe4.js → gateway-be5-Ckdc.js} +284 -174
  11. package/dist/{group-o0GmovSf.js → group-Dbpnjalm.js} +19 -17
  12. package/dist/{handler-runtime-zQvT6SrI.js → handler-runtime-BvR-ayNW.js} +8 -12
  13. package/dist/{log-DEtcoDWe.js → log-Da4jz75I.js} +4 -8
  14. package/dist/{outbound-BIrfvvFJ.js → outbound-BLl8Tsu7.js} +8 -142
  15. package/dist/{runtime-DodcT_fQ.js → runtime-Du28LbOJ.js} +2 -2
  16. package/dist/runtime-api.js +1 -1
  17. package/dist/secret-contract-api.js +6 -22
  18. package/dist/{sender-CjDuU-uz.js → sender-0vqsivoI.js} +220 -66
  19. package/dist/setup-plugin-api.js +1 -1
  20. package/dist/state-keys-jLJ2SmJA.js +225 -0
  21. package/dist/{tools-UJJ-tLHP.js → tools-DYb23LBU.js} +48 -6
  22. package/dist/tools-api.js +1 -1
  23. package/node_modules/p-map/index.d.ts +155 -0
  24. package/node_modules/p-map/index.js +284 -0
  25. package/node_modules/p-map/license +9 -0
  26. package/node_modules/p-map/package.json +57 -0
  27. package/node_modules/p-map/readme.md +190 -0
  28. package/node_modules/parse-ms/index.d.ts +30 -0
  29. package/node_modules/parse-ms/index.js +45 -0
  30. package/node_modules/parse-ms/license +9 -0
  31. package/node_modules/parse-ms/package.json +47 -0
  32. package/node_modules/parse-ms/readme.md +46 -0
  33. package/node_modules/pretty-ms/index.d.ts +157 -0
  34. package/node_modules/pretty-ms/index.js +149 -0
  35. package/node_modules/pretty-ms/license +9 -0
  36. package/node_modules/pretty-ms/package.json +55 -0
  37. package/node_modules/pretty-ms/readme.md +179 -0
  38. package/npm-shrinkwrap.json +44 -3
  39. package/openclaw.plugin.json +61 -89
  40. package/package.json +8 -4
  41. package/dist/state-keys-CQKlAFyo.js +0 -141
@@ -0,0 +1,190 @@
1
+ # p-map
2
+
3
+ > Map over promises concurrently
4
+
5
+ Useful when you need to run promise-returning & async functions multiple times with different inputs concurrently.
6
+
7
+ This is different from `Promise.all()` in that you can control the concurrency and also decide whether or not to stop iterating when there's an error.
8
+
9
+ ## Install
10
+
11
+ ```sh
12
+ npm install p-map
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```js
18
+ import pMap from 'p-map';
19
+ import got from 'got';
20
+
21
+ const sites = [
22
+ getWebsiteFromUsername('sindresorhus'), //=> Promise
23
+ 'https://avajs.dev',
24
+ 'https://github.com'
25
+ ];
26
+
27
+ const mapper = async site => {
28
+ const {requestUrl} = await got.head(site);
29
+ return requestUrl;
30
+ };
31
+
32
+ const result = await pMap(sites, mapper, {concurrency: 2});
33
+
34
+ console.log(result);
35
+ //=> ['https://sindresorhus.com/', 'https://avajs.dev/', 'https://github.com/']
36
+ ```
37
+
38
+ ## API
39
+
40
+ ### pMap(input, mapper, options?)
41
+
42
+ Returns a `Promise` that is fulfilled when all promises in `input` and the ones returned from `mapper` are fulfilled, or rejects if any of the promises reject. The fulfilled value is an `Array` of the fulfilled values returned from `mapper` in `input` order.
43
+
44
+ ### pMapIterable(input, mapper, options?)
45
+
46
+ Returns an async iterable that streams each return value from `mapper` in order.
47
+
48
+ ```js
49
+ import {pMapIterable} from 'p-map';
50
+
51
+ // Multiple posts are fetched concurrently, with limited concurrency and backpressure
52
+ for await (const post of pMapIterable(postIds, getPostMetadata, {concurrency: 8})) {
53
+ console.log(post);
54
+ };
55
+ ```
56
+
57
+ #### input
58
+
59
+ Type: `AsyncIterable<Promise<unknown> | unknown> | Iterable<Promise<unknown> | unknown>`
60
+
61
+ Synchronous or asynchronous iterable that is iterated over concurrently, calling the `mapper` function for each element. Each iterated item is `await`'d before the `mapper` is invoked so the iterable may return a `Promise` that resolves to an item.
62
+
63
+ Asynchronous iterables (different from synchronous iterables that return `Promise` that resolves to an item) can be used when the next item may not be ready without waiting for an asynchronous process to complete and/or the end of the iterable may be reached after the asynchronous process completes. For example, reading from a remote queue when the queue has reached empty, or reading lines from a stream.
64
+
65
+ #### mapper(element, index)
66
+
67
+ Type: `Function`
68
+
69
+ Expected to return a `Promise` or value.
70
+
71
+ #### options
72
+
73
+ Type: `object`
74
+
75
+ ##### concurrency
76
+
77
+ Type: `number` *(Integer)*\
78
+ Default: `Infinity`\
79
+ Minimum: `1`
80
+
81
+ Number of concurrently pending promises returned by `mapper`.
82
+
83
+ ##### backpressure
84
+
85
+ **Only for `pMapIterable`**
86
+
87
+ Type: `number` *(Integer)*\
88
+ Default: `options.concurrency`\
89
+ Minimum: `options.concurrency`
90
+
91
+ Maximum number of promises returned by `mapper` that have resolved but not yet collected by the consumer of the async iterable. Calls to `mapper` will be limited so that there is never too much backpressure.
92
+
93
+ Useful whenever you are consuming the iterable slower than what the mapper function can produce concurrently. For example, to avoid making an overwhelming number of HTTP requests if you are saving each of the results to a database.
94
+
95
+ ##### stopOnError
96
+
97
+ **Only for `pMap`**
98
+
99
+ Type: `boolean`\
100
+ Default: `true`
101
+
102
+ When `true`, the first mapper rejection will be rejected back to the consumer.
103
+
104
+ When `false`, instead of stopping when a promise rejects, it will wait for all the promises to settle and then reject with an [`AggregateError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError) containing all the errors from the rejected promises.
105
+
106
+ Caveat: When `true`, any already-started async mappers will continue to run until they resolve or reject. In the case of infinite concurrency with sync iterables, *all* mappers are invoked on startup and will continue after the first rejection. Use the `signal` option for abort control.
107
+
108
+ ##### signal
109
+
110
+ **Only for `pMap`**
111
+
112
+ Type: [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)
113
+
114
+ You can abort the promises using [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).
115
+
116
+ ```js
117
+ import pMap from 'p-map';
118
+ import delay from 'delay';
119
+
120
+ const abortController = new AbortController();
121
+
122
+ setTimeout(() => {
123
+ abortController.abort();
124
+ }, 500);
125
+
126
+ const mapper = async value => value;
127
+
128
+ await pMap([delay(1000), delay(1000)], mapper, {signal: abortController.signal});
129
+ // Throws AbortError (DOMException) after 500 ms.
130
+ ```
131
+
132
+ ### pMapSkip
133
+
134
+ Return this value from a `mapper` function to skip including the value in the returned array.
135
+
136
+ ```js
137
+ import pMap, {pMapSkip} from 'p-map';
138
+ import got from 'got';
139
+
140
+ const sites = [
141
+ getWebsiteFromUsername('sindresorhus'), //=> Promise
142
+ 'https://avajs.dev',
143
+ 'https://example.invalid',
144
+ 'https://github.com'
145
+ ];
146
+
147
+ const mapper = async site => {
148
+ try {
149
+ const {requestUrl} = await got.head(site);
150
+ return requestUrl;
151
+ } catch {
152
+ return pMapSkip;
153
+ }
154
+ };
155
+
156
+ const result = await pMap(sites, mapper, {concurrency: 2});
157
+
158
+ console.log(result);
159
+ //=> ['https://sindresorhus.com/', 'https://avajs.dev/', 'https://github.com/']
160
+ ```
161
+
162
+ ## Recipes
163
+
164
+ ### Rate limiting
165
+
166
+ This package controls how many mapper promises run concurrently. To limit how often the mapper starts, compose it with a rate limiter like [`p-throttle`](https://github.com/sindresorhus/p-throttle):
167
+
168
+ ```js
169
+ import pThrottle from 'p-throttle';
170
+ import pMap from 'p-map';
171
+
172
+ const throttle = pThrottle({
173
+ limit: 1,
174
+ interval: 1000,
175
+ strict: true,
176
+ });
177
+
178
+ const result = await pMap(input, throttle(mapper), {concurrency: 2});
179
+ ```
180
+
181
+ For more advanced scheduling, use [`p-queue`](https://github.com/sindresorhus/p-queue).
182
+
183
+ ## Related
184
+
185
+ - [p-all](https://github.com/sindresorhus/p-all) - Run promise-returning & async functions concurrently with optional limited concurrency
186
+ - [p-filter](https://github.com/sindresorhus/p-filter) - Filter promises concurrently
187
+ - [p-times](https://github.com/sindresorhus/p-times) - Run promise-returning & async functions a specific number of times concurrently
188
+ - [p-props](https://github.com/sindresorhus/p-props) - Like `Promise.all()` but for `Map` and `Object`
189
+ - [p-map-series](https://github.com/sindresorhus/p-map-series) - Map over promises serially
190
+ - [More…](https://github.com/sindresorhus/promise-fun)
@@ -0,0 +1,30 @@
1
+ export type TimeComponents<T extends (number | bigint) = number> = {
2
+ days: T;
3
+ hours: T;
4
+ minutes: T;
5
+ seconds: T;
6
+ milliseconds: T;
7
+ microseconds: T;
8
+ nanoseconds: T;
9
+ };
10
+
11
+ /**
12
+ Parse milliseconds into an object.
13
+
14
+ @example
15
+ ```
16
+ import parseMilliseconds from 'parse-ms';
17
+
18
+ parseMilliseconds(1337000001);
19
+ // {
20
+ // days: 15,
21
+ // hours: 11,
22
+ // minutes: 23,
23
+ // seconds: 20,
24
+ // milliseconds: 1,
25
+ // microseconds: 0,
26
+ // nanoseconds: 0
27
+ // }
28
+ ```
29
+ */
30
+ export default function parseMilliseconds<T extends number | bigint>(milliseconds: T): TimeComponents<T>;
@@ -0,0 +1,45 @@
1
+ const toZeroIfInfinity = value => Number.isFinite(value) ? value : 0;
2
+
3
+ function parseNumber(milliseconds) {
4
+ return {
5
+ days: Math.trunc(milliseconds / 86_400_000),
6
+ hours: Math.trunc(milliseconds / 3_600_000 % 24),
7
+ minutes: Math.trunc(milliseconds / 60_000 % 60),
8
+ seconds: Math.trunc(milliseconds / 1000 % 60),
9
+ milliseconds: Math.trunc(milliseconds % 1000),
10
+ microseconds: Math.trunc(toZeroIfInfinity(milliseconds * 1000) % 1000),
11
+ nanoseconds: Math.trunc(toZeroIfInfinity(milliseconds * 1e6) % 1000),
12
+ };
13
+ }
14
+
15
+ function parseBigint(milliseconds) {
16
+ return {
17
+ days: milliseconds / 86_400_000n,
18
+ hours: milliseconds / 3_600_000n % 24n,
19
+ minutes: milliseconds / 60_000n % 60n,
20
+ seconds: milliseconds / 1000n % 60n,
21
+ milliseconds: milliseconds % 1000n,
22
+ microseconds: 0n,
23
+ nanoseconds: 0n,
24
+ };
25
+ }
26
+
27
+ export default function parseMilliseconds(milliseconds) {
28
+ switch (typeof milliseconds) {
29
+ case 'number': {
30
+ if (Number.isFinite(milliseconds)) {
31
+ return parseNumber(milliseconds);
32
+ }
33
+
34
+ break;
35
+ }
36
+
37
+ case 'bigint': {
38
+ return parseBigint(milliseconds);
39
+ }
40
+
41
+ // No default
42
+ }
43
+
44
+ throw new TypeError('Expected a finite number or bigint');
45
+ }
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
4
+
5
+ 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:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ 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.
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "parse-ms",
3
+ "version": "4.0.0",
4
+ "description": "Parse milliseconds into an object",
5
+ "license": "MIT",
6
+ "repository": "sindresorhus/parse-ms",
7
+ "funding": "https://github.com/sponsors/sindresorhus",
8
+ "author": {
9
+ "name": "Sindre Sorhus",
10
+ "email": "sindresorhus@gmail.com",
11
+ "url": "https://sindresorhus.com"
12
+ },
13
+ "type": "module",
14
+ "exports": {
15
+ "types": "./index.d.ts",
16
+ "default": "./index.js"
17
+ },
18
+ "sideEffects": false,
19
+ "engines": {
20
+ "node": ">=18"
21
+ },
22
+ "scripts": {
23
+ "test": "xo && ava && tsd"
24
+ },
25
+ "files": [
26
+ "index.js",
27
+ "index.d.ts"
28
+ ],
29
+ "keywords": [
30
+ "browser",
31
+ "parse",
32
+ "time",
33
+ "ms",
34
+ "milliseconds",
35
+ "microseconds",
36
+ "nanoseconds",
37
+ "duration",
38
+ "period",
39
+ "range",
40
+ "interval"
41
+ ],
42
+ "devDependencies": {
43
+ "ava": "^6.0.1",
44
+ "tsd": "^0.30.3",
45
+ "xo": "^0.56.0"
46
+ }
47
+ }
@@ -0,0 +1,46 @@
1
+ # parse-ms
2
+
3
+ > Parse milliseconds into an object
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install parse-ms
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```js
14
+ import parseMilliseconds from 'parse-ms';
15
+
16
+ parseMilliseconds(1337000001);
17
+ /*
18
+ {
19
+ days: 15,
20
+ hours: 11,
21
+ minutes: 23,
22
+ seconds: 20,
23
+ milliseconds: 1,
24
+ microseconds: 0,
25
+ nanoseconds: 0
26
+ }
27
+ */
28
+
29
+ parseMilliseconds(1337000001n);
30
+ /*
31
+ {
32
+ days: 15n,
33
+ hours: 11n,
34
+ minutes: 23n,
35
+ seconds: 20n,
36
+ milliseconds: 1n,
37
+ microseconds: 0n,
38
+ nanoseconds: 0n
39
+ }
40
+ */
41
+ ```
42
+
43
+ ## Related
44
+
45
+ - [to-milliseconds](https://github.com/sindresorhus/to-milliseconds) - The inverse of this module
46
+ - [pretty-ms](https://github.com/sindresorhus/pretty-ms) - Convert milliseconds to a human readable string
@@ -0,0 +1,157 @@
1
+ export type Options = {
2
+ /**
3
+ Number of digits to appear after the seconds decimal point.
4
+
5
+ @default 1
6
+ */
7
+ readonly secondsDecimalDigits?: number;
8
+
9
+ /**
10
+ Number of digits to appear after the milliseconds decimal point.
11
+
12
+ Useful in combination with [`process.hrtime()`](https://nodejs.org/api/process.html#process_process_hrtime).
13
+
14
+ @default 0
15
+ */
16
+ readonly millisecondsDecimalDigits?: number;
17
+
18
+ /**
19
+ Keep milliseconds on whole seconds: `13s` → `13.0s`.
20
+
21
+ 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.
22
+
23
+ @default false
24
+ */
25
+ readonly keepDecimalsOnWholeSeconds?: boolean;
26
+
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
+ @default false
33
+ */
34
+ readonly compact?: boolean;
35
+
36
+ /**
37
+ Number of units to show. Setting `compact` to `true` overrides this option.
38
+
39
+ @default Infinity
40
+ */
41
+ readonly unitCount?: number;
42
+
43
+ /**
44
+ Use full-length units: `5h 1m 45s` → `5 hours 1 minute 45 seconds`.
45
+
46
+ @default false
47
+ */
48
+ readonly verbose?: boolean;
49
+
50
+ /**
51
+ Show milliseconds separately. This means they won't be included in the decimal part of the seconds.
52
+
53
+ @default false
54
+ */
55
+ readonly separateMilliseconds?: boolean;
56
+
57
+ /**
58
+ Show microseconds and nanoseconds.
59
+
60
+ @default false
61
+ */
62
+ readonly formatSubMilliseconds?: boolean;
63
+
64
+ /**
65
+ Display time using colon notation: `5h 1m 45s` → `5:01:45`. Always shows time in at least minutes: `1s` → `0:01`
66
+
67
+ Useful when you want to display time without the time units, similar to a digital watch.
68
+
69
+ Setting `colonNotation` to `true` overrides the following options to `false`:
70
+ - `compact`
71
+ - `formatSubMilliseconds`
72
+ - `separateMilliseconds`
73
+ - `verbose`
74
+
75
+ @default false
76
+ */
77
+ readonly colonNotation?: boolean;
78
+
79
+ /**
80
+ Hides the year and shows the hidden year additionally as days (365 per year): `1y 3d 5h 1m 45s` → `368d 5h 1m 45s`.
81
+
82
+ @default false
83
+ */
84
+ readonly hideYear?: boolean;
85
+
86
+ /**
87
+ Hides the year and days and shows the hidden values additionally as hours: `1y 3d 5h 1m 45s` → `8837h 1m 45s`.
88
+
89
+ @default false
90
+ */
91
+ readonly hideYearAndDays?: boolean;
92
+
93
+ /**
94
+ Hides the seconds: `1y 3d 5h 1m 45s` → `1y 3d 5h 1m`.
95
+
96
+ @default false
97
+ */
98
+ readonly hideSeconds?: boolean;
99
+
100
+ /**
101
+ Show sub-second values as decimal seconds: `900ms` → `0.9s`.
102
+
103
+ Useful for progress indicators where you want consistent unit format to prevent flickering.
104
+
105
+ @default false
106
+ */
107
+ readonly subSecondsAsDecimals?: boolean;
108
+ };
109
+
110
+ /**
111
+ Convert milliseconds to a human readable string: `1337000000` → `15d 11h 23m 20s`.
112
+
113
+ @param milliseconds - Milliseconds to humanize.
114
+
115
+ @example
116
+ ```
117
+ import prettyMilliseconds from 'pretty-ms';
118
+
119
+ prettyMilliseconds(1337000000);
120
+ //=> '15d 11h 23m 20s'
121
+
122
+ prettyMilliseconds(1337);
123
+ //=> '1.3s'
124
+
125
+ prettyMilliseconds(133);
126
+ //=> '133ms'
127
+
128
+ // `compact` option
129
+ prettyMilliseconds(1337, {compact: true});
130
+ //=> '1s'
131
+
132
+ // `verbose` option
133
+ prettyMilliseconds(1335669000, {verbose: true});
134
+ //=> '15 days 11 hours 1 minute 9 seconds'
135
+
136
+ // `colonNotation` option
137
+ prettyMilliseconds(95500, {colonNotation: true});
138
+ //=> '1:35.5'
139
+
140
+ // `formatSubMilliseconds` option
141
+ prettyMilliseconds(100.400080, {formatSubMilliseconds: true})
142
+ //=> '100ms 400µs 80ns'
143
+
144
+ // `subSecondsAsDecimals` option
145
+ prettyMilliseconds(900, {subSecondsAsDecimals: true});
146
+ //=> '0.9s'
147
+
148
+ // Can be useful for time durations
149
+ prettyMilliseconds(new Date(2014, 0, 1, 10, 40) - new Date(2014, 0, 1, 10, 5))
150
+ //=> '35m'
151
+ ```
152
+ */
153
+ export default function prettyMilliseconds(
154
+ milliseconds: number | bigint,
155
+ options?: Options
156
+ ): string;
157
+
@@ -0,0 +1,149 @@
1
+ import parseMilliseconds from 'parse-ms';
2
+
3
+ const isZero = value => value === 0 || value === 0n;
4
+ const pluralize = (word, count) => (count === 1 || count === 1n) ? word : `${word}s`;
5
+
6
+ const SECOND_ROUNDING_EPSILON = 0.000_000_1;
7
+ const ONE_DAY_IN_MILLISECONDS = 24n * 60n * 60n * 1000n;
8
+
9
+ export default function prettyMilliseconds(milliseconds, options) {
10
+ const isBigInt = typeof milliseconds === 'bigint';
11
+ if (!isBigInt && !Number.isFinite(milliseconds)) {
12
+ throw new TypeError('Expected a finite number or bigint');
13
+ }
14
+
15
+ options = {...options};
16
+
17
+ const sign = milliseconds < 0 ? '-' : '';
18
+ milliseconds = milliseconds < 0 ? -milliseconds : milliseconds; // Cannot use `Math.abs()` because of BigInt support.
19
+
20
+ if (options.colonNotation) {
21
+ options.compact = false;
22
+ options.formatSubMilliseconds = false;
23
+ options.separateMilliseconds = false;
24
+ options.verbose = false;
25
+ }
26
+
27
+ if (options.compact) {
28
+ options.unitCount = 1;
29
+ options.secondsDecimalDigits = 0;
30
+ options.millisecondsDecimalDigits = 0;
31
+ }
32
+
33
+ let result = [];
34
+
35
+ const floorDecimals = (value, decimalDigits) => {
36
+ const flooredInterimValue = Math.floor((value * (10 ** decimalDigits)) + SECOND_ROUNDING_EPSILON);
37
+ const flooredValue = Math.round(flooredInterimValue) / (10 ** decimalDigits);
38
+ return flooredValue.toFixed(decimalDigits);
39
+ };
40
+
41
+ const add = (value, long, short, valueString) => {
42
+ if (
43
+ (result.length === 0 || !options.colonNotation)
44
+ && isZero(value)
45
+ && !(options.colonNotation && short === 'm')) {
46
+ return;
47
+ }
48
+
49
+ valueString ??= String(value);
50
+ if (options.colonNotation) {
51
+ const wholeDigits = valueString.includes('.') ? valueString.split('.')[0].length : valueString.length;
52
+ const minLength = result.length > 0 ? 2 : 1;
53
+ valueString = '0'.repeat(Math.max(0, minLength - wholeDigits)) + valueString;
54
+ } else {
55
+ valueString += options.verbose ? ' ' + pluralize(long, value) : short;
56
+ }
57
+
58
+ result.push(valueString);
59
+ };
60
+
61
+ const parsed = parseMilliseconds(milliseconds);
62
+ const days = BigInt(parsed.days);
63
+
64
+ if (options.hideYearAndDays) {
65
+ add((BigInt(days) * 24n) + BigInt(parsed.hours), 'hour', 'h');
66
+ } else {
67
+ if (options.hideYear) {
68
+ add(days, 'day', 'd');
69
+ } else {
70
+ add(days / 365n, 'year', 'y');
71
+ add(days % 365n, 'day', 'd');
72
+ }
73
+
74
+ add(Number(parsed.hours), 'hour', 'h');
75
+ }
76
+
77
+ add(Number(parsed.minutes), 'minute', 'm');
78
+
79
+ if (!options.hideSeconds) {
80
+ if (
81
+ options.separateMilliseconds
82
+ || options.formatSubMilliseconds
83
+ || (!options.colonNotation && milliseconds < 1000 && !options.subSecondsAsDecimals)
84
+ ) {
85
+ const seconds = Number(parsed.seconds);
86
+ const milliseconds = Number(parsed.milliseconds);
87
+ const microseconds = Number(parsed.microseconds);
88
+ const nanoseconds = Number(parsed.nanoseconds);
89
+
90
+ add(seconds, 'second', 's');
91
+
92
+ if (options.formatSubMilliseconds) {
93
+ add(milliseconds, 'millisecond', 'ms');
94
+ add(microseconds, 'microsecond', 'µs');
95
+ add(nanoseconds, 'nanosecond', 'ns');
96
+ } else {
97
+ const millisecondsAndBelow
98
+ = milliseconds
99
+ + (microseconds / 1000)
100
+ + (nanoseconds / 1e6);
101
+
102
+ const millisecondsDecimalDigits
103
+ = typeof options.millisecondsDecimalDigits === 'number'
104
+ ? options.millisecondsDecimalDigits
105
+ : 0;
106
+
107
+ const roundedMilliseconds = millisecondsAndBelow >= 1
108
+ ? Math.round(millisecondsAndBelow)
109
+ : Math.ceil(millisecondsAndBelow);
110
+
111
+ const millisecondsString = millisecondsDecimalDigits
112
+ ? millisecondsAndBelow.toFixed(millisecondsDecimalDigits)
113
+ : roundedMilliseconds;
114
+
115
+ add(
116
+ Number.parseFloat(millisecondsString),
117
+ 'millisecond',
118
+ 'ms',
119
+ millisecondsString,
120
+ );
121
+ }
122
+ } else {
123
+ const seconds = (
124
+ (isBigInt ? Number(milliseconds % ONE_DAY_IN_MILLISECONDS) : milliseconds)
125
+ / 1000
126
+ ) % 60;
127
+ const secondsDecimalDigits
128
+ = typeof options.secondsDecimalDigits === 'number'
129
+ ? options.secondsDecimalDigits
130
+ : 1;
131
+ const secondsFixed = floorDecimals(seconds, secondsDecimalDigits);
132
+ const secondsString = options.keepDecimalsOnWholeSeconds
133
+ ? secondsFixed
134
+ : secondsFixed.replace(/\.0+$/, '');
135
+ add(Number.parseFloat(secondsString), 'second', 's', secondsString);
136
+ }
137
+ }
138
+
139
+ if (result.length === 0) {
140
+ return sign + '0' + (options.verbose ? ' milliseconds' : 'ms');
141
+ }
142
+
143
+ const separator = options.colonNotation ? ':' : ' ';
144
+ if (typeof options.unitCount === 'number') {
145
+ result = result.slice(0, Math.max(options.unitCount, 1));
146
+ }
147
+
148
+ return sign + result.join(separator);
149
+ }
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
4
+
5
+ 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:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ 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.