@fedify/vocab-runtime 2.5.0-dev.2304 → 2.5.0-dev.2327
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/deno.json +1 -1
- package/dist/{contexts-BK1CqBR5.cjs → contexts-B09jb9Pi.cjs} +11 -1
- package/dist/{contexts-DPuJ4UYL.js → contexts-DWrj4AGR.js} +11 -1
- package/dist/{docloader-CYwqh5Df.d.cts → docloader-BMHljyYb.d.cts} +2 -0
- package/dist/{docloader-CYwqh5Df.d.ts → docloader-BMHljyYb.d.ts} +2 -0
- package/dist/internal/jsonld-cache.d.cts +1 -1
- package/dist/internal/jsonld-cache.d.ts +1 -1
- package/dist/internal/portable-dereference.cjs +1 -1
- package/dist/internal/portable-dereference.d.cts +2 -2
- package/dist/internal/portable-dereference.d.ts +2 -2
- package/dist/internal/portable-dereference.js +1 -1
- package/dist/internal/signed-representation.cjs +1 -1
- package/dist/internal/signed-representation.js +1 -1
- package/dist/mod.cjs +48 -4
- package/dist/mod.d.cts +25 -4
- package/dist/mod.d.ts +25 -4
- package/dist/mod.js +48 -5
- package/dist/{portable-DqtfLy_1.d.cts → portable-6Aj-7dZJ.d.cts} +1 -1
- package/dist/{portable-DtWsu2yU.d.ts → portable-nkTiqH0w.d.ts} +1 -1
- package/dist/tests/{body-DJbLKygS.mjs → body-B1gvksvz.mjs} +1 -1
- package/dist/tests/{body-DHxitVlM.cjs → body-DPcflIg_.cjs} +1 -1
- package/dist/tests/body.test.cjs +1 -1
- package/dist/tests/body.test.mjs +1 -1
- package/dist/tests/{contexts-DizzBjz4.cjs → contexts-C9Lj11SC.cjs} +11 -1
- package/dist/tests/{contexts-CIKsin4e.mjs → contexts-duRA_dDC.mjs} +11 -1
- package/dist/tests/decimal.test.cjs +4 -3
- package/dist/tests/decimal.test.mjs +4 -3
- package/dist/tests/{docloader-DMFCY7Tm.cjs → docloader-DL0C7__x.cjs} +5 -3
- package/dist/tests/{docloader-C86Xi_tE.mjs → docloader-Fe5rKpYM.mjs} +5 -3
- package/dist/tests/docloader.test.cjs +127 -3
- package/dist/tests/docloader.test.mjs +127 -3
- package/dist/tests/internal/portable-dereference.test.cjs +2 -2
- package/dist/tests/internal/portable-dereference.test.mjs +2 -2
- package/dist/tests/jsonld-CmDhHNTx.cjs +12 -0
- package/dist/tests/jsonld-DweIJ07b.mjs +5 -0
- package/dist/tests/{jsonld-cache-C07AyNOY.cjs → jsonld-cache-BEXiiM-V.cjs} +6 -17
- package/dist/tests/{jsonld-cache-BPQmOZWD.mjs → jsonld-cache-DFnWsLuZ.mjs} +2 -5
- package/dist/tests/jsonld-cache.test.cjs +13 -12
- package/dist/tests/jsonld-cache.test.mjs +2 -1
- package/dist/tests/{langstr-CQ26J_L7.mjs → langstr-Dw8IBDZl.mjs} +5 -2
- package/dist/tests/{langstr-C4Fl80ae.cjs → langstr-h89Kjekh.cjs} +5 -2
- package/dist/tests/langstr.test.cjs +8 -1
- package/dist/tests/langstr.test.mjs +9 -2
- package/dist/tests/langtag-CD3zHKPN.mjs +40 -0
- package/dist/tests/langtag-DASCPgl3.cjs +45 -0
- package/dist/tests/langtag.test.cjs +45 -0
- package/dist/tests/langtag.test.d.cts +1 -0
- package/dist/tests/langtag.test.d.mts +1 -0
- package/dist/tests/langtag.test.mjs +46 -0
- package/dist/tests/{portable-dereference-DRE5bz-l.mjs → portable-dereference-DmTYDy2p.mjs} +3 -2
- package/dist/tests/{portable-dereference-BNXtgg5U.cjs → portable-dereference-qTLMqe2_.cjs} +3 -2
- package/dist/tests/{portable-media-BMIgAOnu.mjs → portable-media-ChlisGkT.mjs} +2 -2
- package/dist/tests/{portable-media-CSWH-bM2.cjs → portable-media-FwLJfqLl.cjs} +2 -2
- package/dist/tests/portable-media.test.cjs +1 -1
- package/dist/tests/portable-media.test.mjs +1 -1
- package/dist/tests/portable-workers.test.cjs +1 -1
- package/dist/tests/portable-workers.test.mjs +1 -1
- package/dist/tests/{request-BjE8IOhe.cjs → request-CZzX339k.cjs} +1 -1
- package/dist/tests/{request-CGarmDOP.mjs → request-DG4GhpaX.mjs} +1 -1
- package/dist/tests/request.test.cjs +1 -1
- package/dist/tests/request.test.mjs +1 -1
- package/dist/tests/signed-representation.test.cjs +1 -1
- package/dist/tests/signed-representation.test.mjs +1 -1
- package/package.json +1 -1
- package/src/contexts/fep-6757.json +12 -0
- package/src/contexts/joinmastodon.json +1 -1
- package/src/contexts.ts +8 -0
- package/src/docloader.test.ts +148 -0
- package/src/docloader.ts +2 -0
- package/src/langstr.test.ts +18 -1
- package/src/langstr.ts +6 -2
- package/src/langtag.test.ts +53 -0
- package/src/langtag.ts +71 -0
- package/src/mod.ts +1 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { deepStrictEqual } from "node:assert";
|
|
2
|
+
import { test } from "node:test";
|
|
3
|
+
import { normalizeLanguageTag } from "./langtag.ts";
|
|
4
|
+
|
|
5
|
+
test("normalizeLanguageTag() removes extlang subtags", () => {
|
|
6
|
+
const cases: [string, string][] = [
|
|
7
|
+
["zh-yue", "yue"],
|
|
8
|
+
["zh-YUE", "yue"],
|
|
9
|
+
["ZH-Yue-hk", "yue-hk"],
|
|
10
|
+
["zh-yue-HK", "yue-HK"],
|
|
11
|
+
["zh-cmn-Hant", "cmn-Hant"],
|
|
12
|
+
["zh-yue-u-nu-hanidec", "yue-u-nu-hanidec"],
|
|
13
|
+
["sgn-ase", "ase"],
|
|
14
|
+
["ar-arz", "arz"],
|
|
15
|
+
["ms-zlm", "zlm"],
|
|
16
|
+
["kok-gom", "gom"],
|
|
17
|
+
["koK-gom", "gom"],
|
|
18
|
+
["lv-ltg", "ltg"],
|
|
19
|
+
["sw-swc", "swc"],
|
|
20
|
+
["uz-uzs", "uzs"],
|
|
21
|
+
// Valid tags never have more than one extlang, so only the first one is
|
|
22
|
+
// removed and the result is still rejected by Intl.Locale:
|
|
23
|
+
["zh-yue-cmn", "yue-cmn"],
|
|
24
|
+
["zh-yue-", "yue-"],
|
|
25
|
+
];
|
|
26
|
+
for (const [input, expected] of cases) {
|
|
27
|
+
deepStrictEqual(normalizeLanguageTag(input), expected, input);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("normalizeLanguageTag() leaves other tags unchanged", () => {
|
|
32
|
+
const tags = [
|
|
33
|
+
"",
|
|
34
|
+
"en",
|
|
35
|
+
"en-US",
|
|
36
|
+
"en-USA",
|
|
37
|
+
"en-yue",
|
|
38
|
+
"zh",
|
|
39
|
+
"zh-Hant-TW",
|
|
40
|
+
"yue",
|
|
41
|
+
"yue-HK",
|
|
42
|
+
"x-private",
|
|
43
|
+
"i-klingon",
|
|
44
|
+
"zh-min-nan",
|
|
45
|
+
"koK-gom",
|
|
46
|
+
"zh-yuK",
|
|
47
|
+
"constructor-yue",
|
|
48
|
+
"toString-yue",
|
|
49
|
+
];
|
|
50
|
+
for (const tag of tags) {
|
|
51
|
+
deepStrictEqual(normalizeLanguageTag(tag), tag, tag);
|
|
52
|
+
}
|
|
53
|
+
});
|
package/src/langtag.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extended language subtags (extlangs) registered in the IANA Language Subtag
|
|
3
|
+
* Registry, grouped by their prefixes. Every extlang record has exactly one
|
|
4
|
+
* prefix and a `Preferred-Value` equal to the extlang subtag itself, so
|
|
5
|
+
* replacing the prefix and the extlang with the extlang alone yields
|
|
6
|
+
* the canonical form.
|
|
7
|
+
*
|
|
8
|
+
* Generated from the registry with File-Date: 2026-09-17.
|
|
9
|
+
*/
|
|
10
|
+
const EXTLANGS: Record<string, string> = {
|
|
11
|
+
ar: "aao abh abv acm acq acw acx acy adf aeb aec afb ajp apc apd arb arq " +
|
|
12
|
+
"ars ary arz auz avl ayh ayl ayn ayp bbz pga shu ssh",
|
|
13
|
+
kok: "gom knn",
|
|
14
|
+
lv: "ltg lvs",
|
|
15
|
+
ms: "bjn btj bve bvu coa dup hji jak jax kvb kvr kxd lce lcf liw max meo " +
|
|
16
|
+
"mfa mfb min mqg msi mui orn ors pel pse tmw urk vkk vkt xmm zlm zmi " +
|
|
17
|
+
"zsm",
|
|
18
|
+
sgn: "ads aed aen afg ajs ase asf asp asq asw bfi bfk bog bqn bqy bvl bzs " +
|
|
19
|
+
"cds csc csd cse csf csg csl csn csq csr csx doq dse dsl dsz dyl ecs " +
|
|
20
|
+
"ehs esl esn eso eth fcs fse fsl fss gds gse gsg gsm gss gus hab haf " +
|
|
21
|
+
"hds hks hos hps hsh hsl icl iks ils inl ins ise isg isr jcs jhs jks " +
|
|
22
|
+
"jls jos jsl jus kgi kvk lbs lgs lls lsb lsc lsg lsl lsn lso lsp lst " +
|
|
23
|
+
"lsv lsw lsy lws mdl mfs mre msd msr mzc mzg mzy nbs ncs nsi nsl nsp " +
|
|
24
|
+
"nsr nzs okl pgz pks prl prz psc psd psg psl pso psp psr pys rib rms " +
|
|
25
|
+
"rnb rsi rsl rsm rsn sdl sfb sfs sgg sgx slf sls sqk sqs sqx ssp ssr " +
|
|
26
|
+
"svk swl syy szs tse tsm tsq tss tsy tza ugn ugy ukl uks vgt vsi vsl " +
|
|
27
|
+
"vsv wbs xki xml xms yds ygs yhs ysl ysm zhk zib zsl",
|
|
28
|
+
sw: "swc swh",
|
|
29
|
+
uz: "uzn uzs",
|
|
30
|
+
zh: "cdo cjy cmn cnp cpx csp czh czo gan hak hnm hsn luh lzh mnp nan sjc " +
|
|
31
|
+
"wuu yue",
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const EXTLANG_PAIRS: ReadonlySet<string> = new Set(
|
|
35
|
+
Object.entries(EXTLANGS).flatMap(([prefix, extlangs]) =>
|
|
36
|
+
extlangs.split(" ").map((extlang) => `${prefix}-${extlang}`)
|
|
37
|
+
),
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
const PREFIX_PATTERN = /^[A-Za-z]{2,3}$/;
|
|
41
|
+
const EXTLANG_PATTERN = /^[A-Za-z]{3}$/;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Normalizes a BCP 47 language tag that has an extended language subtag
|
|
45
|
+
* (extlang), such as `zh-yue`, into its canonical form, such as `yue`, as
|
|
46
|
+
* described in [RFC 5646, Section 4.5][1]. `Intl.Locale` rejects extlang
|
|
47
|
+
* tags, so tags should be normalized before being passed to it.
|
|
48
|
+
*
|
|
49
|
+
* Only registered extlangs that follow their registered prefix are removed;
|
|
50
|
+
* any other tag is returned unchanged, so the result still needs to be
|
|
51
|
+
* validated, e.g., by `Intl.Locale`.
|
|
52
|
+
*
|
|
53
|
+
* [1]: https://www.rfc-editor.org/rfc/rfc5646.html#section-4.5
|
|
54
|
+
*
|
|
55
|
+
* @param tag The BCP 47 language tag to normalize.
|
|
56
|
+
* @returns The normalized language tag.
|
|
57
|
+
* @since 2.5.0
|
|
58
|
+
*/
|
|
59
|
+
export function normalizeLanguageTag(tag: string): string {
|
|
60
|
+
const subtags = tag.split("-");
|
|
61
|
+
if (subtags.length < 2) return tag;
|
|
62
|
+
const [prefix, extlang, ...rest] = subtags;
|
|
63
|
+
// Checked before case folding, since `toLowerCase()` maps some non-ASCII
|
|
64
|
+
// characters (e.g., U+212A KELVIN SIGN) to ASCII letters:
|
|
65
|
+
if (!PREFIX_PATTERN.test(prefix) || !EXTLANG_PATTERN.test(extlang)) {
|
|
66
|
+
return tag;
|
|
67
|
+
}
|
|
68
|
+
const language = extlang.toLowerCase();
|
|
69
|
+
if (!EXTLANG_PAIRS.has(`${prefix.toLowerCase()}-${language}`)) return tag;
|
|
70
|
+
return [language, ...rest].join("-");
|
|
71
|
+
}
|