@sodiumlabs/ms 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 sodiumlabs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,127 @@
1
+ <div align="center">
2
+ <h1>@sodiumlabs/ms</h1>
3
+ <p>
4
+ <a href="https://discord.gg/8PDXWSHH7k"><img src="https://img.shields.io/badge/join_us-on_discord-5865F2?logo=discord&logoColor=white" alt="Discord server" /></a>
5
+ <a href="https://www.npmjs.com/package/@sodiumlabs/ms"><img src="https://img.shields.io/npm/v/@sodiumlabs/ms.svg?maxAge=3600" alt="npm version" /></a>
6
+ <a href="https://www.npmjs.com/package/@sodiumlabs/ms"><img src="https://img.shields.io/npm/dt/@sodiumlabs/ms.svg?maxAge=3600" alt="npm downloads" /></a>
7
+ <a href="https://github.com/sodium-labs/utilities/commits/main/packages/ms"><img alt="Last commit" src="https://img.shields.io/github/last-commit/sodium-labs/utilities?logo=github&logoColor=ffffff&path=packages%2Fms" /></a>
8
+ </p>
9
+ </div>
10
+
11
+ ## About
12
+
13
+ Use this package to easily convert various time formats to milliseconds.
14
+
15
+ This package is an enhanced version of [vercel/ms](https://github.com/vercel/ms), with added localization support. With `@sodiumlabs/ms`, you can use multiple units at the same time (e.g. `ms("2h30m45s")`) and define localized units in any language you need.
16
+
17
+ By default, the following locales are supported: `en`, `fr`, `de`, `es`.
18
+
19
+ ## Installation
20
+
21
+ Node.js 18 or newer is required.
22
+
23
+ ```sh
24
+ npm install @sodiumlabs/ms
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ ```ts
30
+ ms("2 days"); // 172800000
31
+ ms("1d"); // 86400000
32
+ ms("10h"); // 36000000
33
+ ms("2.5 hrs"); // 9000000
34
+ ms("2h"); // 7200000
35
+ ms("1m"); // 60000
36
+ ms("5s"); // 5000
37
+ ```
38
+
39
+ Convert from Milliseconds
40
+
41
+ ```ts
42
+ ms(60000); // "1m"
43
+ ms(2 * 60000); // "2m"
44
+ ms(-3 * 60000); // "-3m"
45
+ ms(ms("10 hours")); // "10h"
46
+ ```
47
+
48
+ Time Format Written-Out
49
+
50
+ ```ts
51
+ ms(60000, { long: true }); // "1 minute"
52
+ ms(2 * 60000, { long: true }); // "2 minutes"
53
+ ms(-3 * 60000, { long: true }); // "-3 minutes"
54
+ ms(ms("10 hours"), { long: true }); // "10 hours"
55
+ ```
56
+
57
+ Compound Format
58
+
59
+ ```ts
60
+ const duration = ms("1min 5s 2ms");
61
+
62
+ ms(duration); // "1m"
63
+ ms(duration, { compound: true }); // "1m5s2ms"
64
+ ms(duration, { compound: true, maxUnits: 2 }); // "1m5s"
65
+ ms(duration, { long: true, compound: true }); // "1 minute 5 seconds 2 milliseconds"
66
+ ```
67
+
68
+ Specific Methods
69
+
70
+ ```ts
71
+ // If you only want to parse, you can use
72
+ parse("2min");
73
+
74
+ // If you only want to format, you can use
75
+ format(120000);
76
+ ```
77
+
78
+ Use another locale
79
+
80
+ ```ts
81
+ ms("2h", { locale: "fr", long: true }); // "2 heures"
82
+ ```
83
+
84
+ Add a locale
85
+
86
+ ```ts
87
+ import { setLocale } from "@sodiumlabs/ms";
88
+
89
+ // Add the `it` locale
90
+ setLocale("it", {
91
+ units: {
92
+ second: {
93
+ short: "s",
94
+ long: c => (c > 1 ? "secondi" : "secondo"),
95
+ names: ["secondi", "secondo", "secs", "sec", "s"],
96
+ },
97
+ minute: {
98
+ short: "m",
99
+ long: c => (c > 1 ? "minuti" : "minuto"),
100
+ names: ["minuti", "minuto", "mins", "min", "m"],
101
+ },
102
+ hour: {
103
+ short: "h",
104
+ long: c => (c > 1 ? "ore" : "ora"),
105
+ names: ["ore", "ora", "h"],
106
+ },
107
+ day: {
108
+ short: "g",
109
+ long: c => (c > 1 ? "giorni" : "giorno"),
110
+ names: ["giorni", "giorno", "g"],
111
+ },
112
+ /// etc.
113
+ },
114
+ });
115
+ ```
116
+
117
+ ## Links
118
+
119
+ - [Documentation](https://docs.sodiumlabs.xyz/docs/packages/ms/stable)
120
+ - [Discord server](https://discord.gg/8PDXWSHH7k)
121
+ - [GitHub](https://github.com/sodium-labs/utilities/tree/main/packages/ms)
122
+ - [npm](https://npmjs.com/package/@sodiumlabs/ms)
123
+ - [Sodium Labs](https://sodiumlabs.xyz)
124
+
125
+ ## Help
126
+
127
+ Need help with the module? Ask on our [support server!](https://discord.gg/8PDXWSHH7k)
@@ -0,0 +1,41 @@
1
+ /**
2
+ * The options.
3
+ */
4
+ interface Options {
5
+ /**
6
+ * Set to `true` to use verbose formatting. Defaults to `false`.
7
+ */
8
+ long?: boolean;
9
+ /**
10
+ * The locale. Defaults to `en`.
11
+ */
12
+ locale?: string;
13
+ compound?: boolean;
14
+ maxUnits?: number;
15
+ }
16
+ /**
17
+ * Parse or format the given value.
18
+ *
19
+ * @param value - The string or number to convert
20
+ * @param options - Options for the conversion
21
+ * @throws Error if `value` is not a non-empty string or a number
22
+ */
23
+ declare function ms(value: string, options?: Options): number;
24
+ declare function ms(value: number, options?: Options): string;
25
+ /**
26
+ * Parse the given string and return milliseconds.
27
+ *
28
+ * @param str - A string to parse into milliseconds. Length must be in [1;100]
29
+ * @returns The parsed value in milliseconds, or `NaN` if the string can't be parsed
30
+ */
31
+ declare function parse(str: string, options?: Options): number;
32
+ /**
33
+ * Format the given integer as a string.
34
+ *
35
+ * @param ms - milliseconds
36
+ * @param options - Options for the conversion
37
+ * @returns The formatted string
38
+ */
39
+ declare function format(ms: number, options?: Options): string;
40
+
41
+ export { type Options, format, ms, parse };
@@ -0,0 +1,41 @@
1
+ /**
2
+ * The options.
3
+ */
4
+ interface Options {
5
+ /**
6
+ * Set to `true` to use verbose formatting. Defaults to `false`.
7
+ */
8
+ long?: boolean;
9
+ /**
10
+ * The locale. Defaults to `en`.
11
+ */
12
+ locale?: string;
13
+ compound?: boolean;
14
+ maxUnits?: number;
15
+ }
16
+ /**
17
+ * Parse or format the given value.
18
+ *
19
+ * @param value - The string or number to convert
20
+ * @param options - Options for the conversion
21
+ * @throws Error if `value` is not a non-empty string or a number
22
+ */
23
+ declare function ms(value: string, options?: Options): number;
24
+ declare function ms(value: number, options?: Options): string;
25
+ /**
26
+ * Parse the given string and return milliseconds.
27
+ *
28
+ * @param str - A string to parse into milliseconds. Length must be in [1;100]
29
+ * @returns The parsed value in milliseconds, or `NaN` if the string can't be parsed
30
+ */
31
+ declare function parse(str: string, options?: Options): number;
32
+ /**
33
+ * Format the given integer as a string.
34
+ *
35
+ * @param ms - milliseconds
36
+ * @param options - Options for the conversion
37
+ * @returns The formatted string
38
+ */
39
+ declare function format(ms: number, options?: Options): string;
40
+
41
+ export { type Options, format, ms, parse };
package/dist/index.js ADDED
@@ -0,0 +1,342 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/index.ts
22
+ var index_exports = {};
23
+ __export(index_exports, {
24
+ format: () => format,
25
+ ms: () => ms,
26
+ parse: () => parse
27
+ });
28
+ module.exports = __toCommonJS(index_exports);
29
+
30
+ // src/locales.ts
31
+ var locales = /* @__PURE__ */ new Map();
32
+ var setLocale = /* @__PURE__ */ __name((locale, definition) => {
33
+ const mappedUnits = /* @__PURE__ */ new Map();
34
+ for (const [unit, def] of Object.entries(definition.units)) {
35
+ for (const name of def.names) {
36
+ mappedUnits.set(name.toLowerCase(), unit);
37
+ }
38
+ }
39
+ locales.set(locale, {
40
+ ...definition,
41
+ mappedUnits
42
+ });
43
+ }, "setLocale");
44
+ var defaultLocales = {
45
+ en: {
46
+ units: {
47
+ millisecond: {
48
+ short: "ms",
49
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "milliseconds" : "millisecond", "long"),
50
+ names: ["milliseconds", "millisecond", "msecs", "msec", "ms"]
51
+ },
52
+ second: {
53
+ short: "s",
54
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "seconds" : "second", "long"),
55
+ names: ["seconds", "second", "secs", "sec", "s"]
56
+ },
57
+ minute: {
58
+ short: "m",
59
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "minutes" : "minute", "long"),
60
+ names: ["minutes", "minute", "mins", "min", "m"]
61
+ },
62
+ hour: {
63
+ short: "h",
64
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "hours" : "hour", "long"),
65
+ names: ["hours", "hour", "hrs", "hr", "h"]
66
+ },
67
+ day: {
68
+ short: "d",
69
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "days" : "day", "long"),
70
+ names: ["days", "day", "d"]
71
+ },
72
+ week: {
73
+ short: "w",
74
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "weeks" : "week", "long"),
75
+ names: ["weeks", "week", "w"]
76
+ },
77
+ month: {
78
+ short: "mo",
79
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "months" : "month", "long"),
80
+ names: ["months", "month", "mo"]
81
+ },
82
+ year: {
83
+ short: "y",
84
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "years" : "year", "long"),
85
+ names: ["years", "year", "yrs", "yr", "y"]
86
+ }
87
+ }
88
+ },
89
+ fr: {
90
+ units: {
91
+ millisecond: {
92
+ short: "ms",
93
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "millisecondes" : "milliseconde", "long"),
94
+ names: ["millisecondes", "milliseconde", "ms"]
95
+ },
96
+ second: {
97
+ short: "s",
98
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "secondes" : "seconde", "long"),
99
+ names: ["secondes", "seconde", "secs", "sec", "s"]
100
+ },
101
+ minute: {
102
+ short: "m",
103
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "minutes" : "minute", "long"),
104
+ names: ["minutes", "minute", "mins", "min", "m"]
105
+ },
106
+ hour: {
107
+ short: "h",
108
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "heures" : "heure", "long"),
109
+ names: ["heures", "heure", "h"]
110
+ },
111
+ day: {
112
+ short: "j",
113
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "jours" : "jour", "long"),
114
+ names: ["jours", "jour", "j"]
115
+ },
116
+ week: {
117
+ short: "sem",
118
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "semaines" : "semaine", "long"),
119
+ names: ["semaines", "semaine", "sem"]
120
+ },
121
+ month: {
122
+ short: "mo",
123
+ long: /* @__PURE__ */ __name((_) => "mois", "long"),
124
+ names: ["mois", "mo"]
125
+ },
126
+ year: {
127
+ short: "an",
128
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "ann\xE9es" : "ann\xE9e", "long"),
129
+ names: ["ann\xE9es", "annees", "ann\xE9e", "annee", "ans", "an"]
130
+ }
131
+ }
132
+ },
133
+ de: {
134
+ units: {
135
+ millisecond: {
136
+ short: "ms",
137
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "Millisekunden" : "Millisekunde", "long"),
138
+ names: ["millisekunden", "millisekunde", "ms"]
139
+ },
140
+ second: {
141
+ short: "s",
142
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "Sekunden" : "Sekunde", "long"),
143
+ names: ["sekunden", "sekunde", "seks", "sek", "s"]
144
+ },
145
+ minute: {
146
+ short: "m",
147
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "Minuten" : "Minute", "long"),
148
+ names: ["minuten", "minute", "mins", "min", "m"]
149
+ },
150
+ hour: {
151
+ short: "h",
152
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "Stunden" : "Stunde", "long"),
153
+ names: ["stunden", "stunde", "hrs", "hr", "h"]
154
+ },
155
+ day: {
156
+ short: "t",
157
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "Tage" : "Tag", "long"),
158
+ names: ["tage", "tag", "t", "d"]
159
+ },
160
+ week: {
161
+ short: "w",
162
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "Wochen" : "Woche", "long"),
163
+ names: ["wochen", "woche", "wo", "w"]
164
+ },
165
+ month: {
166
+ short: "mo",
167
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "Monate" : "Monat", "long"),
168
+ names: ["monate", "monat", "mon", "mo"]
169
+ },
170
+ year: {
171
+ short: "j",
172
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "Jahre" : "Jahr", "long"),
173
+ names: ["jahre", "jahr", "j", "y"]
174
+ }
175
+ }
176
+ },
177
+ es: {
178
+ units: {
179
+ millisecond: {
180
+ short: "ms",
181
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "milisegundos" : "milisegundo", "long"),
182
+ names: ["milisegundos", "milisegundo", "ms"]
183
+ },
184
+ second: {
185
+ short: "s",
186
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "segundos" : "segundo", "long"),
187
+ names: ["segundos", "segundo", "s"]
188
+ },
189
+ minute: {
190
+ short: "min",
191
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "minutos" : "minuto", "long"),
192
+ names: ["minutos", "minuto", "mins", "min", "m"]
193
+ },
194
+ hour: {
195
+ short: "h",
196
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "horas" : "hora", "long"),
197
+ names: ["horas", "hora", "hrs", "hr", "h"]
198
+ },
199
+ day: {
200
+ short: "d",
201
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "d\xEDas" : "d\xEDa", "long"),
202
+ names: ["d\xEDas", "dias", "d\xEDa", "dia", "d"]
203
+ },
204
+ week: {
205
+ short: "sem",
206
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "semanas" : "semana", "long"),
207
+ names: ["semanas", "semana", "sem"]
208
+ },
209
+ month: {
210
+ short: "mes",
211
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "meses" : "mes", "long"),
212
+ names: ["meses", "mes", "mo"]
213
+ },
214
+ year: {
215
+ short: "a",
216
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "a\xF1os" : "a\xF1o", "long"),
217
+ names: ["a\xF1os", "anos", "a\xF1o", "ano", "a"]
218
+ }
219
+ }
220
+ }
221
+ };
222
+ for (const [locale, definition] of Object.entries(defaultLocales)) {
223
+ setLocale(locale, definition);
224
+ }
225
+
226
+ // src/units.ts
227
+ var import_duration = require("@sodiumlabs/duration");
228
+ var unitValues = {
229
+ millisecond: import_duration.Time.Millisecond,
230
+ second: import_duration.Time.Second,
231
+ minute: import_duration.Time.Minute,
232
+ hour: import_duration.Time.Hour,
233
+ day: import_duration.Time.Day,
234
+ week: import_duration.Time.Week,
235
+ month: import_duration.Time.Month,
236
+ year: import_duration.Time.Year
237
+ };
238
+
239
+ // src/index.ts
240
+ function ms(value, options) {
241
+ if (typeof value === "string") {
242
+ return parse(value, options);
243
+ } else if (typeof value === "number") {
244
+ return format(value, options);
245
+ }
246
+ throw new Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(value)}`);
247
+ }
248
+ __name(ms, "ms");
249
+ function parse(str, options) {
250
+ if (typeof str !== "string" || str.length === 0 || str.length > 100) {
251
+ throw new Error(
252
+ `Value provided to ms.parse() must be a string with length between 1 and 99. value=${JSON.stringify(str)}`
253
+ );
254
+ }
255
+ const locale = locales.get(options?.locale ?? "en");
256
+ if (!locale) {
257
+ throw new Error(`Unknown locale "${options?.locale}"`);
258
+ }
259
+ let total = 0;
260
+ let consumed = false;
261
+ const tokenRegex = /(?<value>-?\d*\.?\d+) *(?<unit>[a-zàèìòùáéíóúýâêîôûãñõäëïöüÿçµ]+)?/gi;
262
+ let match;
263
+ let lastIndex = 0;
264
+ while ((match = tokenRegex.exec(str)) !== null) {
265
+ if (str.slice(lastIndex, match.index).trim().length !== 0) {
266
+ return NaN;
267
+ }
268
+ const { value: rawValue, unit: rawUnit = "ms" } = match.groups;
269
+ const value = parseFloat(rawValue);
270
+ if (Number.isNaN(value)) {
271
+ return NaN;
272
+ }
273
+ const unit = !rawUnit ? "millisecond" : locale.mappedUnits.get(rawUnit.toLowerCase());
274
+ if (!unit) {
275
+ return NaN;
276
+ }
277
+ total += value * unitValues[unit];
278
+ consumed = true;
279
+ lastIndex = tokenRegex.lastIndex;
280
+ }
281
+ if (!consumed || str.slice(lastIndex).trim().length !== 0) {
282
+ return NaN;
283
+ }
284
+ return total;
285
+ }
286
+ __name(parse, "parse");
287
+ function format(ms2, options) {
288
+ if (typeof ms2 !== "number" || !Number.isFinite(ms2)) {
289
+ throw new Error("Value provided to ms.format() must be of type number.");
290
+ }
291
+ const locale = locales.get(options?.locale ?? "en");
292
+ if (!locale) {
293
+ throw new Error(`Unknown locale "${options?.locale}"`);
294
+ }
295
+ const sign = ms2 < 0 ? "-" : "";
296
+ let remaining = Math.abs(ms2);
297
+ const units = Object.entries(locale.units).map(([unit, def]) => ({
298
+ unit,
299
+ def,
300
+ value: unitValues[unit]
301
+ })).sort((a, b) => b.value - a.value);
302
+ if (!options?.compound) {
303
+ for (const { def, value } of units) {
304
+ if (remaining >= value) {
305
+ const amount = Math.round(ms2 / value);
306
+ if (options?.long) {
307
+ return `${amount} ${def.long(Math.abs(amount))}`;
308
+ }
309
+ return `${amount}${def.short}`;
310
+ }
311
+ }
312
+ const msDef = locale.units.millisecond;
313
+ return options?.long ? `${ms2} ${msDef.long(Math.abs(ms2))}` : `${ms2}${msDef.short}`;
314
+ }
315
+ const parts = [];
316
+ let usedUnits = 0;
317
+ for (const { def, value } of units) {
318
+ if (remaining < value) continue;
319
+ const amount = Math.floor(remaining / value);
320
+ remaining -= amount * value;
321
+ if (amount > 0) {
322
+ parts.push(options?.long ? `${amount} ${def.long(amount)}` : `${amount}${def.short}`);
323
+ usedUnits++;
324
+ if (options?.maxUnits && usedUnits >= options.maxUnits) {
325
+ break;
326
+ }
327
+ }
328
+ }
329
+ if (parts.length === 0) {
330
+ const msDef = locale.units.millisecond;
331
+ parts.push(options?.long ? `0 ${msDef.long(0)}` : `0${msDef.short}`);
332
+ }
333
+ return sign + parts.join(options?.long ? " " : "");
334
+ }
335
+ __name(format, "format");
336
+ // Annotate the CommonJS export names for ESM import in node:
337
+ 0 && (module.exports = {
338
+ format,
339
+ ms,
340
+ parse
341
+ });
342
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/locales.ts","../src/units.ts"],"sourcesContent":["import { locales } from \"./locales\";\nimport { Unit, unitValues } from \"./units\";\n\n/**\n * The options.\n */\nexport interface Options {\n /**\n * Set to `true` to use verbose formatting. Defaults to `false`.\n */\n long?: boolean;\n /**\n * The locale. Defaults to `en`.\n */\n locale?: string;\n compound?: boolean;\n maxUnits?: number;\n}\n\n/**\n * Parse or format the given value.\n *\n * @param value - The string or number to convert\n * @param options - Options for the conversion\n * @throws Error if `value` is not a non-empty string or a number\n */\nexport function ms(value: string, options?: Options): number;\nexport function ms(value: number, options?: Options): string;\nexport function ms(value: string | number, options?: Options): number | string {\n if (typeof value === \"string\") {\n return parse(value, options);\n } else if (typeof value === \"number\") {\n return format(value, options);\n }\n throw new Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(value)}`);\n}\n\n/**\n * Parse the given string and return milliseconds.\n *\n * @param str - A string to parse into milliseconds. Length must be in [1;100]\n * @returns The parsed value in milliseconds, or `NaN` if the string can't be parsed\n */\nexport function parse(str: string, options?: Options): number {\n if (typeof str !== \"string\" || str.length === 0 || str.length > 100) {\n throw new Error(\n `Value provided to ms.parse() must be a string with length between 1 and 99. value=${JSON.stringify(str)}`,\n );\n }\n\n const locale = locales.get(options?.locale ?? \"en\");\n if (!locale) {\n throw new Error(`Unknown locale \"${options?.locale}\"`);\n }\n\n let total = 0;\n let consumed = false;\n\n const tokenRegex = /(?<value>-?\\d*\\.?\\d+) *(?<unit>[a-zàèìòùáéíóúýâêîôûãñõäëïöüÿçµ]+)?/gi;\n let match: RegExpExecArray | null;\n let lastIndex = 0;\n\n while ((match = tokenRegex.exec(str)) !== null) {\n if (str.slice(lastIndex, match.index).trim().length !== 0) {\n return NaN;\n }\n\n const { value: rawValue, unit: rawUnit = \"ms\" } = match.groups as {\n value: string;\n unit: string | undefined;\n };\n\n const value = parseFloat(rawValue);\n if (Number.isNaN(value)) {\n return NaN;\n }\n\n const unit = !rawUnit ? \"millisecond\" : locale.mappedUnits.get(rawUnit.toLowerCase());\n if (!unit) {\n return NaN;\n }\n\n total += value * unitValues[unit];\n consumed = true;\n\n lastIndex = tokenRegex.lastIndex;\n }\n\n if (!consumed || str.slice(lastIndex).trim().length !== 0) {\n return NaN;\n }\n\n return total;\n}\n\n/**\n * Format the given integer as a string.\n *\n * @param ms - milliseconds\n * @param options - Options for the conversion\n * @returns The formatted string\n */\nexport function format(ms: number, options?: Options): string {\n if (typeof ms !== \"number\" || !Number.isFinite(ms)) {\n throw new Error(\"Value provided to ms.format() must be of type number.\");\n }\n\n const locale = locales.get(options?.locale ?? \"en\");\n if (!locale) {\n throw new Error(`Unknown locale \"${options?.locale}\"`);\n }\n\n const sign = ms < 0 ? \"-\" : \"\";\n let remaining = Math.abs(ms);\n\n // units sorted by descending size\n const units = Object.entries(locale.units)\n .map(([unit, def]) => ({\n unit,\n def,\n value: unitValues[unit as Unit],\n }))\n .sort((a, b) => b.value - a.value);\n\n // === simple mode (current behavior) ===\n if (!options?.compound) {\n for (const { def, value } of units) {\n if (remaining >= value) {\n const amount = Math.round(ms / value);\n\n if (options?.long) {\n return `${amount} ${def.long(Math.abs(amount))}`;\n }\n\n return `${amount}${def.short}`;\n }\n }\n\n const msDef = locale.units.millisecond;\n return options?.long ? `${ms} ${msDef.long(Math.abs(ms))}` : `${ms}${msDef.short}`;\n }\n\n // === compound mode ===\n const parts: string[] = [];\n let usedUnits = 0;\n\n for (const { def, value } of units) {\n if (remaining < value) continue;\n\n const amount = Math.floor(remaining / value);\n remaining -= amount * value;\n\n if (amount > 0) {\n parts.push(options?.long ? `${amount} ${def.long(amount)}` : `${amount}${def.short}`);\n\n usedUnits++;\n if (options?.maxUnits && usedUnits >= options.maxUnits) {\n break;\n }\n }\n }\n\n // fallback if everything was < 1ms\n if (parts.length === 0) {\n const msDef = locale.units.millisecond;\n parts.push(options?.long ? `0 ${msDef.long(0)}` : `0${msDef.short}`);\n }\n\n return sign + parts.join(options?.long ? \" \" : \"\");\n}\n","import { Unit } from \"./units\";\n\n/**\n * The options and translations of a locale.\n */\nexport interface LocaleDefinition {\n units: Record<Unit, UnitDefinition>;\n}\n\n/**\n * The translations of a time unit.\n */\nexport interface UnitDefinition {\n /**\n * The short name of the unit.\n */\n short: string;\n /**\n * The long name of the unit.\n *\n * @example\n * ```ts\n * long: c => (c > 1 ? \"plural form\" : \"singular form\")\n * ```\n *\n * @param c - The absolute value of the rounded number.\n */\n long: (c: number) => string;\n /**\n * The names of the unit. Should be all lowercase.\n *\n * @remarks\n * The values of `short` and `long` are not automatically added\n * to this array, so you probably want to add them here too\n * if you want them to be used in the parse function.\n */\n names: string[];\n}\n\nexport type CompleteLocaleDefinition = LocaleDefinition & {\n /**\n * A map from the translated unit name to the corresponding unit name.\n */\n mappedUnits: Map<string, Unit>;\n};\n\n/**\n * The locales definitions. You can add or edit a locale definition directly here,\n * or use {@link setLocale}.\n */\nexport const locales = new Map<string, CompleteLocaleDefinition>();\n\n/**\n * Add or edit a locale definition.\n *\n * @param locale - The locale (e.g. `it`)\n * @param definition - The definition\n */\nexport const setLocale = (locale: string, definition: LocaleDefinition) => {\n const mappedUnits = new Map<string, Unit>();\n for (const [unit, def] of Object.entries(definition.units) as [Unit, UnitDefinition][]) {\n for (const name of def.names) {\n mappedUnits.set(name.toLowerCase(), unit);\n }\n }\n\n locales.set(locale, {\n ...definition,\n mappedUnits,\n });\n};\n\n// Define the default locales\n\nconst defaultLocales: Record<string, LocaleDefinition> = {\n en: {\n units: {\n millisecond: {\n short: \"ms\",\n long: c => (c > 1 ? \"milliseconds\" : \"millisecond\"),\n names: [\"milliseconds\", \"millisecond\", \"msecs\", \"msec\", \"ms\"],\n },\n second: {\n short: \"s\",\n long: c => (c > 1 ? \"seconds\" : \"second\"),\n names: [\"seconds\", \"second\", \"secs\", \"sec\", \"s\"],\n },\n minute: {\n short: \"m\",\n long: c => (c > 1 ? \"minutes\" : \"minute\"),\n names: [\"minutes\", \"minute\", \"mins\", \"min\", \"m\"],\n },\n hour: {\n short: \"h\",\n long: c => (c > 1 ? \"hours\" : \"hour\"),\n names: [\"hours\", \"hour\", \"hrs\", \"hr\", \"h\"],\n },\n day: {\n short: \"d\",\n long: c => (c > 1 ? \"days\" : \"day\"),\n names: [\"days\", \"day\", \"d\"],\n },\n week: {\n short: \"w\",\n long: c => (c > 1 ? \"weeks\" : \"week\"),\n names: [\"weeks\", \"week\", \"w\"],\n },\n month: {\n short: \"mo\",\n long: c => (c > 1 ? \"months\" : \"month\"),\n names: [\"months\", \"month\", \"mo\"],\n },\n year: {\n short: \"y\",\n long: c => (c > 1 ? \"years\" : \"year\"),\n names: [\"years\", \"year\", \"yrs\", \"yr\", \"y\"],\n },\n },\n },\n fr: {\n units: {\n millisecond: {\n short: \"ms\",\n long: c => (c > 1 ? \"millisecondes\" : \"milliseconde\"),\n names: [\"millisecondes\", \"milliseconde\", \"ms\"],\n },\n second: {\n short: \"s\",\n long: c => (c > 1 ? \"secondes\" : \"seconde\"),\n names: [\"secondes\", \"seconde\", \"secs\", \"sec\", \"s\"],\n },\n minute: {\n short: \"m\",\n long: c => (c > 1 ? \"minutes\" : \"minute\"),\n names: [\"minutes\", \"minute\", \"mins\", \"min\", \"m\"],\n },\n hour: {\n short: \"h\",\n long: c => (c > 1 ? \"heures\" : \"heure\"),\n names: [\"heures\", \"heure\", \"h\"],\n },\n day: {\n short: \"j\",\n long: c => (c > 1 ? \"jours\" : \"jour\"),\n names: [\"jours\", \"jour\", \"j\"],\n },\n week: {\n short: \"sem\",\n long: c => (c > 1 ? \"semaines\" : \"semaine\"),\n names: [\"semaines\", \"semaine\", \"sem\"],\n },\n month: {\n short: \"mo\",\n long: _ => \"mois\",\n names: [\"mois\", \"mo\"],\n },\n year: {\n short: \"an\",\n long: c => (c > 1 ? \"années\" : \"année\"),\n names: [\"années\", \"annees\", \"année\", \"annee\", \"ans\", \"an\"],\n },\n },\n },\n de: {\n units: {\n millisecond: {\n short: \"ms\",\n long: c => (c > 1 ? \"Millisekunden\" : \"Millisekunde\"),\n names: [\"millisekunden\", \"millisekunde\", \"ms\"],\n },\n second: {\n short: \"s\",\n long: c => (c > 1 ? \"Sekunden\" : \"Sekunde\"),\n names: [\"sekunden\", \"sekunde\", \"seks\", \"sek\", \"s\"],\n },\n minute: {\n short: \"m\",\n long: c => (c > 1 ? \"Minuten\" : \"Minute\"),\n names: [\"minuten\", \"minute\", \"mins\", \"min\", \"m\"],\n },\n hour: {\n short: \"h\",\n long: c => (c > 1 ? \"Stunden\" : \"Stunde\"),\n names: [\"stunden\", \"stunde\", \"hrs\", \"hr\", \"h\"],\n },\n day: {\n short: \"t\",\n long: c => (c > 1 ? \"Tage\" : \"Tag\"),\n names: [\"tage\", \"tag\", \"t\", \"d\"],\n },\n week: {\n short: \"w\",\n long: c => (c > 1 ? \"Wochen\" : \"Woche\"),\n names: [\"wochen\", \"woche\", \"wo\", \"w\"],\n },\n month: {\n short: \"mo\",\n long: c => (c > 1 ? \"Monate\" : \"Monat\"),\n names: [\"monate\", \"monat\", \"mon\", \"mo\"],\n },\n year: {\n short: \"j\",\n long: c => (c > 1 ? \"Jahre\" : \"Jahr\"),\n names: [\"jahre\", \"jahr\", \"j\", \"y\"],\n },\n },\n },\n es: {\n units: {\n millisecond: {\n short: \"ms\",\n long: c => (c > 1 ? \"milisegundos\" : \"milisegundo\"),\n names: [\"milisegundos\", \"milisegundo\", \"ms\"],\n },\n second: {\n short: \"s\",\n long: c => (c > 1 ? \"segundos\" : \"segundo\"),\n names: [\"segundos\", \"segundo\", \"s\"],\n },\n minute: {\n short: \"min\",\n long: c => (c > 1 ? \"minutos\" : \"minuto\"),\n names: [\"minutos\", \"minuto\", \"mins\", \"min\", \"m\"],\n },\n hour: {\n short: \"h\",\n long: c => (c > 1 ? \"horas\" : \"hora\"),\n names: [\"horas\", \"hora\", \"hrs\", \"hr\", \"h\"],\n },\n day: {\n short: \"d\",\n long: c => (c > 1 ? \"días\" : \"día\"),\n names: [\"días\", \"dias\", \"día\", \"dia\", \"d\"],\n },\n week: {\n short: \"sem\",\n long: c => (c > 1 ? \"semanas\" : \"semana\"),\n names: [\"semanas\", \"semana\", \"sem\"],\n },\n month: {\n short: \"mes\",\n long: c => (c > 1 ? \"meses\" : \"mes\"),\n names: [\"meses\", \"mes\", \"mo\"],\n },\n year: {\n short: \"a\",\n long: c => (c > 1 ? \"años\" : \"año\"),\n names: [\"años\", \"anos\", \"año\", \"ano\", \"a\"],\n },\n },\n },\n};\n\nfor (const [locale, definition] of Object.entries(defaultLocales)) {\n setLocale(locale, definition);\n}\n","import { Time } from \"@sodiumlabs/duration\";\n\n/**\n * The available time units.\n */\nexport const units = [\"millisecond\", \"second\", \"minute\", \"hour\", \"day\", \"week\", \"month\", \"year\"] as const;\n\n/**\n * A time unit.\n */\nexport type Unit = (typeof units)[number];\n\n/**\n * The values in milliseconds of each time unit.\n */\nexport const unitValues: Record<Unit, number> = {\n millisecond: Time.Millisecond,\n second: Time.Second,\n minute: Time.Minute,\n hour: Time.Hour,\n day: Time.Day,\n week: Time.Week,\n month: Time.Month,\n year: Time.Year,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACkDO,IAAM,UAAU,oBAAI,IAAsC;AAQ1D,IAAM,YAAY,wBAAC,QAAgB,eAAiC;AACvE,QAAM,cAAc,oBAAI,IAAkB;AAC1C,aAAW,CAAC,MAAM,GAAG,KAAK,OAAO,QAAQ,WAAW,KAAK,GAA+B;AACpF,eAAW,QAAQ,IAAI,OAAO;AAC1B,kBAAY,IAAI,KAAK,YAAY,GAAG,IAAI;AAAA,IAC5C;AAAA,EACJ;AAEA,UAAQ,IAAI,QAAQ;AAAA,IAChB,GAAG;AAAA,IACH;AAAA,EACJ,CAAC;AACL,GAZyB;AAgBzB,IAAM,iBAAmD;AAAA,EACrD,IAAI;AAAA,IACA,OAAO;AAAA,MACH,aAAa;AAAA,QACT,OAAO;AAAA,QACP,MAAM,8BAAM,IAAI,IAAI,iBAAiB,eAA/B;AAAA,QACN,OAAO,CAAC,gBAAgB,eAAe,SAAS,QAAQ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Y;AAEhB,aAAW,EAAE,KAAK,MAAM,KAAK,OAAO;AAChC,QAAI,YAAY,MAAO;AAEvB,UAAM,SAAS,KAAK,MAAM,YAAY,KAAK;AAC3C,iBAAa,SAAS;AAEtB,QAAI,SAAS,GAAG;AACZ,YAAM,KAAK,SAAS,OAAO,GAAG,MAAM,IAAI,IAAI,KAAK,MAAM,CAAC,KAAK,GAAG,MAAM,GAAG,IAAI,KAAK,EAAE;AAEpF;AACA,UAAI,SAAS,YAAY,aAAa,QAAQ,UAAU;AACpD;AAAA,MACJ;AAAA,IACJ;AAAA,EACJ;AAGA,MAAI,MAAM,WAAW,GAAG;AACpB,UAAM,QAAQ,OAAO,MAAM;AAC3B,UAAM,KAAK,SAAS,OAAO,KAAK,MAAM,KAAK,CAAC,CAAC,KAAK,IAAI,MAAM,KAAK,EAAE;AAAA,EACvE;AAEA,SAAO,OAAO,MAAM,KAAK,SAAS,OAAO,MAAM,EAAE;AACrD;AAnEgB;","names":["ms"]}
package/dist/index.mjs ADDED
@@ -0,0 +1,315 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // src/locales.ts
5
+ var locales = /* @__PURE__ */ new Map();
6
+ var setLocale = /* @__PURE__ */ __name((locale, definition) => {
7
+ const mappedUnits = /* @__PURE__ */ new Map();
8
+ for (const [unit, def] of Object.entries(definition.units)) {
9
+ for (const name of def.names) {
10
+ mappedUnits.set(name.toLowerCase(), unit);
11
+ }
12
+ }
13
+ locales.set(locale, {
14
+ ...definition,
15
+ mappedUnits
16
+ });
17
+ }, "setLocale");
18
+ var defaultLocales = {
19
+ en: {
20
+ units: {
21
+ millisecond: {
22
+ short: "ms",
23
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "milliseconds" : "millisecond", "long"),
24
+ names: ["milliseconds", "millisecond", "msecs", "msec", "ms"]
25
+ },
26
+ second: {
27
+ short: "s",
28
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "seconds" : "second", "long"),
29
+ names: ["seconds", "second", "secs", "sec", "s"]
30
+ },
31
+ minute: {
32
+ short: "m",
33
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "minutes" : "minute", "long"),
34
+ names: ["minutes", "minute", "mins", "min", "m"]
35
+ },
36
+ hour: {
37
+ short: "h",
38
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "hours" : "hour", "long"),
39
+ names: ["hours", "hour", "hrs", "hr", "h"]
40
+ },
41
+ day: {
42
+ short: "d",
43
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "days" : "day", "long"),
44
+ names: ["days", "day", "d"]
45
+ },
46
+ week: {
47
+ short: "w",
48
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "weeks" : "week", "long"),
49
+ names: ["weeks", "week", "w"]
50
+ },
51
+ month: {
52
+ short: "mo",
53
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "months" : "month", "long"),
54
+ names: ["months", "month", "mo"]
55
+ },
56
+ year: {
57
+ short: "y",
58
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "years" : "year", "long"),
59
+ names: ["years", "year", "yrs", "yr", "y"]
60
+ }
61
+ }
62
+ },
63
+ fr: {
64
+ units: {
65
+ millisecond: {
66
+ short: "ms",
67
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "millisecondes" : "milliseconde", "long"),
68
+ names: ["millisecondes", "milliseconde", "ms"]
69
+ },
70
+ second: {
71
+ short: "s",
72
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "secondes" : "seconde", "long"),
73
+ names: ["secondes", "seconde", "secs", "sec", "s"]
74
+ },
75
+ minute: {
76
+ short: "m",
77
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "minutes" : "minute", "long"),
78
+ names: ["minutes", "minute", "mins", "min", "m"]
79
+ },
80
+ hour: {
81
+ short: "h",
82
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "heures" : "heure", "long"),
83
+ names: ["heures", "heure", "h"]
84
+ },
85
+ day: {
86
+ short: "j",
87
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "jours" : "jour", "long"),
88
+ names: ["jours", "jour", "j"]
89
+ },
90
+ week: {
91
+ short: "sem",
92
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "semaines" : "semaine", "long"),
93
+ names: ["semaines", "semaine", "sem"]
94
+ },
95
+ month: {
96
+ short: "mo",
97
+ long: /* @__PURE__ */ __name((_) => "mois", "long"),
98
+ names: ["mois", "mo"]
99
+ },
100
+ year: {
101
+ short: "an",
102
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "ann\xE9es" : "ann\xE9e", "long"),
103
+ names: ["ann\xE9es", "annees", "ann\xE9e", "annee", "ans", "an"]
104
+ }
105
+ }
106
+ },
107
+ de: {
108
+ units: {
109
+ millisecond: {
110
+ short: "ms",
111
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "Millisekunden" : "Millisekunde", "long"),
112
+ names: ["millisekunden", "millisekunde", "ms"]
113
+ },
114
+ second: {
115
+ short: "s",
116
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "Sekunden" : "Sekunde", "long"),
117
+ names: ["sekunden", "sekunde", "seks", "sek", "s"]
118
+ },
119
+ minute: {
120
+ short: "m",
121
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "Minuten" : "Minute", "long"),
122
+ names: ["minuten", "minute", "mins", "min", "m"]
123
+ },
124
+ hour: {
125
+ short: "h",
126
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "Stunden" : "Stunde", "long"),
127
+ names: ["stunden", "stunde", "hrs", "hr", "h"]
128
+ },
129
+ day: {
130
+ short: "t",
131
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "Tage" : "Tag", "long"),
132
+ names: ["tage", "tag", "t", "d"]
133
+ },
134
+ week: {
135
+ short: "w",
136
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "Wochen" : "Woche", "long"),
137
+ names: ["wochen", "woche", "wo", "w"]
138
+ },
139
+ month: {
140
+ short: "mo",
141
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "Monate" : "Monat", "long"),
142
+ names: ["monate", "monat", "mon", "mo"]
143
+ },
144
+ year: {
145
+ short: "j",
146
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "Jahre" : "Jahr", "long"),
147
+ names: ["jahre", "jahr", "j", "y"]
148
+ }
149
+ }
150
+ },
151
+ es: {
152
+ units: {
153
+ millisecond: {
154
+ short: "ms",
155
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "milisegundos" : "milisegundo", "long"),
156
+ names: ["milisegundos", "milisegundo", "ms"]
157
+ },
158
+ second: {
159
+ short: "s",
160
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "segundos" : "segundo", "long"),
161
+ names: ["segundos", "segundo", "s"]
162
+ },
163
+ minute: {
164
+ short: "min",
165
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "minutos" : "minuto", "long"),
166
+ names: ["minutos", "minuto", "mins", "min", "m"]
167
+ },
168
+ hour: {
169
+ short: "h",
170
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "horas" : "hora", "long"),
171
+ names: ["horas", "hora", "hrs", "hr", "h"]
172
+ },
173
+ day: {
174
+ short: "d",
175
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "d\xEDas" : "d\xEDa", "long"),
176
+ names: ["d\xEDas", "dias", "d\xEDa", "dia", "d"]
177
+ },
178
+ week: {
179
+ short: "sem",
180
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "semanas" : "semana", "long"),
181
+ names: ["semanas", "semana", "sem"]
182
+ },
183
+ month: {
184
+ short: "mes",
185
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "meses" : "mes", "long"),
186
+ names: ["meses", "mes", "mo"]
187
+ },
188
+ year: {
189
+ short: "a",
190
+ long: /* @__PURE__ */ __name((c) => c > 1 ? "a\xF1os" : "a\xF1o", "long"),
191
+ names: ["a\xF1os", "anos", "a\xF1o", "ano", "a"]
192
+ }
193
+ }
194
+ }
195
+ };
196
+ for (const [locale, definition] of Object.entries(defaultLocales)) {
197
+ setLocale(locale, definition);
198
+ }
199
+
200
+ // src/units.ts
201
+ import { Time } from "@sodiumlabs/duration";
202
+ var unitValues = {
203
+ millisecond: Time.Millisecond,
204
+ second: Time.Second,
205
+ minute: Time.Minute,
206
+ hour: Time.Hour,
207
+ day: Time.Day,
208
+ week: Time.Week,
209
+ month: Time.Month,
210
+ year: Time.Year
211
+ };
212
+
213
+ // src/index.ts
214
+ function ms(value, options) {
215
+ if (typeof value === "string") {
216
+ return parse(value, options);
217
+ } else if (typeof value === "number") {
218
+ return format(value, options);
219
+ }
220
+ throw new Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(value)}`);
221
+ }
222
+ __name(ms, "ms");
223
+ function parse(str, options) {
224
+ if (typeof str !== "string" || str.length === 0 || str.length > 100) {
225
+ throw new Error(
226
+ `Value provided to ms.parse() must be a string with length between 1 and 99. value=${JSON.stringify(str)}`
227
+ );
228
+ }
229
+ const locale = locales.get(options?.locale ?? "en");
230
+ if (!locale) {
231
+ throw new Error(`Unknown locale "${options?.locale}"`);
232
+ }
233
+ let total = 0;
234
+ let consumed = false;
235
+ const tokenRegex = /(?<value>-?\d*\.?\d+) *(?<unit>[a-zàèìòùáéíóúýâêîôûãñõäëïöüÿçµ]+)?/gi;
236
+ let match;
237
+ let lastIndex = 0;
238
+ while ((match = tokenRegex.exec(str)) !== null) {
239
+ if (str.slice(lastIndex, match.index).trim().length !== 0) {
240
+ return NaN;
241
+ }
242
+ const { value: rawValue, unit: rawUnit = "ms" } = match.groups;
243
+ const value = parseFloat(rawValue);
244
+ if (Number.isNaN(value)) {
245
+ return NaN;
246
+ }
247
+ const unit = !rawUnit ? "millisecond" : locale.mappedUnits.get(rawUnit.toLowerCase());
248
+ if (!unit) {
249
+ return NaN;
250
+ }
251
+ total += value * unitValues[unit];
252
+ consumed = true;
253
+ lastIndex = tokenRegex.lastIndex;
254
+ }
255
+ if (!consumed || str.slice(lastIndex).trim().length !== 0) {
256
+ return NaN;
257
+ }
258
+ return total;
259
+ }
260
+ __name(parse, "parse");
261
+ function format(ms2, options) {
262
+ if (typeof ms2 !== "number" || !Number.isFinite(ms2)) {
263
+ throw new Error("Value provided to ms.format() must be of type number.");
264
+ }
265
+ const locale = locales.get(options?.locale ?? "en");
266
+ if (!locale) {
267
+ throw new Error(`Unknown locale "${options?.locale}"`);
268
+ }
269
+ const sign = ms2 < 0 ? "-" : "";
270
+ let remaining = Math.abs(ms2);
271
+ const units = Object.entries(locale.units).map(([unit, def]) => ({
272
+ unit,
273
+ def,
274
+ value: unitValues[unit]
275
+ })).sort((a, b) => b.value - a.value);
276
+ if (!options?.compound) {
277
+ for (const { def, value } of units) {
278
+ if (remaining >= value) {
279
+ const amount = Math.round(ms2 / value);
280
+ if (options?.long) {
281
+ return `${amount} ${def.long(Math.abs(amount))}`;
282
+ }
283
+ return `${amount}${def.short}`;
284
+ }
285
+ }
286
+ const msDef = locale.units.millisecond;
287
+ return options?.long ? `${ms2} ${msDef.long(Math.abs(ms2))}` : `${ms2}${msDef.short}`;
288
+ }
289
+ const parts = [];
290
+ let usedUnits = 0;
291
+ for (const { def, value } of units) {
292
+ if (remaining < value) continue;
293
+ const amount = Math.floor(remaining / value);
294
+ remaining -= amount * value;
295
+ if (amount > 0) {
296
+ parts.push(options?.long ? `${amount} ${def.long(amount)}` : `${amount}${def.short}`);
297
+ usedUnits++;
298
+ if (options?.maxUnits && usedUnits >= options.maxUnits) {
299
+ break;
300
+ }
301
+ }
302
+ }
303
+ if (parts.length === 0) {
304
+ const msDef = locale.units.millisecond;
305
+ parts.push(options?.long ? `0 ${msDef.long(0)}` : `0${msDef.short}`);
306
+ }
307
+ return sign + parts.join(options?.long ? " " : "");
308
+ }
309
+ __name(format, "format");
310
+ export {
311
+ format,
312
+ ms,
313
+ parse
314
+ };
315
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/locales.ts","../src/units.ts","../src/index.ts"],"sourcesContent":["import { Unit } from \"./units\";\n\n/**\n * The options and translations of a locale.\n */\nexport interface LocaleDefinition {\n units: Record<Unit, UnitDefinition>;\n}\n\n/**\n * The translations of a time unit.\n */\nexport interface UnitDefinition {\n /**\n * The short name of the unit.\n */\n short: string;\n /**\n * The long name of the unit.\n *\n * @example\n * ```ts\n * long: c => (c > 1 ? \"plural form\" : \"singular form\")\n * ```\n *\n * @param c - The absolute value of the rounded number.\n */\n long: (c: number) => string;\n /**\n * The names of the unit. Should be all lowercase.\n *\n * @remarks\n * The values of `short` and `long` are not automatically added\n * to this array, so you probably want to add them here too\n * if you want them to be used in the parse function.\n */\n names: string[];\n}\n\nexport type CompleteLocaleDefinition = LocaleDefinition & {\n /**\n * A map from the translated unit name to the corresponding unit name.\n */\n mappedUnits: Map<string, Unit>;\n};\n\n/**\n * The locales definitions. You can add or edit a locale definition directly here,\n * or use {@link setLocale}.\n */\nexport const locales = new Map<string, CompleteLocaleDefinition>();\n\n/**\n * Add or edit a locale definition.\n *\n * @param locale - The locale (e.g. `it`)\n * @param definition - The definition\n */\nexport const setLocale = (locale: string, definition: LocaleDefinition) => {\n const mappedUnits = new Map<string, Unit>();\n for (const [unit, def] of Object.entries(definition.units) as [Unit, UnitDefinition][]) {\n for (const name of def.names) {\n mappedUnits.set(name.toLowerCase(), unit);\n }\n }\n\n locales.set(locale, {\n ...definition,\n mappedUnits,\n });\n};\n\n// Define the default locales\n\nconst defaultLocales: Record<string, LocaleDefinition> = {\n en: {\n units: {\n millisecond: {\n short: \"ms\",\n long: c => (c > 1 ? \"milliseconds\" : \"millisecond\"),\n names: [\"milliseconds\", \"millisecond\", \"msecs\", \"msec\", \"ms\"],\n },\n second: {\n short: \"s\",\n long: c => (c > 1 ? \"seconds\" : \"second\"),\n names: [\"seconds\", \"second\", \"secs\", \"sec\", \"s\"],\n },\n minute: {\n short: \"m\",\n long: c => (c > 1 ? \"minutes\" : \"minute\"),\n names: [\"minutes\", \"minute\", \"mins\", \"min\", \"m\"],\n },\n hour: {\n short: \"h\",\n long: c => (c > 1 ? \"hours\" : \"hour\"),\n names: [\"hours\", \"hour\", \"hrs\", \"hr\", \"h\"],\n },\n day: {\n short: \"d\",\n long: c => (c > 1 ? \"days\" : \"day\"),\n names: [\"days\", \"day\", \"d\"],\n },\n week: {\n short: \"w\",\n long: c => (c > 1 ? \"weeks\" : \"week\"),\n names: [\"weeks\", \"week\", \"w\"],\n },\n month: {\n short: \"mo\",\n long: c => (c > 1 ? \"months\" : \"month\"),\n names: [\"months\", \"month\", \"mo\"],\n },\n year: {\n short: \"y\",\n long: c => (c > 1 ? \"years\" : \"year\"),\n names: [\"years\", \"year\", \"yrs\", \"yr\", \"y\"],\n },\n },\n },\n fr: {\n units: {\n millisecond: {\n short: \"ms\",\n long: c => (c > 1 ? \"millisecondes\" : \"milliseconde\"),\n names: [\"millisecondes\", \"milliseconde\", \"ms\"],\n },\n second: {\n short: \"s\",\n long: c => (c > 1 ? \"secondes\" : \"seconde\"),\n names: [\"secondes\", \"seconde\", \"secs\", \"sec\", \"s\"],\n },\n minute: {\n short: \"m\",\n long: c => (c > 1 ? \"minutes\" : \"minute\"),\n names: [\"minutes\", \"minute\", \"mins\", \"min\", \"m\"],\n },\n hour: {\n short: \"h\",\n long: c => (c > 1 ? \"heures\" : \"heure\"),\n names: [\"heures\", \"heure\", \"h\"],\n },\n day: {\n short: \"j\",\n long: c => (c > 1 ? \"jours\" : \"jour\"),\n names: [\"jours\", \"jour\", \"j\"],\n },\n week: {\n short: \"sem\",\n long: c => (c > 1 ? \"semaines\" : \"semaine\"),\n names: [\"semaines\", \"semaine\", \"sem\"],\n },\n month: {\n short: \"mo\",\n long: _ => \"mois\",\n names: [\"mois\", \"mo\"],\n },\n year: {\n short: \"an\",\n long: c => (c > 1 ? \"années\" : \"année\"),\n names: [\"années\", \"annees\", \"année\", \"annee\", \"ans\", \"an\"],\n },\n },\n },\n de: {\n units: {\n millisecond: {\n short: \"ms\",\n long: c => (c > 1 ? \"Millisekunden\" : \"Millisekunde\"),\n names: [\"millisekunden\", \"millisekunde\", \"ms\"],\n },\n second: {\n short: \"s\",\n long: c => (c > 1 ? \"Sekunden\" : \"Sekunde\"),\n names: [\"sekunden\", \"sekunde\", \"seks\", \"sek\", \"s\"],\n },\n minute: {\n short: \"m\",\n long: c => (c > 1 ? \"Minuten\" : \"Minute\"),\n names: [\"minuten\", \"minute\", \"mins\", \"min\", \"m\"],\n },\n hour: {\n short: \"h\",\n long: c => (c > 1 ? \"Stunden\" : \"Stunde\"),\n names: [\"stunden\", \"stunde\", \"hrs\", \"hr\", \"h\"],\n },\n day: {\n short: \"t\",\n long: c => (c > 1 ? \"Tage\" : \"Tag\"),\n names: [\"tage\", \"tag\", \"t\", \"d\"],\n },\n week: {\n short: \"w\",\n long: c => (c > 1 ? \"Wochen\" : \"Woche\"),\n names: [\"wochen\", \"woche\", \"wo\", \"w\"],\n },\n month: {\n short: \"mo\",\n long: c => (c > 1 ? \"Monate\" : \"Monat\"),\n names: [\"monate\", \"monat\", \"mon\", \"mo\"],\n },\n year: {\n short: \"j\",\n long: c => (c > 1 ? \"Jahre\" : \"Jahr\"),\n names: [\"jahre\", \"jahr\", \"j\", \"y\"],\n },\n },\n },\n es: {\n units: {\n millisecond: {\n short: \"ms\",\n long: c => (c > 1 ? \"milisegundos\" : \"milisegundo\"),\n names: [\"milisegundos\", \"milisegundo\", \"ms\"],\n },\n second: {\n short: \"s\",\n long: c => (c > 1 ? \"segundos\" : \"segundo\"),\n names: [\"segundos\", \"segundo\", \"s\"],\n },\n minute: {\n short: \"min\",\n long: c => (c > 1 ? \"minutos\" : \"minuto\"),\n names: [\"minutos\", \"minuto\", \"mins\", \"min\", \"m\"],\n },\n hour: {\n short: \"h\",\n long: c => (c > 1 ? \"horas\" : \"hora\"),\n names: [\"horas\", \"hora\", \"hrs\", \"hr\", \"h\"],\n },\n day: {\n short: \"d\",\n long: c => (c > 1 ? \"días\" : \"día\"),\n names: [\"días\", \"dias\", \"día\", \"dia\", \"d\"],\n },\n week: {\n short: \"sem\",\n long: c => (c > 1 ? \"semanas\" : \"semana\"),\n names: [\"semanas\", \"semana\", \"sem\"],\n },\n month: {\n short: \"mes\",\n long: c => (c > 1 ? \"meses\" : \"mes\"),\n names: [\"meses\", \"mes\", \"mo\"],\n },\n year: {\n short: \"a\",\n long: c => (c > 1 ? \"años\" : \"año\"),\n names: [\"años\", \"anos\", \"año\", \"ano\", \"a\"],\n },\n },\n },\n};\n\nfor (const [locale, definition] of Object.entries(defaultLocales)) {\n setLocale(locale, definition);\n}\n","import { Time } from \"@sodiumlabs/duration\";\n\n/**\n * The available time units.\n */\nexport const units = [\"millisecond\", \"second\", \"minute\", \"hour\", \"day\", \"week\", \"month\", \"year\"] as const;\n\n/**\n * A time unit.\n */\nexport type Unit = (typeof units)[number];\n\n/**\n * The values in milliseconds of each time unit.\n */\nexport const unitValues: Record<Unit, number> = {\n millisecond: Time.Millisecond,\n second: Time.Second,\n minute: Time.Minute,\n hour: Time.Hour,\n day: Time.Day,\n week: Time.Week,\n month: Time.Month,\n year: Time.Year,\n};\n","import { locales } from \"./locales\";\nimport { Unit, unitValues } from \"./units\";\n\n/**\n * The options.\n */\nexport interface Options {\n /**\n * Set to `true` to use verbose formatting. Defaults to `false`.\n */\n long?: boolean;\n /**\n * The locale. Defaults to `en`.\n */\n locale?: string;\n compound?: boolean;\n maxUnits?: number;\n}\n\n/**\n * Parse or format the given value.\n *\n * @param value - The string or number to convert\n * @param options - Options for the conversion\n * @throws Error if `value` is not a non-empty string or a number\n */\nexport function ms(value: string, options?: Options): number;\nexport function ms(value: number, options?: Options): string;\nexport function ms(value: string | number, options?: Options): number | string {\n if (typeof value === \"string\") {\n return parse(value, options);\n } else if (typeof value === \"number\") {\n return format(value, options);\n }\n throw new Error(`Value provided to ms() must be a string or number. value=${JSON.stringify(value)}`);\n}\n\n/**\n * Parse the given string and return milliseconds.\n *\n * @param str - A string to parse into milliseconds. Length must be in [1;100]\n * @returns The parsed value in milliseconds, or `NaN` if the string can't be parsed\n */\nexport function parse(str: string, options?: Options): number {\n if (typeof str !== \"string\" || str.length === 0 || str.length > 100) {\n throw new Error(\n `Value provided to ms.parse() must be a string with length between 1 and 99. value=${JSON.stringify(str)}`,\n );\n }\n\n const locale = locales.get(options?.locale ?? \"en\");\n if (!locale) {\n throw new Error(`Unknown locale \"${options?.locale}\"`);\n }\n\n let total = 0;\n let consumed = false;\n\n const tokenRegex = /(?<value>-?\\d*\\.?\\d+) *(?<unit>[a-zàèìòùáéíóúýâêîôûãñõäëïöüÿçµ]+)?/gi;\n let match: RegExpExecArray | null;\n let lastIndex = 0;\n\n while ((match = tokenRegex.exec(str)) !== null) {\n if (str.slice(lastIndex, match.index).trim().length !== 0) {\n return NaN;\n }\n\n const { value: rawValue, unit: rawUnit = \"ms\" } = match.groups as {\n value: string;\n unit: string | undefined;\n };\n\n const value = parseFloat(rawValue);\n if (Number.isNaN(value)) {\n return NaN;\n }\n\n const unit = !rawUnit ? \"millisecond\" : locale.mappedUnits.get(rawUnit.toLowerCase());\n if (!unit) {\n return NaN;\n }\n\n total += value * unitValues[unit];\n consumed = true;\n\n lastIndex = tokenRegex.lastIndex;\n }\n\n if (!consumed || str.slice(lastIndex).trim().length !== 0) {\n return NaN;\n }\n\n return total;\n}\n\n/**\n * Format the given integer as a string.\n *\n * @param ms - milliseconds\n * @param options - Options for the conversion\n * @returns The formatted string\n */\nexport function format(ms: number, options?: Options): string {\n if (typeof ms !== \"number\" || !Number.isFinite(ms)) {\n throw new Error(\"Value provided to ms.format() must be of type number.\");\n }\n\n const locale = locales.get(options?.locale ?? \"en\");\n if (!locale) {\n throw new Error(`Unknown locale \"${options?.locale}\"`);\n }\n\n const sign = ms < 0 ? \"-\" : \"\";\n let remaining = Math.abs(ms);\n\n // units sorted by descending size\n const units = Object.entries(locale.units)\n .map(([unit, def]) => ({\n unit,\n def,\n value: unitValues[unit as Unit],\n }))\n .sort((a, b) => b.value - a.value);\n\n // === simple mode (current behavior) ===\n if (!options?.compound) {\n for (const { def, value } of units) {\n if (remaining >= value) {\n const amount = Math.round(ms / value);\n\n if (options?.long) {\n return `${amount} ${def.long(Math.abs(amount))}`;\n }\n\n return `${amount}${def.short}`;\n }\n }\n\n const msDef = locale.units.millisecond;\n return options?.long ? `${ms} ${msDef.long(Math.abs(ms))}` : `${ms}${msDef.short}`;\n }\n\n // === compound mode ===\n const parts: string[] = [];\n let usedUnits = 0;\n\n for (const { def, value } of units) {\n if (remaining < value) continue;\n\n const amount = Math.floor(remaining / value);\n remaining -= amount * value;\n\n if (amount > 0) {\n parts.push(options?.long ? `${amount} ${def.long(amount)}` : `${amount}${def.short}`);\n\n usedUnits++;\n if (options?.maxUnits && usedUnits >= options.maxUnits) {\n break;\n }\n }\n }\n\n // fallback if everything was < 1ms\n if (parts.length === 0) {\n const msDef = locale.units.millisecond;\n parts.push(options?.long ? `0 ${msDef.long(0)}` : `0${msDef.short}`);\n }\n\n return sign + parts.join(options?.long ? \" \" : \"\");\n}\n"],"mappings":";;;;AAkDO,IAAM,UAAU,oBAAI,IAAsC;AAQ1D,IAAM,YAAY,wBAAC,QAAgB,eAAiC;AACvE,QAAM,cAAc,oBAAI,IAAkB;AAC1C,aAAW,CAAC,MAAM,GAAG,KAAK,OAAO,QAAQ,WAAW,KAAK,GAA+B;AACpF,eAAW,QAAQ,IAAI,OAAO;AAC1B,kBAAY,IAAI,KAAK,YAAY,GAAG,IAAI;AAAA,IAC5C;AAAA,EACJ;AAEA,UAAQ,IAAI,QAAQ;AAAA,IAChB,GAAG;AAAA,IACH;AAAA,EACJ,CAAC;AACL,GAZyB;AAgBzB,IAAM,iBAAmD;AAAA,EACrD,IAAI;AAAA,IACA,OAAO;AAAA,MACH,aAAa;AAAA,QACT,OAAO;AAAA,QACP,MAAM,8BAAM,IAAI,IAAI,iBAAiB,eAA/B;AAAA,QACN,OAAO,CAAC,gBAAgB,eAAe,SAAS,QAAQ,IAAI;AAAA,MAChE;AAAA,MACA,QAAQ;AAAA,QAC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AAI,YAAY,MAAO;AAEvB,UAAM,SAAS,KAAK,MAAM,YAAY,KAAK;AAC3C,iBAAa,SAAS;AAEtB,QAAI,SAAS,GAAG;AACZ,YAAM,KAAK,SAAS,OAAO,GAAG,MAAM,IAAI,IAAI,KAAK,MAAM,CAAC,KAAK,GAAG,MAAM,GAAG,IAAI,KAAK,EAAE;AAEpF;AACA,UAAI,SAAS,YAAY,aAAa,QAAQ,UAAU;AACpD;AAAA,MACJ;AAAA,IACJ;AAAA,EACJ;AAGA,MAAI,MAAM,WAAW,GAAG;AACpB,UAAM,QAAQ,OAAO,MAAM;AAC3B,UAAM,KAAK,SAAS,OAAO,KAAK,MAAM,KAAK,CAAC,CAAC,KAAK,IAAI,MAAM,KAAK,EAAE;AAAA,EACvE;AAEA,SAAO,OAAO,MAAM,KAAK,SAAS,OAAO,MAAM,EAAE;AACrD;AAnEgB;","names":["ms"]}
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/package.json",
3
+ "name": "@sodiumlabs/ms",
4
+ "version": "1.0.0",
5
+ "description": "Utility to convert various time formats to milliseconds",
6
+ "keywords": [
7
+ "enhanced",
8
+ "localized",
9
+ "ms",
10
+ "parse",
11
+ "sodium",
12
+ "sodiumlabs",
13
+ "time",
14
+ "typescript"
15
+ ],
16
+ "homepage": "https://github.com/sodium-labs/utilities/tree/main/packages/ms",
17
+ "bugs": {
18
+ "url": "https://github.com/sodium-labs/utilities/issues"
19
+ },
20
+ "license": "MIT",
21
+ "author": "sodiumlabs",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/sodium-labs/utilities.git",
25
+ "directory": "packages/ms"
26
+ },
27
+ "files": [
28
+ "dist"
29
+ ],
30
+ "main": "./dist/index.js",
31
+ "module": "./dist/index.mjs",
32
+ "types": "./dist/index.d.ts",
33
+ "exports": {
34
+ ".": {
35
+ "require": {
36
+ "types": "./dist/index.d.ts",
37
+ "default": "./dist/index.js"
38
+ },
39
+ "import": {
40
+ "types": "./dist/index.d.mts",
41
+ "default": "./dist/index.mjs"
42
+ }
43
+ }
44
+ },
45
+ "dependencies": {
46
+ "@sodiumlabs/duration": "^1.0.1"
47
+ },
48
+ "devDependencies": {
49
+ "@microsoft/api-extractor": "^7.55.2",
50
+ "tsup": "^8.5.1",
51
+ "typescript": "^5.9.3"
52
+ },
53
+ "engines": {
54
+ "node": ">=18"
55
+ },
56
+ "scripts": {
57
+ "build": "tsup",
58
+ "build:docs": "tsc -p tsconfig.docs.json",
59
+ "lint": "tsc --noEmit && oxlint && oxfmt --check",
60
+ "fmt": "oxfmt",
61
+ "test": "vitest run",
62
+ "docs": "npm run build:docs && api-extractor run --local"
63
+ }
64
+ }