@eldrajs/sdk 0.2.8 → 0.2.9
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/CHANGELOG.md +6 -0
- package/README.md +21 -0
- package/THIRD-PARTY-NOTICES.md +18 -0
- package/dist/format/date.d.ts +4 -0
- package/dist/format/date.js +12214 -0
- package/dist/format/display-names.d.ts +4 -0
- package/dist/format/display-names.js +4905 -0
- package/dist/format/list.d.ts +4 -0
- package/dist/format/list.js +902 -0
- package/dist/format/relative-time.d.ts +4 -0
- package/dist/format/relative-time.js +1546 -0
- package/dist/format.d.ts +12 -0
- package/dist/format.js +72 -0
- package/dist/locale-DOZdbAbY.js +4011 -0
- package/dist/number-D3Vt6TOL.js +9585 -0
- package/package.json +32 -3
package/dist/format.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/format/compare.d.ts
|
|
2
|
+
/** Icelandic alphabetical order (`Intl.Collator('is')`), for runtimes that ship without it. */
|
|
3
|
+
export declare function compareIcelandic(a: string, b: string): number;
|
|
4
|
+
/** A sort comparator for `locale`: Icelandic order from {@link compareIcelandic}, any other from the runtime. */
|
|
5
|
+
export declare function comparator(locale: string): (a: string, b: string) => number;
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/format/number.d.ts
|
|
8
|
+
/** `new Intl.NumberFormat(locale, options)` with the same text on every runtime, Chrome and Workers included. */
|
|
9
|
+
export declare function numberFormat(locale: string, options?: Intl.NumberFormatOptions): Intl.NumberFormat;
|
|
10
|
+
/** A price in major units, the way every Eldra surface writes it: `12.900 kr.`, `ISK 12,900`. */
|
|
11
|
+
export declare function formatPrice(amount: number, currency: string, locale: string): string;
|
|
12
|
+
//#endregion
|
package/dist/format.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { n as numberFormat, t as formatPrice } from "./number-D3Vt6TOL.js";
|
|
2
|
+
//#region src/format/compare.ts
|
|
3
|
+
const PUNCTUATION = " \xA0_-–—,;:!¡?¿.…·'‘’\"“”„«»()[]{}§@*/\\&#%`^°+÷×<=>|~$£€";
|
|
4
|
+
const LETTERS = "aábcdðeéfghiíjklłmnoópqrstuúvwxyýzþæöå";
|
|
5
|
+
const IGNORED = /* @__PURE__ */ new Set([
|
|
6
|
+
"",
|
|
7
|
+
"",
|
|
8
|
+
"",
|
|
9
|
+
"",
|
|
10
|
+
"",
|
|
11
|
+
""
|
|
12
|
+
]);
|
|
13
|
+
const SECONDARY_OF = {
|
|
14
|
+
ä: "æ",
|
|
15
|
+
ø: "ö",
|
|
16
|
+
đ: "d"
|
|
17
|
+
};
|
|
18
|
+
const EXPANSIONS = {
|
|
19
|
+
ß: "ss",
|
|
20
|
+
œ: "oe"
|
|
21
|
+
};
|
|
22
|
+
const DIGITS_AT = 54;
|
|
23
|
+
const LETTERS_AT = 64;
|
|
24
|
+
const OTHER_AT = 102;
|
|
25
|
+
function key(text) {
|
|
26
|
+
const result = [
|
|
27
|
+
[],
|
|
28
|
+
[],
|
|
29
|
+
[]
|
|
30
|
+
];
|
|
31
|
+
for (const char of text.normalize("NFC")) {
|
|
32
|
+
if (IGNORED.has(char)) continue;
|
|
33
|
+
const lower = char.toLowerCase();
|
|
34
|
+
const expansion = EXPANSIONS[lower];
|
|
35
|
+
const tertiary = (char === lower ? 0 : 1) + (expansion ? 2 : 0);
|
|
36
|
+
for (const unit of expansion ?? lower) {
|
|
37
|
+
const [primary, secondary] = weigh(unit);
|
|
38
|
+
result[0].push(primary);
|
|
39
|
+
result[1].push(secondary);
|
|
40
|
+
result[2].push(tertiary);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
function weigh(char) {
|
|
46
|
+
const letter = LETTERS.indexOf(char);
|
|
47
|
+
if (letter >= 0) return [LETTERS_AT + letter, 0];
|
|
48
|
+
const base = SECONDARY_OF[char] ?? char.normalize("NFD")[0] ?? char;
|
|
49
|
+
const accented = LETTERS.indexOf(base);
|
|
50
|
+
if (accented >= 0) return [LETTERS_AT + accented, char.codePointAt(0) ?? 0];
|
|
51
|
+
if (char >= "0" && char <= "9") return [DIGITS_AT + Number(char), 0];
|
|
52
|
+
const mark = PUNCTUATION.indexOf(char);
|
|
53
|
+
if (mark >= 0) return [mark, 0];
|
|
54
|
+
return [OTHER_AT + (char.codePointAt(0) ?? 0), 0];
|
|
55
|
+
}
|
|
56
|
+
function compareWeights(a, b) {
|
|
57
|
+
const length = Math.min(a.length, b.length);
|
|
58
|
+
for (let i = 0; i < length; i++) if (a[i] !== b[i]) return (a[i] ?? 0) - (b[i] ?? 0);
|
|
59
|
+
return a.length - b.length;
|
|
60
|
+
}
|
|
61
|
+
/** Icelandic alphabetical order (`Intl.Collator('is')`), for runtimes that ship without it. */
|
|
62
|
+
function compareIcelandic(a, b) {
|
|
63
|
+
const [ka, kb] = [key(a), key(b)];
|
|
64
|
+
return Math.sign(compareWeights(ka[0], kb[0]) || compareWeights(ka[1], kb[1]) || compareWeights(ka[2], kb[2]));
|
|
65
|
+
}
|
|
66
|
+
/** A sort comparator for `locale`: Icelandic order from {@link compareIcelandic}, any other from the runtime. */
|
|
67
|
+
function comparator(locale) {
|
|
68
|
+
if ((Intl.getCanonicalLocales(locale)[0] ?? locale).split("-")[0] === "is") return compareIcelandic;
|
|
69
|
+
return new Intl.Collator(locale).compare;
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
72
|
+
export { comparator, compareIcelandic, formatPrice, numberFormat };
|