@wener/common 2.0.5 → 2.0.6
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/ai/qwen3vl/index.js +1 -1
- package/lib/ai/qwen3vl/utils.js +15 -15
- package/lib/ai/vision/DocLayoutElementTypeSchema.js +22 -22
- package/lib/ai/vision/ImageAnnotationSchema.js +63 -47
- package/lib/ai/vision/index.js +2 -2
- package/lib/ai/vision/resolveImageAnnotation.js +81 -95
- package/lib/cn/ChineseResidentIdNo.js +55 -41
- package/lib/cn/ChineseResidentIdNo.mod.js +6 -1
- package/lib/cn/ChineseResidentIdNo.test.js +22 -21
- package/lib/cn/DivisionCode.js +220 -235
- package/lib/cn/DivisionCode.mod.js +6 -1
- package/lib/cn/DivisionCode.test.js +92 -121
- package/lib/cn/Mod11.js +18 -37
- package/lib/cn/Mod31.js +23 -41
- package/lib/cn/UnifiedSocialCreditCode.js +143 -137
- package/lib/cn/UnifiedSocialCreditCode.mod.js +6 -1
- package/lib/cn/UnifiedSocialCreditCode.test.js +21 -15
- package/lib/cn/formatChineseAmount.js +46 -71
- package/lib/cn/index.js +6 -6
- package/lib/cn/mod.js +5 -3
- package/lib/cn/parseChineseNumber.js +81 -85
- package/lib/cn/parseChineseNumber.test.js +183 -261
- package/lib/cn/pinyin/cartesianProduct.js +19 -19
- package/lib/cn/pinyin/cartesianProduct.test.js +78 -178
- package/lib/cn/pinyin/loader.js +13 -11
- package/lib/cn/pinyin/preload.js +2 -1
- package/lib/cn/pinyin/toPinyin.test.js +149 -161
- package/lib/cn/pinyin/toPinyinPure.js +28 -23
- package/lib/cn/pinyin/transform.js +11 -11
- package/lib/cn/types.d.js +2 -2
- package/lib/consola/createStandardConsolaReporter.js +14 -15
- package/lib/consola/formatLogObject.js +149 -133
- package/lib/consola/formatLogObject.test.js +167 -178
- package/lib/consola/index.js +2 -2
- package/lib/data/formatSort.js +14 -12
- package/lib/data/formatSort.test.js +33 -33
- package/lib/data/index.js +3 -3
- package/lib/data/maybeNumber.js +23 -23
- package/lib/data/parseSort.js +75 -68
- package/lib/data/parseSort.test.js +196 -187
- package/lib/data/resolvePagination.js +38 -39
- package/lib/data/resolvePagination.test.js +228 -218
- package/lib/data/types.d.js +2 -2
- package/lib/dayjs/dayjs.js +20 -20
- package/lib/dayjs/formatDuration.js +56 -56
- package/lib/dayjs/formatDuration.test.js +63 -77
- package/lib/dayjs/index.js +4 -4
- package/lib/dayjs/parseDuration.js +21 -26
- package/lib/dayjs/parseRelativeTime.js +65 -66
- package/lib/dayjs/parseRelativeTime.test.js +227 -243
- package/lib/dayjs/resolveRelativeTime.js +73 -72
- package/lib/dayjs/resolveRelativeTime.test.js +296 -307
- package/lib/decimal/index.js +1 -1
- package/lib/decimal/parseDecimal.js +12 -12
- package/lib/drain3/Drain.js +303 -338
- package/lib/drain3/LogCluster.js +25 -25
- package/lib/drain3/Node.js +24 -24
- package/lib/drain3/TemplateMiner.js +197 -196
- package/lib/drain3/index.js +5 -5
- package/lib/drain3/persistence/FilePersistence.js +19 -19
- package/lib/drain3/persistence/MemoryPersistence.js +8 -8
- package/lib/drain3/persistence/PersistenceHandler.js +2 -2
- package/lib/drain3/types.js +2 -2
- package/lib/emittery/emitter.js +7 -7
- package/lib/emittery/index.js +1 -1
- package/lib/foundation/schema/SexType.js +15 -12
- package/lib/foundation/schema/index.js +1 -1
- package/lib/foundation/schema/parseSexType.js +15 -16
- package/lib/foundation/schema/types.js +8 -6
- package/lib/fs/FileSystemError.js +18 -18
- package/lib/fs/IFileSystem.d.js +2 -2
- package/lib/fs/MemoryFileSystem.test.js +172 -181
- package/lib/fs/createBrowserFileSystem.js +222 -235
- package/lib/fs/createMemoryFileSystem.js +472 -510
- package/lib/fs/createSandboxFileSystem.js +102 -101
- package/lib/fs/createWebDavFileSystem.js +162 -149
- package/lib/fs/createWebFileSystem.js +197 -220
- package/lib/fs/findMimeType.js +14 -14
- package/lib/fs/index.js +7 -7
- package/lib/fs/minio/createMinioFileSystem.js +959 -956
- package/lib/fs/minio/index.js +1 -1
- package/lib/fs/orpc/FileSystemContract.js +57 -57
- package/lib/fs/orpc/createContractClientFileSystem.js +88 -88
- package/lib/fs/orpc/index.js +2 -2
- package/lib/fs/orpc/server/createFileSystemContractImpl.js +62 -60
- package/lib/fs/orpc/server/index.js +1 -1
- package/lib/fs/s3/createS3MiniFileSystem.js +756 -737
- package/lib/fs/s3/index.js +1 -1
- package/lib/fs/s3/s3mini.test.js +524 -553
- package/lib/fs/scandir.js +56 -56
- package/lib/fs/server/createDatabaseFileSystem.js +834 -741
- package/lib/fs/server/createNodeFileSystem.js +407 -405
- package/lib/fs/server/dbfs.test.js +201 -214
- package/lib/fs/server/index.js +1 -1
- package/lib/fs/server/loadTestDatabase.js +40 -43
- package/lib/fs/tests/runFileSystemTest.js +352 -316
- package/lib/fs/types.js +17 -20
- package/lib/fs/utils/getFileUrl.js +24 -30
- package/lib/fs/utils.js +17 -17
- package/lib/fs/webdav/index.js +1 -1
- package/lib/index.js +2 -2
- package/lib/jsonschema/JsonSchema.js +216 -155
- package/lib/jsonschema/JsonSchema.test.js +123 -124
- package/lib/jsonschema/forEachJsonSchema.js +41 -41
- package/lib/jsonschema/index.js +2 -2
- package/lib/jsonschema/types.d.js +2 -2
- package/lib/meta/defineFileType.js +32 -38
- package/lib/meta/defineInit.js +39 -35
- package/lib/meta/defineMetadata.js +37 -34
- package/lib/meta/defineMetadata.test.js +13 -12
- package/lib/meta/index.js +3 -3
- package/lib/orpc/createOpenApiContractClient.js +26 -24
- package/lib/orpc/createRpcContractClient.js +37 -31
- package/lib/orpc/index.js +2 -2
- package/lib/orpc/resolveLinkPlugins.js +25 -25
- package/lib/password/PHC.js +187 -189
- package/lib/password/PHC.test.js +517 -535
- package/lib/password/Password.js +85 -80
- package/lib/password/Password.test.js +330 -364
- package/lib/password/createArgon2PasswordAlgorithm.js +50 -51
- package/lib/password/createBase64PasswordAlgorithm.js +11 -11
- package/lib/password/createBcryptPasswordAlgorithm.js +20 -18
- package/lib/password/createPBKDF2PasswordAlgorithm.js +65 -52
- package/lib/password/createScryptPasswordAlgorithm.js +74 -63
- package/lib/password/index.js +5 -5
- package/lib/password/server/index.js +1 -1
- package/lib/resource/Identifiable.js +2 -2
- package/lib/resource/ListQuery.js +42 -42
- package/lib/resource/getTitleOfResource.js +5 -5
- package/lib/resource/index.js +2 -2
- package/lib/resource/schema/AnyResourceSchema.js +91 -89
- package/lib/resource/schema/BaseResourceSchema.js +26 -26
- package/lib/resource/schema/ResourceActionType.js +117 -115
- package/lib/resource/schema/ResourceStatus.js +94 -92
- package/lib/resource/schema/ResourceType.js +25 -23
- package/lib/resource/schema/index.js +5 -5
- package/lib/resource/schema/types.js +86 -55
- package/lib/resource/schema/types.test.js +16 -13
- package/lib/s3/formatS3Url.js +60 -60
- package/lib/s3/formatS3Url.test.js +238 -261
- package/lib/s3/index.js +2 -2
- package/lib/s3/parseS3Url.js +61 -60
- package/lib/s3/parseS3Url.test.js +270 -269
- package/lib/schema/SchemaRegistry.js +41 -42
- package/lib/schema/SchemaRegistry.mod.js +1 -1
- package/lib/schema/TypeSchema.d.js +2 -2
- package/lib/schema/createSchemaData.js +113 -67
- package/lib/schema/findJsonSchemaByPath.js +28 -23
- package/lib/schema/formatZodError.js +112 -131
- package/lib/schema/formatZodError.test.js +192 -195
- package/lib/schema/getSchemaCache.js +7 -7
- package/lib/schema/getSchemaOptions.js +17 -16
- package/lib/schema/index.js +6 -6
- package/lib/schema/toJsonSchema.js +195 -189
- package/lib/schema/toJsonSchema.test.js +34 -26
- package/lib/schema/validate.js +105 -96
- package/lib/tools/generateSchema.js +40 -40
- package/lib/tools/renderJsonSchemaToMarkdownDoc.js +74 -74
- package/lib/utils/buildBaseUrl.js +8 -8
- package/lib/utils/buildRedactorFormSchema.js +54 -53
- package/lib/utils/getEstimateProcessTime.js +24 -19
- package/lib/utils/index.js +3 -3
- package/lib/utils/resolveFeatureOptions.js +9 -9
- package/package.json +14 -14
- package/src/ai/vision/index.ts +2 -2
- package/src/cn/index.ts +1 -2
- package/src/consola/index.ts +1 -1
- package/src/data/index.ts +3 -4
- package/src/data/resolvePagination.ts +2 -2
- package/src/dayjs/formatDuration.ts +8 -9
- package/src/dayjs/index.ts +1 -1
- package/src/dayjs/parseRelativeTime.ts +1 -1
- package/src/dayjs/resolveRelativeTime.ts +1 -1
- package/src/drain3/Drain.test.ts +2 -2
- package/src/drain3/index.ts +2 -4
- package/src/fs/createWebDavFileSystem.ts +2 -7
- package/src/fs/createWebFileSystem.ts +1 -1
- package/src/fs/index.ts +4 -4
- package/src/fs/minio/createMinioFileSystem.ts +2 -2
- package/src/fs/minio/index.ts +1 -1
- package/src/fs/s3/createS3MiniFileSystem.ts +1 -1
- package/src/fs/server/createDatabaseFileSystem.ts +84 -120
- package/src/fs/server/dbfs.test.ts +14 -10
- package/src/fs/server/index.ts +1 -0
- package/src/fs/server/loadTestDatabase.ts +8 -119
- package/src/jsonschema/index.ts +1 -1
- package/src/meta/index.ts +2 -3
- package/src/orm/createSqliteDialect.ts +17 -0
- package/src/orm/index.ts +1 -0
- package/src/orpc/createOpenApiContractClient.ts +1 -1
- package/src/orpc/index.ts +1 -1
- package/src/password/createArgon2PasswordAlgorithm.ts +1 -1
- package/src/password/index.ts +2 -2
- package/src/resource/index.ts +3 -3
- package/src/resource/schema/index.ts +4 -4
- package/src/s3/index.ts +1 -1
- package/src/schema/SchemaRegistry.ts +1 -1
- package/src/schema/createSchemaData.ts +1 -1
- package/src/schema/findJsonSchemaByPath.ts +1 -1
- package/src/schema/index.ts +5 -5
- package/src/schema/validate.ts +1 -1
- package/src/utils/buildRedactorFormSchema.ts +1 -1
- package/src/utils/formatNumber.ts +18 -0
- package/src/utils/formatPercent.ts +17 -0
- package/src/utils/index.ts +3 -3
- package/src/utils/resolveFeatureOptions.ts +1 -1
|
@@ -1,90 +1,76 @@
|
|
|
1
1
|
function _array_like_to_array(arr, len) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
arr2[i] = arr[i];
|
|
6
|
-
return arr2;
|
|
2
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
3
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
4
|
+
return arr2;
|
|
7
5
|
}
|
|
8
6
|
function _array_with_holes(arr) {
|
|
9
|
-
|
|
10
|
-
return arr;
|
|
7
|
+
if (Array.isArray(arr)) return arr;
|
|
11
8
|
}
|
|
12
9
|
function _iterable_to_array_limit(arr, i) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
finally {
|
|
37
|
-
if (_d)
|
|
38
|
-
throw _e;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return _arr;
|
|
10
|
+
var _i = arr == null ? null : (typeof Symbol !== 'undefined' && arr[Symbol.iterator]) || arr['@@iterator'];
|
|
11
|
+
if (_i == null) return;
|
|
12
|
+
var _arr = [];
|
|
13
|
+
var _n = true;
|
|
14
|
+
var _d = false;
|
|
15
|
+
var _s, _e;
|
|
16
|
+
try {
|
|
17
|
+
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
|
|
18
|
+
_arr.push(_s.value);
|
|
19
|
+
if (i && _arr.length === i) break;
|
|
20
|
+
}
|
|
21
|
+
} catch (err) {
|
|
22
|
+
_d = true;
|
|
23
|
+
_e = err;
|
|
24
|
+
} finally {
|
|
25
|
+
try {
|
|
26
|
+
if (!_n && _i['return'] != null) _i['return']();
|
|
27
|
+
} finally {
|
|
28
|
+
if (_d) throw _e;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return _arr;
|
|
42
32
|
}
|
|
43
33
|
function _non_iterable_rest() {
|
|
44
|
-
|
|
34
|
+
throw new TypeError(
|
|
35
|
+
'Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.',
|
|
36
|
+
);
|
|
45
37
|
}
|
|
46
38
|
function _sliced_to_array(arr, i) {
|
|
47
|
-
|
|
39
|
+
return (
|
|
40
|
+
_array_with_holes(arr) ||
|
|
41
|
+
_iterable_to_array_limit(arr, i) ||
|
|
42
|
+
_unsupported_iterable_to_array(arr, i) ||
|
|
43
|
+
_non_iterable_rest()
|
|
44
|
+
);
|
|
48
45
|
}
|
|
49
46
|
function _unsupported_iterable_to_array(o, minLen) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
n = o.constructor.name;
|
|
57
|
-
if (n === "Map" || n === "Set")
|
|
58
|
-
return Array.from(n);
|
|
59
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
|
|
60
|
-
return _array_like_to_array(o, minLen);
|
|
47
|
+
if (!o) return;
|
|
48
|
+
if (typeof o === 'string') return _array_like_to_array(o, minLen);
|
|
49
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
50
|
+
if (n === 'Object' && o.constructor) n = o.constructor.name;
|
|
51
|
+
if (n === 'Map' || n === 'Set') return Array.from(n);
|
|
52
|
+
if (n === 'Arguments' || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
61
53
|
}
|
|
62
|
-
|
|
63
|
-
import {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
"1m1s1ms"
|
|
85
|
-
]
|
|
86
|
-
]; _i < _iter.length; _i++) {
|
|
87
|
-
var _iter__i = _sliced_to_array(_iter[_i], 2), a = _iter__i[0], b = _iter__i[1];
|
|
88
|
-
expect(formatDuration(a)).toBe(b);
|
|
89
|
-
}
|
|
54
|
+
|
|
55
|
+
import { expect, test } from 'vitest';
|
|
56
|
+
import { formatDuration } from './formatDuration.js';
|
|
57
|
+
|
|
58
|
+
test('formatDuration', () => {
|
|
59
|
+
for (
|
|
60
|
+
var _i = 0,
|
|
61
|
+
_iter = [
|
|
62
|
+
[0, '0ms'],
|
|
63
|
+
[1000, '1s'],
|
|
64
|
+
[1000 * 60, '1m'],
|
|
65
|
+
[1000 * 60 + 1000, '1m1s'],
|
|
66
|
+
[1000 * 60 + 1000 + 1, '1m1s1ms'],
|
|
67
|
+
];
|
|
68
|
+
_i < _iter.length;
|
|
69
|
+
_i++
|
|
70
|
+
) {
|
|
71
|
+
var _iter__i = _sliced_to_array(_iter[_i], 2),
|
|
72
|
+
a = _iter__i[0],
|
|
73
|
+
b = _iter__i[1];
|
|
74
|
+
expect(formatDuration(a)).toBe(b);
|
|
75
|
+
}
|
|
90
76
|
});
|
package/lib/dayjs/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { dayjs } from
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export { resolveRelativeTime } from
|
|
1
|
+
export { dayjs } from './dayjs.js';
|
|
2
|
+
export { formatDuration } from './formatDuration.js';
|
|
3
|
+
export { parseDuration } from './parseDuration.js';
|
|
4
|
+
export { resolveRelativeTime } from './resolveRelativeTime.js';
|
|
5
5
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,29 +1,24 @@
|
|
|
1
|
-
import { dayjs } from
|
|
1
|
+
import { dayjs } from './dayjs.js';
|
|
2
2
|
export function parseDuration(value) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
else {
|
|
24
|
-
console.warn(`Invalid duration value:`, value);
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
return duration;
|
|
3
|
+
if (!value && value !== 0) {
|
|
4
|
+
return;
|
|
5
|
+
}
|
|
6
|
+
let duration;
|
|
7
|
+
if (typeof value === 'number') {
|
|
8
|
+
duration = dayjs.duration(value);
|
|
9
|
+
} else if (typeof value === 'string' && value.startsWith('P')) {
|
|
10
|
+
// PT0S
|
|
11
|
+
duration = dayjs.duration(value);
|
|
12
|
+
} else if (typeof value === 'object' && 'value' in value) {
|
|
13
|
+
duration = dayjs.duration(value.value, value.unit);
|
|
14
|
+
} else if (dayjs.isDuration(value)) {
|
|
15
|
+
duration = value;
|
|
16
|
+
} else if (typeof value === 'object') {
|
|
17
|
+
duration = dayjs.duration(value);
|
|
18
|
+
} else {
|
|
19
|
+
console.warn(`Invalid duration value:`, value);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
return duration;
|
|
28
23
|
}
|
|
29
24
|
//# sourceMappingURL=parseDuration.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import dayjs from
|
|
2
|
-
import { checkDurationUnit, RelativeDurationUnits } from
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
import { checkDurationUnit, RelativeDurationUnits } from './resolveRelativeTime.js';
|
|
3
3
|
/**
|
|
4
4
|
* Parses a relative time string and returns an array of operations.
|
|
5
5
|
*
|
|
@@ -17,74 +17,73 @@ import { checkDurationUnit, RelativeDurationUnits } from "./resolveRelativeTime.
|
|
|
17
17
|
* parseRelativeTime('now+500ms') // [{ operator: '+', duration: dayjs.duration(500, 'ms') }]
|
|
18
18
|
* ```
|
|
19
19
|
*/ export function parseRelativeTime(s) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return operations;
|
|
20
|
+
if (typeof s !== 'string' || !s.startsWith('now')) {
|
|
21
|
+
throw new Error(`Invalid relative time format: ${s}`);
|
|
22
|
+
}
|
|
23
|
+
const remaining = s.slice(3); // Remove 'now'
|
|
24
|
+
if (!remaining) {
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
const operations = [];
|
|
28
|
+
// Single regex to match all operations: <op><duration_spec> or <op><unit>
|
|
29
|
+
// Where duration_spec can be: 1h, 1d6h, 500ms, etc.
|
|
30
|
+
const operationRegex = /([+\-/\\])([^+\-/\\]+)/g;
|
|
31
|
+
let match;
|
|
32
|
+
let lastIndex = 0;
|
|
33
|
+
while ((match = operationRegex.exec(remaining)) !== null) {
|
|
34
|
+
const [, operator, operand] = match;
|
|
35
|
+
if (operator === '/' || operator === '\\') {
|
|
36
|
+
// Truncation operation - single unit only
|
|
37
|
+
checkDurationUnit(operand.trim());
|
|
38
|
+
operations.push({
|
|
39
|
+
operator: operator,
|
|
40
|
+
unit: operand.trim(),
|
|
41
|
+
});
|
|
42
|
+
} else {
|
|
43
|
+
// Addition or subtraction operation - parse complex duration
|
|
44
|
+
const parsedDuration = parseDurationSpec(operand.trim());
|
|
45
|
+
operations.push({
|
|
46
|
+
operator: operator,
|
|
47
|
+
duration: parsedDuration,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
lastIndex = operationRegex.lastIndex;
|
|
51
|
+
}
|
|
52
|
+
// Check if we parsed the entire remaining string
|
|
53
|
+
if (lastIndex < remaining.length) {
|
|
54
|
+
throw new Error(`Invalid relative time format: ${s}`);
|
|
55
|
+
}
|
|
56
|
+
return operations;
|
|
58
57
|
}
|
|
59
58
|
/**
|
|
60
59
|
* Parses a duration specification like "1h", "1d6h", "500ms" into a dayjs Duration.
|
|
61
60
|
* Supports multiple units in a single specification.
|
|
62
61
|
*/ function parseDurationSpec(spec) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
62
|
+
// Match all number+unit pairs: 1d, 6h, 30m, 500ms, etc.
|
|
63
|
+
const durationRegex = /(\d+)(ms|[smhdwMQy])/g;
|
|
64
|
+
const durationObj = {};
|
|
65
|
+
let match;
|
|
66
|
+
let hasMatch = false;
|
|
67
|
+
while ((match = durationRegex.exec(spec)) !== null) {
|
|
68
|
+
const [, amountStr, unit] = match;
|
|
69
|
+
checkDurationUnit(unit);
|
|
70
|
+
const amount = parseInt(amountStr, 10);
|
|
71
|
+
// Dayjs duration supports unit strings directly
|
|
72
|
+
durationObj[unit] = (durationObj[unit] || 0) + amount;
|
|
73
|
+
hasMatch = true;
|
|
74
|
+
}
|
|
75
|
+
if (!hasMatch) {
|
|
76
|
+
// Check if there are invalid units by looking for number+invalid_unit patterns
|
|
77
|
+
const invalidUnitRegex = /\d+([a-zA-Z]+)/g;
|
|
78
|
+
let invalidMatch;
|
|
79
|
+
while ((invalidMatch = invalidUnitRegex.exec(spec)) !== null) {
|
|
80
|
+
const [, unit] = invalidMatch;
|
|
81
|
+
if (!RelativeDurationUnits.includes(unit)) {
|
|
82
|
+
throw new Error(`Invalid unit: ${unit}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
throw new Error(`Invalid duration specification: ${spec}`);
|
|
86
|
+
}
|
|
87
|
+
return dayjs.duration(durationObj);
|
|
89
88
|
}
|
|
90
89
|
//# sourceMappingURL=parseRelativeTime.js.map
|