qstd 0.3.64 → 0.3.66

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.
@@ -281,7 +281,15 @@ var formatDuration = (value, options = {}) => {
281
281
  showMs = false,
282
282
  spaces = true
283
283
  } = options;
284
- const ms = unit === "ss" ? value * 1e3 : unit === "mm" ? value * 60 * 1e3 : value;
284
+ const isMs = unit === "ms";
285
+ const isSeconds = unit === "seconds" || unit === "secs" || unit === "ss";
286
+ const isMinutes = unit === "minutes" || unit === "mins" || unit === "mm";
287
+ if (!isMs && !isSeconds && !isMinutes) {
288
+ throw new Error(
289
+ `Invalid unit "${unit}". Use "ms", "seconds" (or "secs"/"ss"), or "minutes" (or "mins"/"mm").`
290
+ );
291
+ }
292
+ const ms = isSeconds ? value * 1e3 : isMinutes ? value * 60 * 1e3 : value;
285
293
  const absMs = Math.abs(ms);
286
294
  const totalSeconds = Math.floor(absMs / 1e3);
287
295
  const hours = Math.floor(totalSeconds / 3600);
@@ -274,7 +274,15 @@ var formatDuration = (value, options = {}) => {
274
274
  showMs = false,
275
275
  spaces = true
276
276
  } = options;
277
- const ms = unit === "ss" ? value * 1e3 : unit === "mm" ? value * 60 * 1e3 : value;
277
+ const isMs = unit === "ms";
278
+ const isSeconds = unit === "seconds" || unit === "secs" || unit === "ss";
279
+ const isMinutes = unit === "minutes" || unit === "mins" || unit === "mm";
280
+ if (!isMs && !isSeconds && !isMinutes) {
281
+ throw new Error(
282
+ `Invalid unit "${unit}". Use "ms", "seconds" (or "secs"/"ss"), or "minutes" (or "mins"/"mm").`
283
+ );
284
+ }
285
+ const ms = isSeconds ? value * 1e3 : isMinutes ? value * 60 * 1e3 : value;
278
286
  const absMs = Math.abs(ms);
279
287
  const totalSeconds = Math.floor(absMs / 1e3);
280
288
  const hours = Math.floor(totalSeconds / 3600);
@@ -293,7 +293,15 @@ var formatDuration = (value, options = {}) => {
293
293
  showMs = false,
294
294
  spaces = true
295
295
  } = options;
296
- const ms = unit === "ss" ? value * 1e3 : unit === "mm" ? value * 60 * 1e3 : value;
296
+ const isMs = unit === "ms";
297
+ const isSeconds = unit === "seconds" || unit === "secs" || unit === "ss";
298
+ const isMinutes = unit === "minutes" || unit === "mins" || unit === "mm";
299
+ if (!isMs && !isSeconds && !isMinutes) {
300
+ throw new Error(
301
+ `Invalid unit "${unit}". Use "ms", "seconds" (or "secs"/"ss"), or "minutes" (or "mins"/"mm").`
302
+ );
303
+ }
304
+ const ms = isSeconds ? value * 1e3 : isMinutes ? value * 60 * 1e3 : value;
297
305
  const absMs = Math.abs(ms);
298
306
  const totalSeconds = Math.floor(absMs / 1e3);
299
307
  const hours = Math.floor(totalSeconds / 3600);
@@ -285,7 +285,15 @@ var formatDuration = (value, options = {}) => {
285
285
  showMs = false,
286
286
  spaces = true
287
287
  } = options;
288
- const ms = unit === "ss" ? value * 1e3 : unit === "mm" ? value * 60 * 1e3 : value;
288
+ const isMs = unit === "ms";
289
+ const isSeconds = unit === "seconds" || unit === "secs" || unit === "ss";
290
+ const isMinutes = unit === "minutes" || unit === "mins" || unit === "mm";
291
+ if (!isMs && !isSeconds && !isMinutes) {
292
+ throw new Error(
293
+ `Invalid unit "${unit}". Use "ms", "seconds" (or "secs"/"ss"), or "minutes" (or "mins"/"mm").`
294
+ );
295
+ }
296
+ const ms = isSeconds ? value * 1e3 : isMinutes ? value * 60 * 1e3 : value;
289
297
  const absMs = Math.abs(ms);
290
298
  const totalSeconds = Math.floor(absMs / 1e3);
291
299
  const hours = Math.floor(totalSeconds / 3600);
@@ -1,10 +1,11 @@
1
1
  import type { Locale } from "date-fns";
2
2
  type DurationFormat = "compact" | "full" | "clock" | "fractional";
3
- type DurationUnit = "ms" | "ss" | "mm";
3
+ /** Suggested units - aliases like 'ss', 'secs', 'mm', 'mins' are also accepted */
4
+ type DurationUnit = "ms" | "seconds" | "minutes" | (string & {});
4
5
  type DurationOptions = {
5
6
  /** Format style: 'compact' (1h 2m), 'full' (1 hour 2 minutes), 'clock' (01:02:03), 'fractional' (1.4s, 1m4.4s) */
6
7
  format?: DurationFormat;
7
- /** Input unit: 'ms' (milliseconds, default), 'ss' (seconds), or 'mm' (minutes). Use 'ss' for audio/video currentTime. */
8
+ /** Input unit: 'ms' (milliseconds, default), 'seconds' (or 'secs'/'ss'), or 'minutes' (or 'mins'/'mm'). Use 'seconds' for audio/video currentTime. */
8
9
  unit?: DurationUnit;
9
10
  /** Show zero values for intermediate units (e.g., "1h 0m 30s" vs "1h 30s") */
10
11
  showZero?: boolean;
@@ -24,7 +25,7 @@ type DurationOptions = {
24
25
  * @param value - Duration value in the specified unit (defaults to milliseconds)
25
26
  * @param options - Configuration options
26
27
  * @param options.format - Output format: 'clock' (default), 'compact', 'full', or 'fractional'
27
- * @param options.unit - Input unit: 'ms' (milliseconds, default), 'ss' (seconds), or 'mm' (minutes)
28
+ * @param options.unit - Input unit: 'ms' (milliseconds, default), 'seconds' (or 'secs'/'ss'), or 'minutes' (or 'mins'/'mm')
28
29
  * @param options.showZero - Show zero intermediate units (e.g., "1h 0m 0s" vs "1h")
29
30
  * @param options.showMs - Include milliseconds in compact format
30
31
  * @param options.spaces - Use spaces between units in compact format (default: true)
@@ -37,10 +38,10 @@ type DurationOptions = {
37
38
  * // ─────────────────────────────────────────────────────────────────────────────
38
39
  * formatDuration(90000) // "1:30"
39
40
  * formatDuration(3661000) // "1:01:01"
40
- * formatDuration(45, { unit: "ss" }) // "0:45"
41
- * formatDuration(225, { unit: "ss" }) // "3:45"
42
- * formatDuration(3661, { unit: "ss" }) // "1:01:01"
43
- * formatDuration(90, { unit: "mm" }) // "1:30:00"
41
+ * formatDuration(45, { unit: "seconds" }) // "0:45"
42
+ * formatDuration(225, { unit: "seconds" }) // "3:45"
43
+ * formatDuration(3661, { unit: "seconds" }) // "1:01:01"
44
+ * formatDuration(90, { unit: "minutes" }) // "1:30:00"
44
45
  *
45
46
  * // ─────────────────────────────────────────────────────────────────────────────
46
47
  * // COMPACT FORMAT - "1h 2m 3s" or "1h2m3s"
@@ -49,14 +50,14 @@ type DurationOptions = {
49
50
  * formatDuration(90000, { format: "compact" }) // "1m 30s"
50
51
  * formatDuration(3600000, { format: "compact" }) // "1h"
51
52
  * formatDuration(3661000, { format: "compact" }) // "1h 1m 1s"
52
- * formatDuration(45, { unit: "ss", format: "compact" }) // "45s"
53
- * formatDuration(90, { unit: "ss", format: "compact" }) // "1m 30s"
54
- * formatDuration(3661, { unit: "ss", format: "compact" }) // "1h 1m 1s"
53
+ * formatDuration(45, { unit: "seconds", format: "compact" }) // "45s"
54
+ * formatDuration(90, { unit: "seconds", format: "compact" }) // "1m 30s"
55
+ * formatDuration(3661, { unit: "seconds", format: "compact" }) // "1h 1m 1s"
55
56
  *
56
57
  * // Without spaces (recording timer style)
57
- * formatDuration(3661, { unit: "ss", format: "compact", spaces: false }) // "1h1m1s"
58
- * formatDuration(90, { unit: "ss", format: "compact", spaces: false }) // "1m30s"
59
- * formatDuration(45, { unit: "ss", format: "compact", spaces: false }) // "45s"
58
+ * formatDuration(3661, { unit: "seconds", format: "compact", spaces: false }) // "1h1m1s"
59
+ * formatDuration(90, { unit: "seconds", format: "compact", spaces: false }) // "1m30s"
60
+ * formatDuration(45, { unit: "seconds", format: "compact", spaces: false }) // "45s"
60
61
  *
61
62
  * // With zero intermediate units
62
63
  * formatDuration(3600000, { format: "compact", showZero: true }) // "1h 0m 0s"
@@ -92,7 +93,7 @@ type DurationOptions = {
92
93
  * formatDuration(NaN) // "--:--"
93
94
  * formatDuration(Infinity) // "--:--"
94
95
  * formatDuration(-5) // "--:--"
95
- * formatDuration(-5, { unit: "ss" }) // "--:--"
96
+ * formatDuration(-5, { unit: "seconds" }) // "--:--"
96
97
  * ```
97
98
  */
98
99
  export declare const formatDuration: (value: number | null | undefined, options?: DurationOptions) => string;
@@ -1 +1 @@
1
- {"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../../src/shared/time.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,M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AC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qstd",
3
- "version": "0.3.64",
3
+ "version": "0.3.66",
4
4
  "description": "Standard Block component and utilities library with Panda CSS",
5
5
  "author": "malin1",
6
6
  "license": "MIT",