@miloun/cosmo 0.1.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) Aiden Adrian
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,73 @@
1
+ # Cosmo
2
+
3
+ Ergonomic application localisation for JavaScript / Node, built entirely on the standard [`Intl`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl) API.
4
+
5
+ Cosmo is a thin, ergonomic layer over the JavaScript engine's own
6
+ [ICU](https://icu.unicode.org/), reached through the standard
7
+ [`Intl`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Intl)
8
+ API. Give it a locale (and optionally a time zone) and it formats numbers, money,
9
+ dates, units, lists and messages exactly the way your users expect. There are **zero
10
+ runtime dependencies and zero bundled locale data** — every result comes straight
11
+ from ICU and [CLDR](https://cldr.unicode.org/), covering all languages, scripts,
12
+ calendars and time zones.
13
+
14
+ Cosmo is implemented consistently across four languages — the same concepts, method
15
+ names and behaviour, each built directly on its platform's ICU:
16
+ **JavaScript** ·
17
+ [Python](https://github.com/cosmo-intl/cosmo-python) ([docs](https://cosmo.miloun.com/?lang=python)) ·
18
+ [Java](https://github.com/cosmo-intl/cosmo-java) ([docs](https://cosmo.miloun.com/?lang=java)) ·
19
+ [PHP](https://github.com/salarmehr/cosmopolitan) ([docs](https://cosmo.miloun.com/?lang=php)).
20
+
21
+ 📖 **Full documentation, API reference and live playground:** https://cosmo.miloun.com/?lang=js
22
+
23
+ ## Requirements
24
+
25
+ - Node 20+ (Node 22+ for `duration()`), or any modern browser
26
+ - ESM-only; ships TypeScript type definitions
27
+
28
+ ## Install
29
+
30
+ ```sh
31
+ npm install @miloun/cosmo
32
+ ```
33
+
34
+ ## Quick start
35
+
36
+ ```ts
37
+ import { Cosmo, cosmo } from "@miloun/cosmo";
38
+
39
+ new Cosmo("es_ES").money(11000.4, "EUR"); // "11.000,40 €"
40
+ new Cosmo("tr").unit("temperature", "celsius", 26, "short"); // "26 °C"
41
+ new Cosmo("en").percentage(0.2); // "20%"
42
+ new Cosmo("fa").language("en"); // "انگلیسی"
43
+
44
+ // or the helper
45
+ cosmo("en_AU").country(); // "Australia"
46
+ ```
47
+
48
+ Underscore locales (`en_AU`) and [BCP-47](https://www.rfc-editor.org/info/bcp47) [Unicode
49
+ extensions](https://unicode.org/reports/tr35/#u_Extension) (`fa-IR-u-nu-latn-ca-buddhist`)
50
+ are both accepted.
51
+
52
+ ## What you get
53
+
54
+ - **Locale display names** — languages, regions, scripts, calendars and currencies, plus emoji flags and writing direction.
55
+ - **Numbers & money** — decimals, percentages, currencies, units, compact notation (`1.2M`), scientific, and number/money ranges.
56
+ - **Dates & times** — locale formats in any calendar (Gregorian, Persian, Buddhist…), durations, date ranges, and relative times (`"3 days ago"`).
57
+ - **Text** — locale-aware sort and search, word/sentence/grapheme segmentation, and case mapping.
58
+ - **Lists** — `"A, B, and C"` conjunctions and disjunctions.
59
+ - **Messages** — [ICU MessageFormat](https://unicode-org.github.io/icu/userguide/format_parse/messages/) (`plural`, `selectordinal`, `select`).
60
+
61
+ See the [full API reference](https://cosmo.miloun.com/api-reference/?lang=js) for every method,
62
+ the [platform notes](https://cosmo.miloun.com/platform-notes/) for what `Intl` does and
63
+ doesn't expose to JavaScript, and [resources](https://cosmo.miloun.com/resources/) for ICU/CLDR references.
64
+
65
+ ## Errors
66
+
67
+ Recoverable problems throw `CosmoError`, with `InvalidArgumentError` and
68
+ `UnsupportedError` subclasses — an invalid currency in strict mode, an unsupported
69
+ unit, an unsupported symbol name, a malformed message, and the like.
70
+
71
+ ## License
72
+
73
+ MIT © Aiden Adrian
package/changelog.md ADDED
@@ -0,0 +1,31 @@
1
+ Changelog
2
+ =========
3
+ * v0.1.0 — initial (unstable) JavaScript / Node port of [salarmehr/cosmopolitan](https://github.com/salarmehr/cosmopolitan)
4
+ - Built entirely on the standard `Intl` API (ICU) with **zero runtime dependencies** and **no bundled locale data**
5
+ - PHP-ported core: `language`, `country`, `script`, `calendar`, `currency` (name + symbol),
6
+ `direction`, `flag`, `number`, `percentage`, `money`, `symbol`, `unit`,
7
+ `message` (ICU MessageFormat subset), `duration`, `moment`, `date`, `time`
8
+ - Collation & search: `compare`, `sort`, `contains` (`Intl.Collator` / `Intl.Segmenter`)
9
+ - Text segmentation: `splitWords`, `splitSentences`, `splitGraphemes`, `ellipsize` (`Intl.Segmenter`)
10
+ - Locale-aware case: `upper`, `lower`
11
+ - Locale metadata: `pluralCategory`, `weekInfo`, `addLikelySubtags`,
12
+ `removeLikelySubtags`, `monthNames` (calendar-aligned), `weekdayNames`, `timeZoneName`,
13
+ `displayName` (generic `Intl.DisplayNames` lookup), `supportedValues` (`Intl.supportedValuesOf`)
14
+ - Directed-duration & range formatting (JS-only): `relativeDuration` (the
15
+ directed-duration counterpart of the undirected `duration`) +
16
+ `relativeDurationBetween(target, reference?)`, `join`, `compact`,
17
+ `scientific`, `numberRange`, `moneyRange`, `dateRange`
18
+ - `duration()` also accepts a unit breakdown (`{ days, hours, minutes, … }`) for multi-unit output
19
+ - `number`/`percentage`/`money` accept a `NumberOptions` bag (`roundingMode`, `roundingIncrement`,
20
+ `min`/`maxFractionDigits`, `useGrouping`); `compare`/`sort`/`contains` accept collation
21
+ tailoring (`{ numeric, caseFirst }`) — all restricted to settings the PHP and Python ports
22
+ also expose, so the contract stays identical across ports
23
+ - Terminology: a point in time is a `Moment`; `duration` is undirected,
24
+ `relativeDuration` is directed; `time`/`timeWidth`/`timeZone` always mean clock/zone
25
+ - `Cosmo.fromSubtags()` and `Cosmo.fromAcceptLanguage()` factories, plus the `cosmo()` helper
26
+ - TypeScript source, ships `.d.ts` types, ESM-only
27
+ - Intentionally **omitted** because they would require ICU facilities the `Intl`
28
+ API does not expose (and the library bundles no data of its own):
29
+ `spellout()` (RBNF), `ordinal()` text such as "1st" (RBNF / suffix data),
30
+ `quote()` (CLDR delimiters), `get()` (raw ICU resource bundles), and automatic
31
+ region→currency inference.
@@ -0,0 +1,381 @@
1
+ import { type MessageArgs } from "./message.js";
2
+ /** Width of a formatted date, time, unit, … — mirrors ICU's length styles. */
3
+ export type FormatWidth = "none" | "short" | "medium" | "long" | "full";
4
+ /** Optional locale overrides applied on top of the locale identifier. */
5
+ export interface Modifiers {
6
+ /** Calendar identifier, e.g. `"gregory"`, `"persian"`, `"buddhist"`. */
7
+ calendar?: string | null;
8
+ /** ISO 4217 currency code used as the default for {@link Cosmo.money}. */
9
+ currency?: string | null;
10
+ /** IANA time zone, e.g. `"Australia/Sydney"`. */
11
+ timeZone?: string | null;
12
+ }
13
+ /** Locale subtags parsed from the canonical locale. */
14
+ export interface Subtags {
15
+ language: string;
16
+ script: string;
17
+ region: string;
18
+ }
19
+ /** A moment in time accepted by the date/time methods. Numbers are Unix milliseconds (JS-native). */
20
+ export type Moment = Date | number;
21
+ /** LDML plural category, as returned by `Intl.PluralRules#select`. */
22
+ export type PluralCategory = "zero" | "one" | "two" | "few" | "many" | "other";
23
+ /**
24
+ * Week metadata, mirroring `Intl.Locale#getWeekInfo()`. Days are 1 = Mon … 7 = Sun.
25
+ * `minimalDays` is omitted on runtimes (e.g. current V8) that don't expose it.
26
+ */
27
+ export interface WeekInfo {
28
+ firstDay: number;
29
+ weekend: number[];
30
+ minimalDays?: number;
31
+ }
32
+ /** Time-zone name styles accepted by `Intl.DateTimeFormat`'s `timeZoneName`. */
33
+ export type TimeZoneNameStyle = "short" | "long" | "shortOffset" | "longOffset" | "shortGeneric" | "longGeneric";
34
+ /** Kinds of list joins exposed by `Intl.ListFormat`. */
35
+ export type ListType = "conjunction" | "disjunction" | "unit";
36
+ /** Display-name categories accepted by {@link Cosmo.displayName}. */
37
+ export type DisplayType = "language" | "region" | "script" | "calendar" | "currency";
38
+ /** Keys accepted by {@link Cosmo.supportedValues} / `Intl.supportedValuesOf`. */
39
+ export type SupportedKey = "calendar" | "collation" | "currency" | "numberingSystem" | "timeZone" | "unit";
40
+ /**
41
+ * Number-formatting controls for {@link Cosmo.number}, {@link Cosmo.percentage}
42
+ * and {@link Cosmo.money}. Field names match `Intl.NumberFormat`'s options.
43
+ *
44
+ * Most fields map onto an ICU setting the PHP and Python ports expose too, so the
45
+ * contract is identical across all three ports. The exceptions are flagged inline
46
+ * as **JS port only**: these have no equivalent in the legacy ICU `NumberFormatter`
47
+ * (PHP) / `DecimalFormat` (Python) APIs those ports use, so they take effect in the
48
+ * JS port and are silently ignored by the others.
49
+ */
50
+ export interface NumberOptions {
51
+ /** Minimum integer digits; zero-pads the whole part (`5` → `"005"` at 3). */
52
+ minimumIntegerDigits?: number;
53
+ minimumFractionDigits?: number;
54
+ maximumFractionDigits?: number;
55
+ /** Minimum significant digits (ICU treats significant- and fraction-digit limits as mutually exclusive). */
56
+ minimumSignificantDigits?: number;
57
+ /** Maximum significant digits. */
58
+ maximumSignificantDigits?: number;
59
+ /** ICU-portable rounding modes (these have a direct ICU equivalent in every port). */
60
+ roundingMode?: "ceil" | "floor" | "expand" | "trunc" | "halfExpand" | "halfTrunc" | "halfEven";
61
+ roundingIncrement?: 1 | 2 | 5 | 10 | 20 | 25 | 50 | 100 | 200 | 250 | 500 | 1000 | 2000 | 2500 | 5000;
62
+ /** JS accepts the full union; the PHP and Python ports coerce any truthy value to "on". */
63
+ useGrouping?: "always" | "auto" | "min2" | boolean;
64
+ /** **JS port only** — ignored by the PHP and Python ports (legacy ICU formatters have no sign-display attribute). */
65
+ signDisplay?: "auto" | "always" | "exceptZero" | "negative" | "never";
66
+ /** **JS port only** — ignored by the PHP and Python ports. */
67
+ trailingZeroDisplay?: "auto" | "stripIfInteger";
68
+ /** **JS port only** — ignored by the PHP and Python ports. */
69
+ roundingPriority?: "auto" | "morePrecision" | "lessPrecision";
70
+ /** **JS port only** — ignored by PHP/Python; for those ports use the dedicated `compact()` / `scientific()` methods instead. */
71
+ notation?: "standard" | "scientific" | "engineering" | "compact";
72
+ /** Only meaningful with `notation: "compact"`. **JS port only** — ignored by the PHP and Python ports. */
73
+ compactDisplay?: "short" | "long";
74
+ }
75
+ /** Collation tailoring for {@link Cosmo.compare}, {@link Cosmo.sort}, {@link Cosmo.contains}. */
76
+ export interface CollationOptions {
77
+ /** Sort numeric substrings by value (`"item2"` < `"item10"`). */
78
+ numeric?: boolean;
79
+ /** Whether upper- or lower-case sorts first. */
80
+ caseFirst?: "upper" | "lower" | "false";
81
+ }
82
+ /** A breakdown of a duration into units, accepted by {@link Cosmo.duration}. */
83
+ export interface DurationParts {
84
+ years?: number;
85
+ months?: number;
86
+ weeks?: number;
87
+ days?: number;
88
+ hours?: number;
89
+ minutes?: number;
90
+ seconds?: number;
91
+ milliseconds?: number;
92
+ }
93
+ export declare class Cosmo {
94
+ /** Canonical BCP-47 locale identifier, e.g. `"en-AU"`. */
95
+ readonly locale: string;
96
+ /** Parsed language / script / region subtags. */
97
+ readonly subtags: Subtags;
98
+ /** Resolved modifiers (calendar / currency / timeZone). */
99
+ readonly modifiers: Required<Modifiers>;
100
+ private readonly intlLocale;
101
+ /**
102
+ * @param locale BCP-47 (or underscore-separated `en_AU`) locale identifier. Unicode
103
+ * extensions such as `-u-nu-latn-ca-buddhist` are honoured. Defaults to the
104
+ * runtime locale.
105
+ * @param modifiers Optional `calendar`, `currency`, and `timeZone` overrides.
106
+ */
107
+ constructor(locale?: string | null, modifiers?: Modifiers);
108
+ /**
109
+ * Builds a Cosmo from locale subtags instead of a string.
110
+ * @example Cosmo.fromSubtags({ language: "en", region: "AU" })
111
+ */
112
+ static fromSubtags(subtags: Partial<Subtags>, modifiers?: Modifiers): Cosmo;
113
+ /**
114
+ * Builds a Cosmo from an HTTP `Accept-Language` header, picking the
115
+ * highest-quality tag.
116
+ */
117
+ static fromAcceptLanguage(header: string, modifiers?: Modifiers): Cosmo;
118
+ private display;
119
+ /**
120
+ * Localised language name (e.g. `"en"` → `"English"`, in `fa` → `"انگلیسی"`).
121
+ * Accepts a bare language code or a full locale (the language subtag is used).
122
+ * Returns `""` for an empty/nullish argument.
123
+ */
124
+ language(code?: string | null): string;
125
+ /**
126
+ * Localised country/region name (e.g. `"AU"` → `"Australia"`).
127
+ * Accepts a region code or a locale containing one. Returns `""` when empty.
128
+ */
129
+ country(code?: string | null): string;
130
+ /**
131
+ * Localised script name (e.g. `"Latn"` → `"Latin"`). Defaults to the locale's
132
+ * script subtag. Returns `""` when there is no script.
133
+ */
134
+ script(code?: string | null): string;
135
+ /**
136
+ * Localised calendar name (e.g. `"buddhist"` → `"Buddhist Calendar"`).
137
+ * Returns `""` for an empty argument.
138
+ */
139
+ calendar(code: string): string;
140
+ /**
141
+ * Localised currency name (default) or symbol.
142
+ * @param code ISO 4217 code; defaults to the `currency` modifier.
143
+ * @param symbol When `true`, returns the standard (disambiguated) symbol — e.g.
144
+ * `"A$"` for AUD in `en-US`, not the ambiguous narrow `"$"`.
145
+ * @param strict Throw on an unknown currency instead of echoing the code back.
146
+ */
147
+ currency(code?: string | null, symbol?: boolean, strict?: boolean): string;
148
+ /** Text direction of the locale (or a given language): `"rtl"` or `"ltr"`. */
149
+ direction(language?: string | null): string;
150
+ /**
151
+ * Country flag emoji for a region (e.g. `"AU"` → `"🇦🇺"`). Defaults to the
152
+ * locale's region. Uses the Unicode regional-indicator transform, so no data
153
+ * table is involved.
154
+ */
155
+ flag(country?: string | null): string;
156
+ /**
157
+ * Formats a number using the locale's default decimal format.
158
+ * @param options Optional rounding/grouping controls ({@link NumberOptions}).
159
+ */
160
+ number(value: number, options?: NumberOptions): string;
161
+ /**
162
+ * Formats a fraction as a localised percentage (e.g. `0.2` → `"20%"`).
163
+ * @param precision Maximum fraction digits (default 3).
164
+ * @param options Optional rounding/grouping controls ({@link NumberOptions});
165
+ * an explicit `maximumFractionDigits` here overrides `precision`.
166
+ */
167
+ percentage(value: number, precision?: number, options?: NumberOptions): string;
168
+ /**
169
+ * Formats a monetary value.
170
+ *
171
+ * No currency is inferred from the region: the `Intl` API exposes no
172
+ * region→currency mapping, and this library bundles no data. Provide a
173
+ * currency code or set the `currency` modifier.
174
+ *
175
+ * @returns The formatted amount, or `""` when no currency is available
176
+ * (unless `strict`, which throws).
177
+ */
178
+ money(value: number, code?: string | null, options?: {
179
+ precision?: number;
180
+ strict?: boolean;
181
+ } & NumberOptions): string;
182
+ /**
183
+ * Returns a single localised number symbol that the `Intl` API exposes via
184
+ * `formatToParts` (decimal/group separators, percent, sign symbols, nan,
185
+ * infinity). Symbols ICU keeps internal (permille, pad escape, …) are not
186
+ * available and throw.
187
+ *
188
+ * @param name One of: `decimal`, `group`, `percent`, `minusSign`, `plusSign`,
189
+ * `nan`, `infinity`, `currency` (case/`_`-insensitive; `_separator`/`_symbol`
190
+ * suffixes are ignored).
191
+ */
192
+ symbol(name: string): string;
193
+ /**
194
+ * Formats a measurement with a localised unit (e.g. `2.19` gigabytes).
195
+ * @param category Informational unit category (e.g. `"digital"`); accepted for
196
+ * descriptive grouping but not required by `Intl`.
197
+ * @param unit The unit identifier, e.g. `"gigabyte"`, `"celsius"`, `"gram"`.
198
+ * Must be one of the units sanctioned by ECMA-402.
199
+ * @param value Numeric value.
200
+ * @param width `full`/`long` → long, `medium` → short, `short` → narrow.
201
+ * @throws CosmoError if the unit is not supported by `Intl`.
202
+ * @see https://tc39.es/ecma402/#table-sanctioned-single-unit-identifiers
203
+ */
204
+ unit(category: string, unit: string, value: number, width?: FormatWidth): string;
205
+ /** Formats an ICU MessageFormat pattern (subset: args, number, plural, select). */
206
+ message(pattern: string, args?: MessageArgs): string;
207
+ /**
208
+ * Formats an **undirected** duration (magnitude only) given in **seconds**.
209
+ * For the directed form (with a past/future orientation, e.g. "3 days ago")
210
+ * see {@link Cosmo.relativeDuration}.
211
+ * @param withWords When `true`, spells out the units (`"339 hours, …"`),
212
+ * otherwise uses the digital clock form (`"339:27:40"`).
213
+ *
214
+ * Requires `Intl.DurationFormat` (Node 22+). Both forms are produced entirely
215
+ * by ICU.
216
+ */
217
+ duration(value: number | DurationParts, withWords?: boolean): string;
218
+ private dateTimeFormat;
219
+ /**
220
+ * Formats a moment (date and/or time) using the locale's conventions.
221
+ * @param moment A `Date` or Unix-millisecond timestamp.
222
+ * @param dateWidth `none`/`short`/`medium`/`long`/`full` (default `short`).
223
+ * @param timeWidth `none`/`short`/`medium`/`long`/`full` (default `short`).
224
+ * @param calendar Pass `"gregorian"` to force Gregorian; otherwise the
225
+ * locale/modifier calendar is used.
226
+ */
227
+ moment(moment: Moment, dateWidth?: FormatWidth, timeWidth?: FormatWidth, calendar?: string | null): string;
228
+ /** Formats just the date part of a moment. */
229
+ date(moment: Moment, width?: FormatWidth): string;
230
+ /** Formats just the time (clock) part of a moment. */
231
+ time(moment: Moment, width?: FormatWidth): string;
232
+ /**
233
+ * Locale-aware comparison of two strings, suitable for `Array#sort`.
234
+ * Returns a negative number, `0`, or a positive number.
235
+ */
236
+ compare(a: string, b: string, options?: CollationOptions): number;
237
+ /**
238
+ * Returns a new array sorted by the locale's collation rules.
239
+ * @param key Optional accessor returning the string to sort each item by.
240
+ * @param options Optional collation tailoring ({@link CollationOptions}).
241
+ */
242
+ sort<T>(items: readonly T[], key?: (item: T) => string, options?: CollationOptions): T[];
243
+ /**
244
+ * Locale-aware substring test that honours the locale's collation, so
245
+ * accents/case can be ignored.
246
+ * @param sensitivity `base` (ignore case & accents, default), `accent`,
247
+ * `case`, or `variant` (exact). See `Intl.Collator`.
248
+ */
249
+ contains(haystack: string, needle: string, sensitivity?: "base" | "accent" | "case" | "variant", options?: CollationOptions): boolean;
250
+ /**
251
+ * Splits text into words using the locale's word-boundary rules, keeping only
252
+ * word-like segments (drops whitespace and punctuation). Mirrors ICU's
253
+ * word `BreakIterator`.
254
+ */
255
+ splitWords(text: string): string[];
256
+ /** Splits text into sentences using the locale's sentence-boundary rules. */
257
+ splitSentences(text: string): string[];
258
+ /**
259
+ * Truncates text to at most `max` graphemes, breaking on a word boundary and
260
+ * appending `ellipsis`. Grapheme- and word-aware via `Intl.Segmenter`, so it
261
+ * never splits a combining sequence. Returns the original text if it already
262
+ * fits.
263
+ */
264
+ ellipsize(text: string, max: number, ellipsis?: string): string;
265
+ /**
266
+ * Splits text into grapheme clusters (user-perceived characters), so combining
267
+ * marks and emoji ZWJ sequences stay intact. Mirrors `Intl.Segmenter`
268
+ * `granularity:"grapheme"`.
269
+ */
270
+ splitGraphemes(text: string): string[];
271
+ /**
272
+ * The LDML plural category a number falls into for this locale
273
+ * (e.g. `1` → `"one"`, `2` → `"other"` in English). Mirrors the category
274
+ * selection inside ICU `MessageFormat`.
275
+ * @param ordinal Use ordinal rules (1st/2nd/3rd …) instead of cardinal.
276
+ */
277
+ pluralCategory(value: number, ordinal?: boolean): PluralCategory;
278
+ /**
279
+ * Week conventions for the locale: first day of the week, weekend days, and
280
+ * the minimal days in the first week. Mirrors `IntlCalendar` accessors.
281
+ * @throws CosmoError if the runtime lacks `Intl.Locale#getWeekInfo`.
282
+ */
283
+ weekInfo(): WeekInfo;
284
+ /**
285
+ * Returns a new Cosmo with likely subtags added (e.g. `"en"` → `"en-Latn-US"`).
286
+ * Uses `Intl.Locale#maximize`.
287
+ */
288
+ addLikelySubtags(): Cosmo;
289
+ /**
290
+ * Returns a new Cosmo with likely subtags removed (e.g. `"en-Latn-US"` → `"en"`).
291
+ * Uses `Intl.Locale#minimize`.
292
+ */
293
+ removeLikelySubtags(): Cosmo;
294
+ /**
295
+ * Localised month names (January … December), following the active calendar.
296
+ * Mirrors `IntlDateFormatter` month symbols.
297
+ */
298
+ monthNames(width?: FormatWidth): string[];
299
+ /**
300
+ * Localised weekday names, **Sunday first** (matching ICU symbol order).
301
+ * Mirrors `IntlDateFormatter` weekday symbols.
302
+ */
303
+ weekdayNames(width?: FormatWidth): string[];
304
+ /**
305
+ * Localised display name of a time zone (e.g. `"Australian Eastern Standard Time"`).
306
+ * Defaults to the `timeZone` modifier, falling back to the runtime zone.
307
+ * @param style `long` (default), `short`, `shortOffset`, `longOffset`,
308
+ * `shortGeneric`, or `longGeneric`.
309
+ */
310
+ timeZoneName(style?: TimeZoneNameStyle): string;
311
+ /**
312
+ * Generic localised display name — a single entry point over the dedicated
313
+ * lookups. Mirrors `Intl.DisplayNames`.
314
+ * @param type `language`, `region`, `script`, `calendar`, or `currency`.
315
+ * @param code The code to translate (e.g. `"en"`, `"AU"`, `"Hans"`, `"buddhist"`, `"EUR"`).
316
+ */
317
+ displayName(type: DisplayType, code: string): string;
318
+ /**
319
+ * The values the runtime's ICU supports for a given key (e.g. all IANA time
320
+ * zones, calendars, currencies). Mirrors `Intl.supportedValuesOf`.
321
+ * @param key `calendar`, `collation`, `currency`, `numberingSystem`, `timeZone`, or `unit`.
322
+ */
323
+ supportedValues(key: SupportedKey): string[];
324
+ /** Locale-aware upper-casing (e.g. Turkish dotted/dotless I). */
325
+ upper(text: string): string;
326
+ /** Locale-aware lower-casing. */
327
+ lower(text: string): string;
328
+ /**
329
+ * Renders a **directed duration** — a signed amount carrying a past/future
330
+ * orientation — in the locale's words (e.g. `(-3, "day")` → `"3 days ago"`,
331
+ * `(2, "hour")` → `"in 2 hours"`). The directed counterpart of
332
+ * {@link Cosmo.duration}, which is undirected (magnitude only). Wraps
333
+ * `Intl.RelativeTimeFormat`.
334
+ * @param amount Signed amount: negative = past (`"… ago"`), positive = future
335
+ * (`"in …"`).
336
+ * @param unit `second`, `minute`, `hour`, `day`, `week`, `month`, `quarter`, `year`.
337
+ * @param numeric `always` (default, "1 day ago") or `auto` (allows "yesterday").
338
+ */
339
+ relativeDuration(amount: number, unit: Intl.RelativeTimeFormatUnit, numeric?: "always" | "auto"): string;
340
+ /**
341
+ * Renders the directed duration **between two moments** as relative text,
342
+ * auto-selecting the largest sensible unit (e.g. `"in 5 days"`,
343
+ * `"3 days ago"`). Computes `target − reference`, then formats via
344
+ * {@link Cosmo.relativeDuration}. JS-only.
345
+ * @param target The moment being described.
346
+ * @param reference The moment `target` is measured against. **Defaults to
347
+ * now.** When `target` is after `reference` the result is future (`"in …"`);
348
+ * when before, it is past (`"… ago"`).
349
+ * @param numeric `auto` (default, allows "yesterday") or `always`.
350
+ */
351
+ relativeDurationBetween(target: Moment, reference?: Moment, numeric?: "always" | "auto"): string;
352
+ /**
353
+ * Joins a list using the locale's conventions (e.g. `"A, B, and C"`).
354
+ * Mirrors `Intl.ListFormat`.
355
+ * @param type `conjunction` (and, default), `disjunction` (or), or `unit`.
356
+ * @param width maps to long/short/narrow list styles.
357
+ */
358
+ join(items: readonly string[], type?: ListType, width?: FormatWidth): string;
359
+ /**
360
+ * Compact number notation (e.g. `1200` → `"1.2K"`, or `"1.2 thousand"`).
361
+ * JS-only.
362
+ * @param width `full`/`long` → long words, otherwise short.
363
+ */
364
+ compact(value: number, width?: FormatWidth): string;
365
+ /** Scientific notation (e.g. `12345` → `"1.2345E4"`). Mirrors `NumberFormatter::SCIENTIFIC`. */
366
+ scientific(value: number): string;
367
+ /** Formats a numeric range (e.g. `"3–5"`). Uses `NumberFormat#formatRange`. JS-only. */
368
+ numberRange(start: number, end: number): string;
369
+ /**
370
+ * Formats a monetary range (e.g. `"$3.00 – $5.00"`). JS-only.
371
+ * @returns `""` when no currency is available (or throws if none and required).
372
+ */
373
+ moneyRange(start: number, end: number, code?: string | null): string;
374
+ /**
375
+ * Formats a moment range (e.g. `"2–5 Feb 2020"`). Uses `DateTimeFormat#formatRange`. JS-only.
376
+ * @param dateWidth Defaults to `medium` — `short` numeric dates read poorly as
377
+ * a range, so this differs from {@link Cosmo.date} (which defaults to `short`).
378
+ */
379
+ dateRange(start: Moment, end: Moment, dateWidth?: FormatWidth, timeWidth?: FormatWidth): string;
380
+ }
381
+ //# sourceMappingURL=cosmo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cosmo.d.ts","sourceRoot":"","sources":["../src/cosmo.ts"],"names":[],"mappings":"AAUA,OAAO,EAAiB,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAE/D,8EAA8E;AAC9E,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;AAExE,yEAAyE;AACzE,MAAM,WAAW,SAAS;IACxB,wEAAwE;IACxE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,iDAAiD;IACjD,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAED,uDAAuD;AACvD,MAAM,WAAW,OAAO;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,qGAAqG;AACrG,MAAM,MAAM,MAAM,GAAG,IAAI,GAAG,MAAM,CAAC;AAkBnC,sEAAsE;AACtE,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,KAAK,GAAG,KAAK,GAAG,KA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