ranuts 0.4.0-alpha.1 → 0.4.0-alpha.2

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.
@@ -1,3 +1,5 @@
1
+ /** Accepted everywhere a moment in time is taken; `undefined` means "now". */
2
+ export type DateInput = number | string | Date;
1
3
  /**
2
4
  * @description: Format a date with a token pattern. Accepts a timestamp, a date string, a
3
5
  * `Date`, or nothing (meaning now). Wrap literal text in `[]` to keep it out of the substitution.
@@ -23,10 +25,10 @@
23
25
  * ```ts
24
26
  * formatDate(); // '2026-07-25 14:30:00'
25
27
  * formatDate(1753425000000, 'YYYY/MM/DD'); // '2026/07/25'
26
- * formatDate(new Date(), 'YYYY[年]MM[月]DD[日] hh:mm a'); // '2026年07月25日 02:30 pm' (escaped literals)
28
+ * formatDate(new Date(), 'YYYY[年]MM[月]DD[日] hh:mm a'); // '2026 年 07 月 25 日 02:30 pm' (escaped literals)
27
29
  * ```
28
30
  */
29
- export declare const formatDate: (value?: number | string | Date, pattern?: string) => string;
31
+ export declare const formatDate: (value?: DateInput, pattern?: string) => string;
30
32
  /**
31
33
  * @description: Turn a timestamp into a `Date` carrying a `format` method.
32
34
  * @deprecated Use [`formatDate`](#formatdate). This returns a `Date` with an extra method
@@ -39,12 +41,80 @@ export declare const formatDate: (value?: number | string | Date, pattern?: stri
39
41
  export declare function timestampToTime(timestamp?: number | string): Date & {
40
42
  format?: Function;
41
43
  };
44
+ /**
45
+ * @description: Format an elapsed number of **seconds** as a colon-separated clock duration,
46
+ * the shape media players use for a playhead: `mm:ss`, widening to `hh:mm:ss` past an hour.
47
+ *
48
+ * This is a length of time, not a point in time — for the latter see
49
+ * [`formatDate`](#formatdate) (absolute) and [`formatRelative`](#formatrelative) (relative).
50
+ *
51
+ * @param {number} seconds elapsed seconds; negatives clamp to `0`
52
+ * @return {string} the duration, or `''` when the input is not a finite number — a player
53
+ * asks for `video.duration` before metadata loads and gets `NaN`, and an empty label reads
54
+ * better there than `NaN:NaN`
55
+ * @example
56
+ * ```ts
57
+ * formatDuration(0); // '00:00'
58
+ * formatDuration(65); // '01:05'
59
+ * formatDuration(3661); // '01:01:01'
60
+ * formatDuration(NaN); // ''
61
+ * ```
62
+ */
63
+ export declare const formatDuration: (seconds: number) => string;
42
64
  /**
43
65
  * @description: Format a number of seconds as a colon-separated duration
66
+ * @deprecated Renamed to [`formatDuration`](#formatduration) — `timeFormat` said nothing about
67
+ * *which* of the three time formats it was, and read backwards from its `formatDate` sibling.
68
+ * This alias stays for compatibility and behaves identically.
44
69
  * @param {number} time
45
- * @return {*}
70
+ * @return {string}
46
71
  */
47
72
  export declare const timeFormat: (time: number) => string;
73
+ /** `'compact'` is ours; the other three are `Intl.RelativeTimeFormat` styles. */
74
+ export type RelativeStyle = 'long' | 'short' | 'narrow' | 'compact';
75
+ export interface FormatRelativeOptions {
76
+ /** What to measure against. Defaults to the current time. */
77
+ now?: DateInput;
78
+ /** BCP 47 tag(s); defaults to the runtime's locale. Ignored by the `compact` style. */
79
+ locale?: string | string[];
80
+ /** Defaults to `'long'` (`'3 days ago'`). */
81
+ style?: RelativeStyle;
82
+ /**
83
+ * `'auto'` (the default here) swaps in idioms where a language has them — `yesterday`
84
+ * rather than `1 day ago`, `now` rather than `in 0 seconds`. `'always'` keeps the number.
85
+ */
86
+ numeric?: 'always' | 'auto';
87
+ }
88
+ /**
89
+ * @description: Format a point in time relative to another — "3 days ago", "in 2 hours".
90
+ *
91
+ * Localization is delegated to the platform's `Intl.RelativeTimeFormat`, which has been
92
+ * available in every major browser since 2020 and knows each language's plural and
93
+ * inflection rules. This function supplies only the part `Intl` deliberately leaves out:
94
+ * picking *which* unit to express the gap in.
95
+ *
96
+ * Like `Intl` itself it reports a **single** unit — a gap of 3 days and 6 hours is
97
+ * "3 days ago", never "3 days and 6 hours ago".
98
+ *
99
+ * The extra `compact` style is the dense badge form seen next to list items (`5m`, `3h`,
100
+ * `2d`). It is a magnitude only: it carries **no direction**, so a future timestamp reads
101
+ * the same as a past one. Use it for feeds of past events, and any other style when the
102
+ * reader has to tell past from future.
103
+ *
104
+ * @param {DateInput} value the moment to describe
105
+ * @param {FormatRelativeOptions} options
106
+ * @return {string} the description, or `''` when either end cannot be parsed
107
+ * @example
108
+ * ```ts
109
+ * const twoHoursAgo = Date.now() - 2 * 3600_000;
110
+ * formatRelative(twoHoursAgo); // '2 hours ago'
111
+ * formatRelative(twoHoursAgo, { style: 'short' }); // '2 hr. ago'
112
+ * formatRelative(twoHoursAgo, { style: 'compact' }); // '2h'
113
+ * formatRelative(twoHoursAgo, { locale: 'zh-CN' }); // '2 小时前'
114
+ * formatRelative(Date.now() + 60_000); // 'in 1 minute'
115
+ * ```
116
+ */
117
+ export declare const formatRelative: (value: DateInput, options?: FormatRelativeOptions) => string;
48
118
  /**
49
119
  * @description: Current timestamp
50
120
  * @return {*}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};