@visulima/humanizer 1.2.1 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/README.md +66 -65
  2. package/dist/index.cjs +1 -14
  3. package/dist/index.mjs +1 -3
  4. package/dist/language/af.cjs +1 -45
  5. package/dist/language/af.mjs +1 -41
  6. package/dist/language/am.cjs +1 -37
  7. package/dist/language/am.mjs +1 -33
  8. package/dist/language/ar.cjs +1 -59
  9. package/dist/language/ar.mjs +1 -55
  10. package/dist/language/bg.cjs +1 -46
  11. package/dist/language/bg.mjs +1 -42
  12. package/dist/language/bn.cjs +1 -37
  13. package/dist/language/bn.mjs +1 -33
  14. package/dist/language/ca.cjs +1 -45
  15. package/dist/language/ca.mjs +1 -41
  16. package/dist/language/ckb.cjs +1 -37
  17. package/dist/language/ckb.mjs +1 -33
  18. package/dist/language/cs.cjs +1 -57
  19. package/dist/language/cs.mjs +1 -53
  20. package/dist/language/cy.cjs +1 -59
  21. package/dist/language/cy.mjs +1 -55
  22. package/dist/language/da.cjs +1 -49
  23. package/dist/language/da.mjs +1 -45
  24. package/dist/language/de.cjs +1 -51
  25. package/dist/language/de.mjs +1 -47
  26. package/dist/language/el.cjs +1 -57
  27. package/dist/language/el.mjs +1 -53
  28. package/dist/language/en.cjs +1 -62
  29. package/dist/language/en.mjs +1 -57
  30. package/dist/language/eo.cjs +1 -51
  31. package/dist/language/eo.mjs +1 -47
  32. package/dist/language/es.cjs +1 -50
  33. package/dist/language/es.mjs +1 -46
  34. package/dist/language/et.cjs +1 -51
  35. package/dist/language/et.mjs +1 -47
  36. package/dist/language/eu.cjs +1 -45
  37. package/dist/language/eu.mjs +1 -41
  38. package/dist/language/fa.cjs +1 -42
  39. package/dist/language/fa.mjs +1 -38
  40. package/dist/language/fi.cjs +1 -59
  41. package/dist/language/fi.mjs +1 -55
  42. package/dist/language/fo.cjs +1 -52
  43. package/dist/language/fo.mjs +1 -48
  44. package/dist/language/fr.cjs +1 -56
  45. package/dist/language/fr.mjs +1 -52
  46. package/dist/language/he.cjs +1 -56
  47. package/dist/language/he.mjs +1 -52
  48. package/dist/language/hi.cjs +1 -59
  49. package/dist/language/hi.mjs +1 -55
  50. package/dist/language/hr.cjs +1 -114
  51. package/dist/language/hr.mjs +1 -110
  52. package/dist/language/hu.cjs +1 -55
  53. package/dist/language/hu.mjs +1 -51
  54. package/dist/language/id.cjs +1 -54
  55. package/dist/language/id.mjs +1 -50
  56. package/dist/language/is.cjs +1 -56
  57. package/dist/language/is.mjs +1 -52
  58. package/dist/language/it.cjs +1 -55
  59. package/dist/language/it.mjs +1 -51
  60. package/dist/language/ja.cjs +1 -51
  61. package/dist/language/ja.mjs +1 -47
  62. package/dist/language/km.cjs +1 -61
  63. package/dist/language/km.mjs +1 -57
  64. package/dist/language/kn.cjs +1 -54
  65. package/dist/language/kn.mjs +1 -50
  66. package/dist/language/ko.cjs +1 -46
  67. package/dist/language/ko.mjs +1 -42
  68. package/dist/language/ku.cjs +1 -58
  69. package/dist/language/ku.mjs +1 -54
  70. package/dist/language/lo.cjs +1 -62
  71. package/dist/language/lo.mjs +1 -58
  72. package/dist/language/lt.cjs +1 -75
  73. package/dist/language/lt.mjs +1 -71
  74. package/dist/language/lv.cjs +1 -61
  75. package/dist/language/lv.mjs +1 -57
  76. package/dist/language/mk.cjs +1 -59
  77. package/dist/language/mk.mjs +1 -55
  78. package/dist/language/mn.cjs +1 -50
  79. package/dist/language/mn.mjs +1 -46
  80. package/dist/language/mr.cjs +1 -47
  81. package/dist/language/mr.mjs +1 -43
  82. package/dist/language/ms.cjs +1 -53
  83. package/dist/language/ms.mjs +1 -49
  84. package/dist/language/nl.cjs +1 -54
  85. package/dist/language/nl.mjs +1 -50
  86. package/dist/language/no.cjs +1 -51
  87. package/dist/language/no.mjs +1 -47
  88. package/dist/language/pl.cjs +1 -79
  89. package/dist/language/pl.mjs +1 -75
  90. package/dist/language/pt.cjs +1 -54
  91. package/dist/language/pt.mjs +1 -50
  92. package/dist/language/ro.cjs +1 -57
  93. package/dist/language/ro.mjs +1 -53
  94. package/dist/language/ru.cjs +1 -63
  95. package/dist/language/ru.mjs +1 -59
  96. package/dist/language/sk.cjs +1 -68
  97. package/dist/language/sk.mjs +1 -64
  98. package/dist/language/sl.cjs +1 -142
  99. package/dist/language/sl.mjs +1 -138
  100. package/dist/language/sq.cjs +1 -55
  101. package/dist/language/sq.mjs +1 -51
  102. package/dist/language/sr.cjs +1 -87
  103. package/dist/language/sr.mjs +1 -83
  104. package/dist/language/sr_Latn.cjs +1 -0
  105. package/dist/language/sr_Latn.d.cts +5 -0
  106. package/dist/language/sr_Latn.d.mts +5 -0
  107. package/dist/language/sr_Latn.d.ts +5 -0
  108. package/dist/language/sr_Latn.mjs +1 -0
  109. package/dist/language/sv.cjs +1 -53
  110. package/dist/language/sv.mjs +1 -49
  111. package/dist/language/sw.cjs +1 -55
  112. package/dist/language/sw.mjs +1 -51
  113. package/dist/language/ta.cjs +1 -58
  114. package/dist/language/ta.mjs +1 -54
  115. package/dist/language/te.cjs +1 -54
  116. package/dist/language/te.mjs +1 -50
  117. package/dist/language/th.cjs +1 -48
  118. package/dist/language/th.mjs +1 -44
  119. package/dist/language/tr.cjs +1 -46
  120. package/dist/language/tr.mjs +1 -42
  121. package/dist/language/uk.cjs +1 -65
  122. package/dist/language/uk.mjs +1 -61
  123. package/dist/language/ur.cjs +1 -61
  124. package/dist/language/ur.mjs +1 -57
  125. package/dist/language/util/create-duration-language.cjs +1 -37
  126. package/dist/language/util/create-duration-language.mjs +1 -35
  127. package/dist/language/util/duration/get-czech-or-slovak-form.cjs +1 -18
  128. package/dist/language/util/duration/get-czech-or-slovak-form.mjs +1 -16
  129. package/dist/language/util/duration/get-slavic-form.cjs +1 -21
  130. package/dist/language/util/duration/get-slavic-form.mjs +1 -19
  131. package/dist/language/util/validate-duration-language.cjs +1 -40
  132. package/dist/language/util/validate-duration-language.mjs +1 -38
  133. package/dist/language/uz.cjs +1 -47
  134. package/dist/language/uz.mjs +1 -43
  135. package/dist/language/uz_CYR.cjs +1 -47
  136. package/dist/language/uz_CYR.mjs +1 -43
  137. package/dist/language/vi.cjs +1 -38
  138. package/dist/language/vi.mjs +1 -34
  139. package/dist/language/zh_CN.cjs +1 -43
  140. package/dist/language/zh_CN.mjs +1 -39
  141. package/dist/language/zh_TW.cjs +1 -43
  142. package/dist/language/zh_TW.mjs +1 -39
  143. package/dist/packem_shared/duration-Bjh3QPn5.mjs +1 -0
  144. package/dist/packem_shared/duration-wXLHFesd.cjs +1 -0
  145. package/dist/packem_shared/formatBytes-BhZw-hyc.cjs +1 -0
  146. package/dist/packem_shared/formatBytes-Da87aeh8.mjs +1 -0
  147. package/dist/packem_shared/parseDuration-0coV5SaR.mjs +1 -0
  148. package/dist/packem_shared/parseDuration-CjkiEuTU.cjs +1 -0
  149. package/package.json +9 -9
  150. package/dist/packem_shared/duration-DYSJZCH0.cjs +0 -218
  151. package/dist/packem_shared/duration-jUX98xbn.mjs +0 -216
  152. package/dist/packem_shared/parseBytes-0lZhif0J.cjs +0 -248
  153. package/dist/packem_shared/parseBytes-CAElABGr.mjs +0 -243
  154. package/dist/packem_shared/parseDuration-Bp1J3FbZ.cjs +0 -115
  155. package/dist/packem_shared/parseDuration-N_JLGPIB.mjs +0 -113
@@ -1,243 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
- const BYTE_SIZES = {
4
- iec: [
5
- {
6
- long: "Bytes",
7
- short: "B"
8
- },
9
- {
10
- long: "Kibibytes",
11
- short: "KiB"
12
- },
13
- {
14
- long: "Mebibytes",
15
- short: "MiB"
16
- },
17
- {
18
- long: "Gibibytes",
19
- short: "GiB"
20
- },
21
- {
22
- long: "Tebibytes",
23
- short: "TiB"
24
- },
25
- {
26
- long: "Pebibytes",
27
- short: "PiB"
28
- },
29
- {
30
- long: "Exbibytes",
31
- short: "EiB"
32
- },
33
- {
34
- long: "Zebibytes",
35
- short: "ZiB"
36
- },
37
- {
38
- long: "Yobibytes",
39
- short: "YiB"
40
- }
41
- ],
42
- iec_octet: [
43
- {
44
- long: "Octets",
45
- short: "o"
46
- },
47
- {
48
- long: "Kibioctets",
49
- short: "Kio"
50
- },
51
- {
52
- long: "Mebioctets",
53
- short: "Mio"
54
- },
55
- {
56
- long: "Gibioctets",
57
- short: "Gio"
58
- },
59
- {
60
- long: "Tebioctets",
61
- short: "Tio"
62
- },
63
- {
64
- long: "Pebioctets",
65
- short: "Pio"
66
- },
67
- {
68
- long: "Exbioctets",
69
- short: "Eio"
70
- },
71
- {
72
- long: "Zebioctets",
73
- short: "Zio"
74
- },
75
- {
76
- long: "Yobioctets",
77
- short: "Yio"
78
- }
79
- ],
80
- metric: [
81
- {
82
- long: "Bytes",
83
- short: "Bytes"
84
- },
85
- {
86
- long: "Kilobytes",
87
- short: "KB"
88
- },
89
- {
90
- long: "Megabytes",
91
- short: "MB"
92
- },
93
- {
94
- long: "Gigabytes",
95
- short: "GB"
96
- },
97
- {
98
- long: "Terabytes",
99
- short: "TB"
100
- },
101
- {
102
- long: "Petabytes",
103
- short: "PB"
104
- },
105
- {
106
- long: "Exabytes",
107
- short: "EB"
108
- },
109
- {
110
- long: "Zettabytes",
111
- short: "ZB"
112
- },
113
- {
114
- long: "Yottabytes",
115
- short: "YB"
116
- }
117
- ],
118
- metric_octet: [
119
- {
120
- long: "Octets",
121
- short: "o"
122
- },
123
- {
124
- long: "Kilo-octets",
125
- short: "ko"
126
- },
127
- {
128
- long: "Mega-octets",
129
- short: "Mo"
130
- },
131
- {
132
- long: "Giga-octets",
133
- short: "Go"
134
- },
135
- {
136
- long: "Tera-octets",
137
- short: "To"
138
- },
139
- {
140
- long: "Peta-octets",
141
- short: "Po"
142
- },
143
- {
144
- long: "Exa-octets",
145
- short: "Eo"
146
- },
147
- {
148
- long: "Zetta-octets",
149
- short: "Zo"
150
- },
151
- {
152
- long: "Yotta-octets",
153
- short: "Yo"
154
- }
155
- ]
156
- };
157
- const parseLocalizedNumber = /* @__PURE__ */ __name((stringNumber, locale) => {
158
- const thousandSeparator = new Intl.NumberFormat(locale).format(11111).replaceAll(new RegExp("\\p{Number}", "gu"), "");
159
- const decimalSeparator = new Intl.NumberFormat(locale).format(1.1).replaceAll(new RegExp("\\p{Number}", "gu"), "");
160
- return Number.parseFloat(stringNumber.replaceAll(new RegExp(`\\${thousandSeparator}`, "g"), "").replace(new RegExp(`\\${decimalSeparator}`), "."));
161
- }, "parseLocalizedNumber");
162
- const fromBase = /* @__PURE__ */ __name((base) => {
163
- if (base === 2) {
164
- return 1024;
165
- }
166
- if (base === 10) {
167
- return 1e3;
168
- }
169
- throw new TypeError(`Unsupported base.`);
170
- }, "fromBase");
171
- const parseBytes = /* @__PURE__ */ __name((value, options) => {
172
- const config = {
173
- base: 2,
174
- locale: "en-US",
175
- units: "metric",
176
- ...options
177
- };
178
- if (typeof value !== "string" || value.length === 0) {
179
- throw new TypeError("Value is not a string or is empty.");
180
- }
181
- if (value.length > 100) {
182
- throw new TypeError("Value exceeds the maximum length of 100 characters.");
183
- }
184
- const match = (
185
- // eslint-disable-next-line regexp/no-super-linear-backtracking,regexp/no-unused-capturing-group,regexp/no-misleading-capturing-group,security/detect-unsafe-regex
186
- /^(?<value>-?(?:\d+(([.,])\d+)*)?[.,]?\d+) *(?<type>bytes?|b|kb|kib|mb|mib|gb|gib|tb|tib|pb|pib|eb|eib|zb|zib|yb|yib|(kilo|kibi|mega|mebi|giga|gibi|tera|tebi|peta|pebi|exa|exbi|zetta|zebi|yotta|yobi)?bytes)?$/i.exec(
187
- value
188
- )
189
- );
190
- const groups = match?.groups;
191
- if (!groups) {
192
- return Number.NaN;
193
- }
194
- const localizedNumber = parseLocalizedNumber(groups.value, config.locale);
195
- const type = (groups.type ?? "Bytes").toUpperCase().replace(/^KIBI/, "KILO").replace(/^MIBI/, "MEGA").replace(/^GIBI/, "GIGA").replace(/^TEBI/, "TERA").replace(/^PEBI/, "PETA").replace(/^EXBI/, "EXA").replace(/^ZEBI/, "ZETTA").replace(/^YIBI/, "YOTTA").replace(/^(.)IB$/, "$1B");
196
- const level = BYTE_SIZES[config.units].findIndex((unit) => unit.short[0].toUpperCase() === type[0]);
197
- const base = fromBase(config.base);
198
- return localizedNumber * base ** level;
199
- }, "parseBytes");
200
- const formatBytes = /* @__PURE__ */ __name((bytes, options) => {
201
- if (typeof bytes !== "number" || !Number.isFinite(bytes)) {
202
- throw new TypeError("Bytesize is not a number.");
203
- }
204
- const {
205
- base: givenBase,
206
- decimals,
207
- locale,
208
- long,
209
- unit: requestedUnit,
210
- units,
211
- ...l10nOptions
212
- } = {
213
- base: 2,
214
- decimals: 0,
215
- locale: "en-US",
216
- long: false,
217
- units: "metric",
218
- ...options
219
- };
220
- const base = fromBase(givenBase);
221
- const absoluteBytes = Math.abs(bytes);
222
- const space = options?.space ?? true ? " " : "";
223
- const referenceTable = BYTE_SIZES[units];
224
- const requestedUnitIndex = referenceTable.findIndex((unit2) => unit2.short === requestedUnit);
225
- if (bytes === 0) {
226
- const level2 = Math.min(0, Math.max(requestedUnitIndex, referenceTable.length - 1));
227
- return "0" + space + referenceTable[level2][long ? "long" : "short"];
228
- }
229
- const level = requestedUnitIndex >= 0 ? requestedUnitIndex : Math.min(Math.floor(Math.log(absoluteBytes) / Math.log(base)), referenceTable.length - 1);
230
- const unit = referenceTable[level][long ? "long" : "short"];
231
- const value = bytes / base ** level;
232
- const fractionDigits = decimals < 0 ? void 0 : decimals;
233
- const formattedValue = new Intl.NumberFormat(locale, {
234
- // @ts-expect-error - should be overridden by the options
235
- maximumFractionDigits: fractionDigits,
236
- // @ts-expect-error - should be overridden by the options
237
- minimumFractionDigits: fractionDigits,
238
- ...l10nOptions
239
- }).format(value);
240
- return formattedValue + space + unit;
241
- }, "formatBytes");
242
-
243
- export { formatBytes, parseBytes };
@@ -1,115 +0,0 @@
1
- 'use strict';
2
-
3
- const language_en = require('../language/en.cjs');
4
- const language_util_validateDurationLanguage = require('../language/util/validate-duration-language.cjs');
5
-
6
- var __defProp = Object.defineProperty;
7
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
- const STANDARD_UNIT_MEASURES = {
9
- d: 864e5,
10
- h: 36e5,
11
- m: 6e4,
12
- mo: 2629746e3,
13
- ms: 1,
14
- s: 1e3,
15
- w: 6048e5,
16
- y: 31556952e3
17
- };
18
- const ESCAPE_REGEX = /[-/\\^$*+?.()|[\]{}]/g;
19
- const ISO_FORMAT = /^PT(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?$/i;
20
- const COLON_FORMAT = /^(?:(\d+):)?(?:(\d+):)?(\d+)$/;
21
- const NUMERIC_STRING_REGEX = /^[+-]?\d+(?:\.\d+)?$/;
22
- const parseDuration = /* @__PURE__ */ __name((value, options) => {
23
- if (typeof value !== "string" || value.length === 0) {
24
- return void 0;
25
- }
26
- const { defaultUnit = "ms", language = language_en.durationLanguage } = options ?? {};
27
- language_util_validateDurationLanguage(language);
28
- const decimalSeparator = language.decimal ?? ".";
29
- const groupSeparator = language.groupSeparator ?? ",";
30
- const placeholderSeparator = language.placeholderSeparator ?? "_";
31
- const escapedDecimal = decimalSeparator.replaceAll(ESCAPE_REGEX, "\\$&");
32
- const escapedGroup = groupSeparator.replaceAll(ESCAPE_REGEX, "\\$&");
33
- const escapedPlaceholder = placeholderSeparator.replaceAll(ESCAPE_REGEX, "\\$&");
34
- const currentUnitMap = language.unitMap ?? language_en.englishUnitMap;
35
- let processedValue = value.replaceAll(new RegExp(`(\\d)[${escapedPlaceholder}${escapedGroup}](\\d)`, "g"), "$1$2");
36
- if (decimalSeparator !== ".") {
37
- processedValue = processedValue.replace(escapedDecimal, ".");
38
- }
39
- if (NUMERIC_STRING_REGEX.test(value)) {
40
- const numberOnly = Number.parseFloat(processedValue.trim());
41
- if (!Number.isNaN(numberOnly)) {
42
- const unitKey = currentUnitMap[defaultUnit];
43
- if (unitKey !== void 0) {
44
- return numberOnly * STANDARD_UNIT_MEASURES[unitKey];
45
- }
46
- }
47
- return void 0;
48
- }
49
- const isoMatch = ISO_FORMAT.exec(value);
50
- if (isoMatch) {
51
- const hours = Number.parseInt(isoMatch[1] ?? "0", 10);
52
- const minutes = Number.parseInt(isoMatch[2] ?? "0", 10);
53
- const seconds = Number.parseInt(isoMatch[3] ?? "0", 10);
54
- return hours * 36e5 + minutes * 6e4 + seconds * 1e3;
55
- }
56
- const colonMatch = COLON_FORMAT.exec(value);
57
- if (colonMatch) {
58
- let hours = 0;
59
- let minutes = 0;
60
- let seconds = 0;
61
- if (colonMatch[2] !== void 0) {
62
- hours = Number.parseInt(colonMatch[1] ?? "0", 10);
63
- minutes = Number.parseInt(colonMatch[2], 10);
64
- } else if (colonMatch[1] !== void 0) {
65
- minutes = Number.parseInt(colonMatch[1], 10);
66
- }
67
- seconds = Number.parseInt(colonMatch[3] ?? "0", 10);
68
- return hours * 36e5 + minutes * 6e4 + seconds * 1e3;
69
- }
70
- const currentUnitMapKeys = Object.keys(currentUnitMap);
71
- const regexKeys = currentUnitMapKeys.sort((a, b) => b.length - a.length).map((k) => k.replaceAll(ESCAPE_REGEX, "\\$&")).join("|");
72
- const durationRegex = new RegExp(`(-?\\d*\\.?\\d+)\\s*(${regexKeys})`, "gi");
73
- let totalMs = 0;
74
- let match;
75
- let unitsFound = false;
76
- let firstMatchIndex = -1;
77
- let lastMatchEndIndex = 0;
78
- durationRegex.lastIndex = 0;
79
- while ((match = durationRegex.exec(processedValue)) !== null) {
80
- if (!unitsFound) {
81
- firstMatchIndex = match.index;
82
- }
83
- unitsFound = true;
84
- const numberString = match[1];
85
- const unitString = match[2];
86
- if (!numberString || !unitString) {
87
- continue;
88
- }
89
- const trimmedNumberString = numberString.trim();
90
- const sign = trimmedNumberString.startsWith("-") ? -1 : 1;
91
- const absNumberString = trimmedNumberString.replace(/^[-+]/, "");
92
- const parsedNumber = Number.parseFloat(absNumberString);
93
- const unitKey = currentUnitMap[unitString.toLowerCase()];
94
- if (unitKey === void 0) {
95
- continue;
96
- }
97
- const unitValue = STANDARD_UNIT_MEASURES[unitKey];
98
- if (Number.isNaN(parsedNumber)) {
99
- return void 0;
100
- }
101
- totalMs += sign * parsedNumber * unitValue;
102
- lastMatchEndIndex = durationRegex.lastIndex;
103
- }
104
- const leadingText = processedValue.slice(0, firstMatchIndex).trim();
105
- const trailingText = processedValue.slice(lastMatchEndIndex).trim();
106
- if (unitsFound && (leadingText.length > 0 || trailingText.length > 0)) {
107
- return void 0;
108
- }
109
- if (!unitsFound) {
110
- return void 0;
111
- }
112
- return totalMs;
113
- }, "parseDuration");
114
-
115
- module.exports = parseDuration;
@@ -1,113 +0,0 @@
1
- import { durationLanguage, englishUnitMap } from '../language/en.mjs';
2
- import validateDurationLanguage from '../language/util/validate-duration-language.mjs';
3
-
4
- var __defProp = Object.defineProperty;
5
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
- const STANDARD_UNIT_MEASURES = {
7
- d: 864e5,
8
- h: 36e5,
9
- m: 6e4,
10
- mo: 2629746e3,
11
- ms: 1,
12
- s: 1e3,
13
- w: 6048e5,
14
- y: 31556952e3
15
- };
16
- const ESCAPE_REGEX = /[-/\\^$*+?.()|[\]{}]/g;
17
- const ISO_FORMAT = /^PT(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?$/i;
18
- const COLON_FORMAT = /^(?:(\d+):)?(?:(\d+):)?(\d+)$/;
19
- const NUMERIC_STRING_REGEX = /^[+-]?\d+(?:\.\d+)?$/;
20
- const parseDuration = /* @__PURE__ */ __name((value, options) => {
21
- if (typeof value !== "string" || value.length === 0) {
22
- return void 0;
23
- }
24
- const { defaultUnit = "ms", language = durationLanguage } = options ?? {};
25
- validateDurationLanguage(language);
26
- const decimalSeparator = language.decimal ?? ".";
27
- const groupSeparator = language.groupSeparator ?? ",";
28
- const placeholderSeparator = language.placeholderSeparator ?? "_";
29
- const escapedDecimal = decimalSeparator.replaceAll(ESCAPE_REGEX, "\\$&");
30
- const escapedGroup = groupSeparator.replaceAll(ESCAPE_REGEX, "\\$&");
31
- const escapedPlaceholder = placeholderSeparator.replaceAll(ESCAPE_REGEX, "\\$&");
32
- const currentUnitMap = language.unitMap ?? englishUnitMap;
33
- let processedValue = value.replaceAll(new RegExp(`(\\d)[${escapedPlaceholder}${escapedGroup}](\\d)`, "g"), "$1$2");
34
- if (decimalSeparator !== ".") {
35
- processedValue = processedValue.replace(escapedDecimal, ".");
36
- }
37
- if (NUMERIC_STRING_REGEX.test(value)) {
38
- const numberOnly = Number.parseFloat(processedValue.trim());
39
- if (!Number.isNaN(numberOnly)) {
40
- const unitKey = currentUnitMap[defaultUnit];
41
- if (unitKey !== void 0) {
42
- return numberOnly * STANDARD_UNIT_MEASURES[unitKey];
43
- }
44
- }
45
- return void 0;
46
- }
47
- const isoMatch = ISO_FORMAT.exec(value);
48
- if (isoMatch) {
49
- const hours = Number.parseInt(isoMatch[1] ?? "0", 10);
50
- const minutes = Number.parseInt(isoMatch[2] ?? "0", 10);
51
- const seconds = Number.parseInt(isoMatch[3] ?? "0", 10);
52
- return hours * 36e5 + minutes * 6e4 + seconds * 1e3;
53
- }
54
- const colonMatch = COLON_FORMAT.exec(value);
55
- if (colonMatch) {
56
- let hours = 0;
57
- let minutes = 0;
58
- let seconds = 0;
59
- if (colonMatch[2] !== void 0) {
60
- hours = Number.parseInt(colonMatch[1] ?? "0", 10);
61
- minutes = Number.parseInt(colonMatch[2], 10);
62
- } else if (colonMatch[1] !== void 0) {
63
- minutes = Number.parseInt(colonMatch[1], 10);
64
- }
65
- seconds = Number.parseInt(colonMatch[3] ?? "0", 10);
66
- return hours * 36e5 + minutes * 6e4 + seconds * 1e3;
67
- }
68
- const currentUnitMapKeys = Object.keys(currentUnitMap);
69
- const regexKeys = currentUnitMapKeys.sort((a, b) => b.length - a.length).map((k) => k.replaceAll(ESCAPE_REGEX, "\\$&")).join("|");
70
- const durationRegex = new RegExp(`(-?\\d*\\.?\\d+)\\s*(${regexKeys})`, "gi");
71
- let totalMs = 0;
72
- let match;
73
- let unitsFound = false;
74
- let firstMatchIndex = -1;
75
- let lastMatchEndIndex = 0;
76
- durationRegex.lastIndex = 0;
77
- while ((match = durationRegex.exec(processedValue)) !== null) {
78
- if (!unitsFound) {
79
- firstMatchIndex = match.index;
80
- }
81
- unitsFound = true;
82
- const numberString = match[1];
83
- const unitString = match[2];
84
- if (!numberString || !unitString) {
85
- continue;
86
- }
87
- const trimmedNumberString = numberString.trim();
88
- const sign = trimmedNumberString.startsWith("-") ? -1 : 1;
89
- const absNumberString = trimmedNumberString.replace(/^[-+]/, "");
90
- const parsedNumber = Number.parseFloat(absNumberString);
91
- const unitKey = currentUnitMap[unitString.toLowerCase()];
92
- if (unitKey === void 0) {
93
- continue;
94
- }
95
- const unitValue = STANDARD_UNIT_MEASURES[unitKey];
96
- if (Number.isNaN(parsedNumber)) {
97
- return void 0;
98
- }
99
- totalMs += sign * parsedNumber * unitValue;
100
- lastMatchEndIndex = durationRegex.lastIndex;
101
- }
102
- const leadingText = processedValue.slice(0, firstMatchIndex).trim();
103
- const trailingText = processedValue.slice(lastMatchEndIndex).trim();
104
- if (unitsFound && (leadingText.length > 0 || trailingText.length > 0)) {
105
- return void 0;
106
- }
107
- if (!unitsFound) {
108
- return void 0;
109
- }
110
- return totalMs;
111
- }, "parseDuration");
112
-
113
- export { parseDuration as default };