@siteimprove/alfa-iana 0.89.5
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 +155 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/language/data.d.ts +27873 -0
- package/dist/language/data.js +9740 -0
- package/dist/language.d.ts +187 -0
- package/dist/language.js +331 -0
- package/package.json +43 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import type { Equatable } from "@siteimprove/alfa-equatable";
|
|
2
|
+
import type { Serializable } from "@siteimprove/alfa-json";
|
|
3
|
+
import { Option } from "@siteimprove/alfa-option";
|
|
4
|
+
import { Result } from "@siteimprove/alfa-result";
|
|
5
|
+
import type * as json from "@siteimprove/alfa-json";
|
|
6
|
+
import { Languages } from "./language/data.js";
|
|
7
|
+
/**
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export declare class Language implements Equatable, Serializable {
|
|
11
|
+
static of(primary: Language.Primary, extended?: Option<Language.Extended>, script?: Option<Language.Script>, region?: Option<Language.Region>, variants?: Array<Language.Variant>): Language;
|
|
12
|
+
private readonly _primary;
|
|
13
|
+
private readonly _extended;
|
|
14
|
+
private readonly _script;
|
|
15
|
+
private readonly _region;
|
|
16
|
+
private readonly _variants;
|
|
17
|
+
constructor(primary: Language.Primary, extended: Option<Language.Extended>, script: Option<Language.Script>, region: Option<Language.Region>, variants: Array<Language.Variant>);
|
|
18
|
+
get primary(): Language.Primary;
|
|
19
|
+
get extended(): Option<Language.Extended>;
|
|
20
|
+
get script(): Option<Language.Script>;
|
|
21
|
+
get region(): Option<Language.Region>;
|
|
22
|
+
get variants(): Iterable<Language.Variant>;
|
|
23
|
+
equals(value: unknown): value is this;
|
|
24
|
+
toJSON(): Language.JSON;
|
|
25
|
+
toString(): string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
export declare namespace Language {
|
|
31
|
+
interface JSON {
|
|
32
|
+
[key: string]: json.JSON;
|
|
33
|
+
type: "language";
|
|
34
|
+
primary: Primary.JSON;
|
|
35
|
+
extended: Extended.JSON | null;
|
|
36
|
+
script: Script.JSON | null;
|
|
37
|
+
region: Region.JSON | null;
|
|
38
|
+
variants: Array<Variant.JSON>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* {@link https://tools.ietf.org/html/bcp47#section-3.1.11}
|
|
42
|
+
*/
|
|
43
|
+
type Scope = Exclude<Languages["primary"][Primary.Name]["scope"], null>;
|
|
44
|
+
/**
|
|
45
|
+
* {@link https://tools.ietf.org/html/bcp47#section-3.1.2}
|
|
46
|
+
*/
|
|
47
|
+
abstract class Subtag<T extends string = string, N extends string = string> implements Equatable, Serializable<Subtag.JSON<T, N>> {
|
|
48
|
+
protected readonly _name: N;
|
|
49
|
+
protected constructor(name: N);
|
|
50
|
+
/**
|
|
51
|
+
* {@link https://tools.ietf.org/html/bcp47#section-3.1.3}
|
|
52
|
+
*/
|
|
53
|
+
abstract get type(): T;
|
|
54
|
+
/**
|
|
55
|
+
* {@link https://tools.ietf.org/html/bcp47#section-3.1.4}
|
|
56
|
+
*/
|
|
57
|
+
get name(): N;
|
|
58
|
+
abstract equals<T extends string, N extends string>(value: Subtag<T, N>): boolean;
|
|
59
|
+
abstract equals(value: unknown): value is this;
|
|
60
|
+
abstract toJSON(): Subtag.JSON<T, N>;
|
|
61
|
+
toString(): string;
|
|
62
|
+
}
|
|
63
|
+
namespace Subtag {
|
|
64
|
+
interface JSON<T extends string = string, N extends string = string> {
|
|
65
|
+
[key: string]: json.JSON;
|
|
66
|
+
type: T;
|
|
67
|
+
name: N;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* {@link https://tools.ietf.org/html/bcp47#section-2.2.1}
|
|
72
|
+
*/
|
|
73
|
+
class Primary extends Subtag<"primary", Primary.Name> {
|
|
74
|
+
static of(name: Primary.Name): Primary;
|
|
75
|
+
private constructor();
|
|
76
|
+
get type(): "primary";
|
|
77
|
+
/**
|
|
78
|
+
* {@link https://tools.ietf.org/html/bcp47#section-3.1.11}
|
|
79
|
+
*/
|
|
80
|
+
get scope(): Option<Scope>;
|
|
81
|
+
equals(value: Primary): boolean;
|
|
82
|
+
equals(value: unknown): value is this;
|
|
83
|
+
toJSON(): Primary.JSON;
|
|
84
|
+
}
|
|
85
|
+
namespace Primary {
|
|
86
|
+
type Name = keyof Languages["primary"];
|
|
87
|
+
interface JSON extends Subtag.JSON<"primary", Name> {
|
|
88
|
+
scope: Scope | null;
|
|
89
|
+
}
|
|
90
|
+
function isPrimary(value: unknown): value is Primary;
|
|
91
|
+
function isName(name: string): name is Name;
|
|
92
|
+
}
|
|
93
|
+
const primary: typeof Primary.of, isPrimary: typeof Primary.isPrimary, isPrimaryName: typeof Primary.isName;
|
|
94
|
+
/**
|
|
95
|
+
* {@link https://tools.ietf.org/html/bcp47#section-2.2.2}
|
|
96
|
+
*/
|
|
97
|
+
class Extended extends Subtag<"extended", Extended.Name> {
|
|
98
|
+
static of(name: Extended.Name): Extended;
|
|
99
|
+
private constructor();
|
|
100
|
+
get type(): "extended";
|
|
101
|
+
/**
|
|
102
|
+
* {@link https://tools.ietf.org/html/bcp47#section-3.1.8}
|
|
103
|
+
*/
|
|
104
|
+
get prefix(): Primary.Name;
|
|
105
|
+
equals(value: Extended): boolean;
|
|
106
|
+
equals(value: unknown): value is this;
|
|
107
|
+
toJSON(): Extended.JSON;
|
|
108
|
+
}
|
|
109
|
+
namespace Extended {
|
|
110
|
+
type Name = keyof Languages["extended"];
|
|
111
|
+
interface JSON extends Subtag.JSON<"extended", Name> {
|
|
112
|
+
prefix: Primary.Name;
|
|
113
|
+
}
|
|
114
|
+
function isExtended(value: unknown): value is Extended;
|
|
115
|
+
function isName(name: string): name is Name;
|
|
116
|
+
}
|
|
117
|
+
const extended: typeof Extended.of, isExtended: typeof Extended.isExtended, isExtendedName: typeof Extended.isName;
|
|
118
|
+
/**
|
|
119
|
+
* {@link https://tools.ietf.org/html/bcp47#section-2.2.3}
|
|
120
|
+
*/
|
|
121
|
+
class Script extends Subtag<"script", Script.Name> {
|
|
122
|
+
static of(name: Script.Name): Script;
|
|
123
|
+
private constructor();
|
|
124
|
+
get type(): "script";
|
|
125
|
+
equals(value: Script): boolean;
|
|
126
|
+
equals(value: unknown): value is this;
|
|
127
|
+
toJSON(): Script.JSON;
|
|
128
|
+
}
|
|
129
|
+
namespace Script {
|
|
130
|
+
type Name = keyof Languages["script"];
|
|
131
|
+
interface JSON extends Subtag.JSON<"script", Name> {
|
|
132
|
+
}
|
|
133
|
+
function isScript(value: unknown): value is Script;
|
|
134
|
+
function isName(name: string): name is Name;
|
|
135
|
+
}
|
|
136
|
+
const script: typeof Script.of, isScript: typeof Script.isScript, isScriptName: typeof Script.isName;
|
|
137
|
+
/**
|
|
138
|
+
* {@link https://tools.ietf.org/html/bcp47#section-2.2.4}
|
|
139
|
+
*/
|
|
140
|
+
class Region extends Subtag<"region", Region.Name> {
|
|
141
|
+
static of(name: Region.Name): Region;
|
|
142
|
+
private constructor();
|
|
143
|
+
get type(): "region";
|
|
144
|
+
equals(value: Region): boolean;
|
|
145
|
+
equals(value: unknown): value is this;
|
|
146
|
+
toJSON(): Region.JSON;
|
|
147
|
+
}
|
|
148
|
+
namespace Region {
|
|
149
|
+
type Name = keyof Languages["region"];
|
|
150
|
+
interface JSON extends Subtag.JSON<"region", Name> {
|
|
151
|
+
}
|
|
152
|
+
function isRegion(value: unknown): value is Region;
|
|
153
|
+
function isName(name: string): name is Name;
|
|
154
|
+
}
|
|
155
|
+
const region: typeof Region.of, isRegion: typeof Region.isRegion, isRegionName: typeof Region.isName;
|
|
156
|
+
/**
|
|
157
|
+
* {@link https://tools.ietf.org/html/bcp47#section-2.2.5}
|
|
158
|
+
*/
|
|
159
|
+
class Variant extends Subtag<"variant", Variant.Name> {
|
|
160
|
+
static of(name: Variant.Name): Variant;
|
|
161
|
+
private constructor();
|
|
162
|
+
get type(): "variant";
|
|
163
|
+
/**
|
|
164
|
+
* {@link https://tools.ietf.org/html/bcp47#section-3.1.8}
|
|
165
|
+
*/
|
|
166
|
+
get prefixes(): ReadonlyArray<string>;
|
|
167
|
+
equals(value: Variant): boolean;
|
|
168
|
+
equals(value: unknown): value is this;
|
|
169
|
+
toJSON(): Variant.JSON;
|
|
170
|
+
}
|
|
171
|
+
namespace Variant {
|
|
172
|
+
type Name = keyof Languages["variant"];
|
|
173
|
+
interface JSON extends Subtag.JSON<"variant", Name> {
|
|
174
|
+
prefixes: Array<string>;
|
|
175
|
+
}
|
|
176
|
+
function isVariant(value: unknown): value is Variant;
|
|
177
|
+
function isName(name: string): name is Name;
|
|
178
|
+
}
|
|
179
|
+
const variant: typeof Variant.of, isVariant: typeof Variant.isVariant, isVariantName: typeof Variant.isName;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* @public
|
|
183
|
+
*/
|
|
184
|
+
export declare namespace Language {
|
|
185
|
+
function parse(input: string): Result<Language, string>;
|
|
186
|
+
}
|
|
187
|
+
//# sourceMappingURL=language.d.ts.map
|
package/dist/language.js
ADDED
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
import { Option, None } from "@siteimprove/alfa-option";
|
|
2
|
+
import { Result, Err } from "@siteimprove/alfa-result";
|
|
3
|
+
import { Slice } from "@siteimprove/alfa-slice";
|
|
4
|
+
import { Languages } from "./language/data.js";
|
|
5
|
+
/**
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export class Language {
|
|
9
|
+
static of(primary, extended = None, script = None, region = None, variants = []) {
|
|
10
|
+
return new Language(primary, extended, script, region, variants);
|
|
11
|
+
}
|
|
12
|
+
_primary;
|
|
13
|
+
_extended;
|
|
14
|
+
_script;
|
|
15
|
+
_region;
|
|
16
|
+
_variants;
|
|
17
|
+
constructor(primary, extended, script, region, variants) {
|
|
18
|
+
this._primary = primary;
|
|
19
|
+
this._extended = extended;
|
|
20
|
+
this._script = script;
|
|
21
|
+
this._region = region;
|
|
22
|
+
this._variants = variants;
|
|
23
|
+
}
|
|
24
|
+
get primary() {
|
|
25
|
+
return this._primary;
|
|
26
|
+
}
|
|
27
|
+
get extended() {
|
|
28
|
+
return this._extended;
|
|
29
|
+
}
|
|
30
|
+
get script() {
|
|
31
|
+
return this._script;
|
|
32
|
+
}
|
|
33
|
+
get region() {
|
|
34
|
+
return this._region;
|
|
35
|
+
}
|
|
36
|
+
get variants() {
|
|
37
|
+
return this._variants;
|
|
38
|
+
}
|
|
39
|
+
equals(value) {
|
|
40
|
+
return (value instanceof Language &&
|
|
41
|
+
value._primary.equals(this._primary) &&
|
|
42
|
+
value._extended.equals(this._extended) &&
|
|
43
|
+
value._script.equals(this._script) &&
|
|
44
|
+
value._region.equals(this._region) &&
|
|
45
|
+
value._variants.length === this._variants.length &&
|
|
46
|
+
value._variants.every((variant, i) => variant.equals(this._variants[i])));
|
|
47
|
+
}
|
|
48
|
+
toJSON() {
|
|
49
|
+
return {
|
|
50
|
+
type: "language",
|
|
51
|
+
primary: this._primary.toJSON(),
|
|
52
|
+
extended: this._extended.map((extended) => extended.toJSON()).getOr(null),
|
|
53
|
+
script: this._script.map((script) => script.toJSON()).getOr(null),
|
|
54
|
+
region: this._region.map((region) => region.toJSON()).getOr(null),
|
|
55
|
+
variants: this._variants.map((variant) => variant.toJSON()),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
toString() {
|
|
59
|
+
return [
|
|
60
|
+
this._primary,
|
|
61
|
+
...this._extended,
|
|
62
|
+
...this._script,
|
|
63
|
+
...this._region,
|
|
64
|
+
...this._variants,
|
|
65
|
+
].join("-");
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* @public
|
|
70
|
+
*/
|
|
71
|
+
(function (Language) {
|
|
72
|
+
/**
|
|
73
|
+
* {@link https://tools.ietf.org/html/bcp47#section-3.1.2}
|
|
74
|
+
*/
|
|
75
|
+
class Subtag {
|
|
76
|
+
_name;
|
|
77
|
+
constructor(name) {
|
|
78
|
+
this._name = name;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* {@link https://tools.ietf.org/html/bcp47#section-3.1.4}
|
|
82
|
+
*/
|
|
83
|
+
get name() {
|
|
84
|
+
return this._name;
|
|
85
|
+
}
|
|
86
|
+
toString() {
|
|
87
|
+
return this._name;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
Language.Subtag = Subtag;
|
|
91
|
+
/**
|
|
92
|
+
* {@link https://tools.ietf.org/html/bcp47#section-2.2.1}
|
|
93
|
+
*/
|
|
94
|
+
class Primary extends Subtag {
|
|
95
|
+
static of(name) {
|
|
96
|
+
return new Primary(name);
|
|
97
|
+
}
|
|
98
|
+
constructor(name) {
|
|
99
|
+
super(name);
|
|
100
|
+
}
|
|
101
|
+
get type() {
|
|
102
|
+
return "primary";
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* {@link https://tools.ietf.org/html/bcp47#section-3.1.11}
|
|
106
|
+
*/
|
|
107
|
+
get scope() {
|
|
108
|
+
return Option.from(Languages.primary[this._name].scope);
|
|
109
|
+
}
|
|
110
|
+
equals(value) {
|
|
111
|
+
return value instanceof Primary && value._name === this._name;
|
|
112
|
+
}
|
|
113
|
+
toJSON() {
|
|
114
|
+
return {
|
|
115
|
+
type: "primary",
|
|
116
|
+
name: this._name,
|
|
117
|
+
scope: this.scope.getOr(null),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
Language.Primary = Primary;
|
|
122
|
+
(function (Primary) {
|
|
123
|
+
function isPrimary(value) {
|
|
124
|
+
return value instanceof Primary;
|
|
125
|
+
}
|
|
126
|
+
Primary.isPrimary = isPrimary;
|
|
127
|
+
function isName(name) {
|
|
128
|
+
return name in Languages.primary;
|
|
129
|
+
}
|
|
130
|
+
Primary.isName = isName;
|
|
131
|
+
})(Primary = Language.Primary || (Language.Primary = {}));
|
|
132
|
+
Language.primary = Primary.of, Language.isPrimary = Primary.isPrimary, Language.isPrimaryName = Primary.isName;
|
|
133
|
+
/**
|
|
134
|
+
* {@link https://tools.ietf.org/html/bcp47#section-2.2.2}
|
|
135
|
+
*/
|
|
136
|
+
class Extended extends Subtag {
|
|
137
|
+
static of(name) {
|
|
138
|
+
return new Extended(name);
|
|
139
|
+
}
|
|
140
|
+
constructor(name) {
|
|
141
|
+
super(name);
|
|
142
|
+
}
|
|
143
|
+
get type() {
|
|
144
|
+
return "extended";
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* {@link https://tools.ietf.org/html/bcp47#section-3.1.8}
|
|
148
|
+
*/
|
|
149
|
+
get prefix() {
|
|
150
|
+
return Languages.extended[this._name].prefix;
|
|
151
|
+
}
|
|
152
|
+
equals(value) {
|
|
153
|
+
return value instanceof Extended && value._name === this._name;
|
|
154
|
+
}
|
|
155
|
+
toJSON() {
|
|
156
|
+
return {
|
|
157
|
+
type: "extended",
|
|
158
|
+
name: this._name,
|
|
159
|
+
prefix: this.prefix,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
Language.Extended = Extended;
|
|
164
|
+
(function (Extended) {
|
|
165
|
+
function isExtended(value) {
|
|
166
|
+
return value instanceof Extended;
|
|
167
|
+
}
|
|
168
|
+
Extended.isExtended = isExtended;
|
|
169
|
+
function isName(name) {
|
|
170
|
+
return name in Languages.extended;
|
|
171
|
+
}
|
|
172
|
+
Extended.isName = isName;
|
|
173
|
+
})(Extended = Language.Extended || (Language.Extended = {}));
|
|
174
|
+
Language.extended = Extended.of, Language.isExtended = Extended.isExtended, Language.isExtendedName = Extended.isName;
|
|
175
|
+
/**
|
|
176
|
+
* {@link https://tools.ietf.org/html/bcp47#section-2.2.3}
|
|
177
|
+
*/
|
|
178
|
+
class Script extends Subtag {
|
|
179
|
+
static of(name) {
|
|
180
|
+
return new Script(name);
|
|
181
|
+
}
|
|
182
|
+
constructor(name) {
|
|
183
|
+
super(name);
|
|
184
|
+
}
|
|
185
|
+
get type() {
|
|
186
|
+
return "script";
|
|
187
|
+
}
|
|
188
|
+
equals(value) {
|
|
189
|
+
return value instanceof Script && value._name === this._name;
|
|
190
|
+
}
|
|
191
|
+
toJSON() {
|
|
192
|
+
return {
|
|
193
|
+
type: "script",
|
|
194
|
+
name: this._name,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
Language.Script = Script;
|
|
199
|
+
(function (Script) {
|
|
200
|
+
function isScript(value) {
|
|
201
|
+
return value instanceof Script;
|
|
202
|
+
}
|
|
203
|
+
Script.isScript = isScript;
|
|
204
|
+
function isName(name) {
|
|
205
|
+
return name in Languages.script;
|
|
206
|
+
}
|
|
207
|
+
Script.isName = isName;
|
|
208
|
+
})(Script = Language.Script || (Language.Script = {}));
|
|
209
|
+
Language.script = Script.of, Language.isScript = Script.isScript, Language.isScriptName = Script.isName;
|
|
210
|
+
/**
|
|
211
|
+
* {@link https://tools.ietf.org/html/bcp47#section-2.2.4}
|
|
212
|
+
*/
|
|
213
|
+
class Region extends Subtag {
|
|
214
|
+
static of(name) {
|
|
215
|
+
return new Region(name);
|
|
216
|
+
}
|
|
217
|
+
constructor(name) {
|
|
218
|
+
super(name);
|
|
219
|
+
}
|
|
220
|
+
get type() {
|
|
221
|
+
return "region";
|
|
222
|
+
}
|
|
223
|
+
equals(value) {
|
|
224
|
+
return value instanceof Region && value._name === this._name;
|
|
225
|
+
}
|
|
226
|
+
toJSON() {
|
|
227
|
+
return {
|
|
228
|
+
type: "region",
|
|
229
|
+
name: this._name,
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
Language.Region = Region;
|
|
234
|
+
(function (Region) {
|
|
235
|
+
function isRegion(value) {
|
|
236
|
+
return value instanceof Region;
|
|
237
|
+
}
|
|
238
|
+
Region.isRegion = isRegion;
|
|
239
|
+
function isName(name) {
|
|
240
|
+
return name in Languages.region;
|
|
241
|
+
}
|
|
242
|
+
Region.isName = isName;
|
|
243
|
+
})(Region = Language.Region || (Language.Region = {}));
|
|
244
|
+
Language.region = Region.of, Language.isRegion = Region.isRegion, Language.isRegionName = Region.isName;
|
|
245
|
+
/**
|
|
246
|
+
* {@link https://tools.ietf.org/html/bcp47#section-2.2.5}
|
|
247
|
+
*/
|
|
248
|
+
class Variant extends Subtag {
|
|
249
|
+
static of(name) {
|
|
250
|
+
return new Variant(name);
|
|
251
|
+
}
|
|
252
|
+
constructor(name) {
|
|
253
|
+
super(name);
|
|
254
|
+
}
|
|
255
|
+
get type() {
|
|
256
|
+
return "variant";
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* {@link https://tools.ietf.org/html/bcp47#section-3.1.8}
|
|
260
|
+
*/
|
|
261
|
+
get prefixes() {
|
|
262
|
+
return Languages.variant[this._name].prefixes;
|
|
263
|
+
}
|
|
264
|
+
equals(value) {
|
|
265
|
+
return value instanceof Variant && value._name === this._name;
|
|
266
|
+
}
|
|
267
|
+
toJSON() {
|
|
268
|
+
return {
|
|
269
|
+
type: "variant",
|
|
270
|
+
name: this._name,
|
|
271
|
+
prefixes: [...this.prefixes],
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
Language.Variant = Variant;
|
|
276
|
+
(function (Variant) {
|
|
277
|
+
function isVariant(value) {
|
|
278
|
+
return value instanceof Variant;
|
|
279
|
+
}
|
|
280
|
+
Variant.isVariant = isVariant;
|
|
281
|
+
function isName(name) {
|
|
282
|
+
return name in Languages.variant;
|
|
283
|
+
}
|
|
284
|
+
Variant.isName = isName;
|
|
285
|
+
})(Variant = Language.Variant || (Language.Variant = {}));
|
|
286
|
+
Language.variant = Variant.of, Language.isVariant = Variant.isVariant, Language.isVariantName = Variant.isName;
|
|
287
|
+
})(Language || (Language = {}));
|
|
288
|
+
/**
|
|
289
|
+
* @public
|
|
290
|
+
*/
|
|
291
|
+
(function (Language) {
|
|
292
|
+
function parse(input) {
|
|
293
|
+
let parts = Slice.of(input.toLowerCase().split("-"));
|
|
294
|
+
return parts
|
|
295
|
+
.get(0)
|
|
296
|
+
.map((name) => {
|
|
297
|
+
if (!Language.isPrimaryName(name)) {
|
|
298
|
+
return Err.of(`${name} is not a valid primary language`);
|
|
299
|
+
}
|
|
300
|
+
const primary = Language.Primary.of(name);
|
|
301
|
+
parts = parts.slice(1);
|
|
302
|
+
const extended = parts.get(0).filter(Language.isExtendedName).map(Language.Extended.of);
|
|
303
|
+
if (extended.isSome()) {
|
|
304
|
+
parts = parts.slice(1);
|
|
305
|
+
}
|
|
306
|
+
const script = parts.get(0).filter(Language.isScriptName).map(Language.Script.of);
|
|
307
|
+
if (script.isSome()) {
|
|
308
|
+
parts = parts.slice(1);
|
|
309
|
+
}
|
|
310
|
+
const region = parts.get(0).filter(Language.isRegionName).map(Language.Region.of);
|
|
311
|
+
if (region.isSome()) {
|
|
312
|
+
parts = parts.slice(1);
|
|
313
|
+
}
|
|
314
|
+
const variants = [];
|
|
315
|
+
while (true) {
|
|
316
|
+
const variant = parts.get(0).filter(Language.isVariantName).map(Language.Variant.of);
|
|
317
|
+
if (variant.isSome()) {
|
|
318
|
+
parts = parts.slice(1);
|
|
319
|
+
variants.push(variant.get());
|
|
320
|
+
}
|
|
321
|
+
else {
|
|
322
|
+
break;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
return Result.of(Language.of(primary, extended, script, region, variants));
|
|
326
|
+
})
|
|
327
|
+
.getOrElse(() => Err.of(`Expected a primary language name`));
|
|
328
|
+
}
|
|
329
|
+
Language.parse = parse;
|
|
330
|
+
})(Language || (Language = {}));
|
|
331
|
+
//# sourceMappingURL=language.js.map
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json.schemastore.org/package",
|
|
3
|
+
"name": "@siteimprove/alfa-iana",
|
|
4
|
+
"homepage": "https://alfa.siteimprove.com",
|
|
5
|
+
"version": "0.89.5",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"description": "Functionality for working with the different IANA registries, such as the language subtag registry",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "github:Siteimprove/alfa",
|
|
11
|
+
"directory": "packages/alfa-iana"
|
|
12
|
+
},
|
|
13
|
+
"bugs": "https://github.com/siteimprove/alfa/issues",
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=20.0.0"
|
|
16
|
+
},
|
|
17
|
+
"type": "module",
|
|
18
|
+
"main": "dist/index.js",
|
|
19
|
+
"types": "dist/index.d.ts",
|
|
20
|
+
"files": [
|
|
21
|
+
"dist/**/*.js",
|
|
22
|
+
"dist/**/*.d.ts"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"generate": "node scripts/languages.js"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@siteimprove/alfa-equatable": "^0.89.5",
|
|
29
|
+
"@siteimprove/alfa-json": "^0.89.5",
|
|
30
|
+
"@siteimprove/alfa-option": "^0.89.5",
|
|
31
|
+
"@siteimprove/alfa-result": "^0.89.5",
|
|
32
|
+
"@siteimprove/alfa-slice": "^0.89.5"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@siteimprove/alfa-test": "^0.89.5",
|
|
36
|
+
"axios": "^1.7.4",
|
|
37
|
+
"prettier": "^3.0.0"
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public",
|
|
41
|
+
"registry": "https://npm.pkg.github.com/"
|
|
42
|
+
}
|
|
43
|
+
}
|