@formatjs/intl-getcanonicallocales 2.5.6 → 3.0.1

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/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export declare function getCanonicalLocales(locales?: string[] | string): string[];
2
- export * from './src/emitter';
3
- export { isStructurallyValidLanguageTag, isUnicodeLanguageSubtag, isUnicodeRegionSubtag, isUnicodeScriptSubtag, parseUnicodeLanguageId, parseUnicodeLocaleId, } from './src/parser';
4
- export * from './src/types';
5
- export * from './src/likelySubtags.generated';
2
+ export * from './src/emitter.js';
3
+ export { isStructurallyValidLanguageTag, isUnicodeLanguageSubtag, isUnicodeRegionSubtag, isUnicodeScriptSubtag, parseUnicodeLanguageId, parseUnicodeLocaleId, } from './src/parser.js';
4
+ export * from './src/types.js';
5
+ export * from './src/likelySubtags.generated.js';
package/index.js CHANGED
@@ -1,11 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseUnicodeLocaleId = exports.parseUnicodeLanguageId = exports.isUnicodeScriptSubtag = exports.isUnicodeRegionSubtag = exports.isUnicodeLanguageSubtag = exports.isStructurallyValidLanguageTag = void 0;
4
- exports.getCanonicalLocales = getCanonicalLocales;
5
- var tslib_1 = require("tslib");
6
- var canonicalizer_1 = require("./src/canonicalizer");
7
- var emitter_1 = require("./src/emitter");
8
- var parser_1 = require("./src/parser");
1
+ import { CanonicalizeUnicodeLocaleId } from './src/canonicalizer.js';
2
+ import { emitUnicodeLocaleId } from './src/emitter.js';
3
+ import { parseUnicodeLocaleId } from './src/parser.js';
9
4
  /**
10
5
  * https://tc39.es/ecma402/#sec-canonicalizelocalelist
11
6
  * @param locales
@@ -20,23 +15,17 @@ function CanonicalizeLocaleList(locales) {
20
15
  }
21
16
  for (var _i = 0, locales_1 = locales; _i < locales_1.length; _i++) {
22
17
  var locale = locales_1[_i];
23
- var canonicalizedTag = (0, emitter_1.emitUnicodeLocaleId)((0, canonicalizer_1.CanonicalizeUnicodeLocaleId)((0, parser_1.parseUnicodeLocaleId)(locale)));
18
+ var canonicalizedTag = emitUnicodeLocaleId(CanonicalizeUnicodeLocaleId(parseUnicodeLocaleId(locale)));
24
19
  if (seen.indexOf(canonicalizedTag) < 0) {
25
20
  seen.push(canonicalizedTag);
26
21
  }
27
22
  }
28
23
  return seen;
29
24
  }
30
- function getCanonicalLocales(locales) {
25
+ export function getCanonicalLocales(locales) {
31
26
  return CanonicalizeLocaleList(locales);
32
27
  }
33
- tslib_1.__exportStar(require("./src/emitter"), exports);
34
- var parser_2 = require("./src/parser");
35
- Object.defineProperty(exports, "isStructurallyValidLanguageTag", { enumerable: true, get: function () { return parser_2.isStructurallyValidLanguageTag; } });
36
- Object.defineProperty(exports, "isUnicodeLanguageSubtag", { enumerable: true, get: function () { return parser_2.isUnicodeLanguageSubtag; } });
37
- Object.defineProperty(exports, "isUnicodeRegionSubtag", { enumerable: true, get: function () { return parser_2.isUnicodeRegionSubtag; } });
38
- Object.defineProperty(exports, "isUnicodeScriptSubtag", { enumerable: true, get: function () { return parser_2.isUnicodeScriptSubtag; } });
39
- Object.defineProperty(exports, "parseUnicodeLanguageId", { enumerable: true, get: function () { return parser_2.parseUnicodeLanguageId; } });
40
- Object.defineProperty(exports, "parseUnicodeLocaleId", { enumerable: true, get: function () { return parser_2.parseUnicodeLocaleId; } });
41
- tslib_1.__exportStar(require("./src/types"), exports);
42
- tslib_1.__exportStar(require("./src/likelySubtags.generated"), exports);
28
+ export * from './src/emitter.js';
29
+ export { isStructurallyValidLanguageTag, isUnicodeLanguageSubtag, isUnicodeRegionSubtag, isUnicodeScriptSubtag, parseUnicodeLanguageId, parseUnicodeLocaleId, } from './src/parser.js';
30
+ export * from './src/types.js';
31
+ export * from './src/likelySubtags.generated.js';
package/package.json CHANGED
@@ -1,10 +1,17 @@
1
1
  {
2
2
  "name": "@formatjs/intl-getcanonicallocales",
3
3
  "description": "Intl.getCanonicalLocales polyfill",
4
- "version": "2.5.6",
4
+ "version": "3.0.1",
5
5
  "license": "MIT",
6
6
  "author": "Long Ho <holevietlong@gmail.com>",
7
+ "type": "module",
7
8
  "types": "index.d.ts",
9
+ "exports": {
10
+ ".": "./index.js",
11
+ "./polyfill.js": "./polyfill.js",
12
+ "./polyfill-force.js": "./polyfill-force.js",
13
+ "./should-polyfill.js": "./should-polyfill.js"
14
+ },
8
15
  "dependencies": {
9
16
  "tslib": "^2.8.0"
10
17
  },
@@ -20,6 +27,5 @@
20
27
  "react-intl",
21
28
  "tc39"
22
29
  ],
23
- "main": "index.js",
24
30
  "repository": "formatjs/formatjs.git"
25
31
  }
package/polyfill-force.js CHANGED
@@ -1,6 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var _1 = require("./");
1
+ import { getCanonicalLocales } from './index.js';
4
2
  if (typeof Intl === 'undefined') {
5
3
  if (typeof window !== 'undefined') {
6
4
  Object.defineProperty(window, 'Intl', {
@@ -16,7 +14,7 @@ if (typeof Intl === 'undefined') {
16
14
  }
17
15
  }
18
16
  Object.defineProperty(Intl, 'getCanonicalLocales', {
19
- value: _1.getCanonicalLocales,
17
+ value: getCanonicalLocales,
20
18
  writable: true,
21
19
  enumerable: false,
22
20
  configurable: true,
package/polyfill.js CHANGED
@@ -1,7 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var _1 = require("./");
4
- var should_polyfill_1 = require("./should-polyfill");
1
+ import { getCanonicalLocales } from './index.js';
2
+ import { shouldPolyfill } from './should-polyfill.js';
5
3
  if (typeof Intl === 'undefined') {
6
4
  if (typeof window !== 'undefined') {
7
5
  Object.defineProperty(window, 'Intl', {
@@ -16,9 +14,9 @@ if (typeof Intl === 'undefined') {
16
14
  });
17
15
  }
18
16
  }
19
- if ((0, should_polyfill_1.shouldPolyfill)()) {
17
+ if (shouldPolyfill()) {
20
18
  Object.defineProperty(Intl, 'getCanonicalLocales', {
21
- value: _1.getCanonicalLocales,
19
+ value: getCanonicalLocales,
22
20
  writable: true,
23
21
  enumerable: false,
24
22
  configurable: true,
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.shouldPolyfill = shouldPolyfill;
4
- function shouldPolyfill() {
1
+ export function shouldPolyfill() {
5
2
  return (typeof Intl === 'undefined' ||
6
3
  !('getCanonicalLocales' in Intl) ||
7
4
  // Native Intl.getCanonicalLocales is just buggy
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.variantAlias = exports.scriptAlias = exports.territoryAlias = exports.languageAlias = void 0;
4
1
  /* @generated */
5
2
  // prettier-ignore
6
- exports.languageAlias = {
3
+ export var languageAlias = {
7
4
  "aa-saaho": "ssy",
8
5
  "aam": "aas",
9
6
  "aar": "aa",
@@ -503,7 +500,7 @@ exports.languageAlias = {
503
500
  "zul": "zu",
504
501
  "zyb": "za"
505
502
  };
506
- exports.territoryAlias = {
503
+ export var territoryAlias = {
507
504
  "004": "AF",
508
505
  "008": "AL",
509
506
  "010": "AQ",
@@ -1145,10 +1142,10 @@ exports.territoryAlias = {
1145
1142
  "ZWE": "ZW",
1146
1143
  "ZZZ": "ZZ"
1147
1144
  };
1148
- exports.scriptAlias = {
1145
+ export var scriptAlias = {
1149
1146
  "Qaai": "Zinh"
1150
1147
  };
1151
- exports.variantAlias = {
1148
+ export var variantAlias = {
1152
1149
  "heploc": "alalc97",
1153
1150
  "polytoni": "polyton"
1154
1151
  };
@@ -1,4 +1,4 @@
1
- import { UnicodeLanguageId, UnicodeLocaleId } from './types';
1
+ import { UnicodeLanguageId, UnicodeLocaleId } from './types.js';
2
2
  /**
3
3
  * CAVEAT: We don't do this section in the spec bc they have no JSON data
4
4
  * Use the bcp47 data to replace keys, types, tfields, and tvalues by their canonical forms. See Section 3.6.4 U Extension Data Files) and Section 3.7.1 T Extension Data Files. The aliases are in the alias attribute value, while the canonical is in the name attribute value. For example,
@@ -1,12 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.canonicalizeUnicodeLanguageId = canonicalizeUnicodeLanguageId;
4
- exports.CanonicalizeUnicodeLocaleId = CanonicalizeUnicodeLocaleId;
5
- var tslib_1 = require("tslib");
6
- var aliases_generated_1 = require("./aliases.generated");
7
- var emitter_1 = require("./emitter");
8
- var likelySubtags_generated_1 = require("./likelySubtags.generated");
9
- var parser_1 = require("./parser");
1
+ import { __spreadArray } from "tslib";
2
+ import { languageAlias, scriptAlias, territoryAlias, variantAlias, } from './aliases.generated.js';
3
+ import { emitUnicodeLanguageId } from './emitter.js';
4
+ import { likelySubtags } from './likelySubtags.generated.js';
5
+ import { isUnicodeLanguageSubtag, isUnicodeVariantSubtag, parseUnicodeLanguageId, SEPARATOR, } from './parser.js';
10
6
  function canonicalizeAttrs(strs) {
11
7
  return Object.keys(strs.reduce(function (all, str) {
12
8
  all[str.toLowerCase()] = 1;
@@ -38,7 +34,7 @@ function compareExtension(e1, e2) {
38
34
  return e1.type < e2.type ? -1 : e1.type > e2.type ? 1 : 0;
39
35
  }
40
36
  function mergeVariants(v1, v2) {
41
- var result = tslib_1.__spreadArray([], v1, true);
37
+ var result = __spreadArray([], v1, true);
42
38
  for (var _i = 0, v2_1 = v2; _i < v2_1.length; _i++) {
43
39
  var v = v2_1[_i];
44
40
  if (v1.indexOf(v) < 0) {
@@ -56,7 +52,7 @@ We get the following transformation:
56
52
  en-u-ms-imperial ⇒ en-u-ms-uksystem
57
53
  * @param lang
58
54
  */
59
- function canonicalizeUnicodeLanguageId(unicodeLanguageId) {
55
+ export function canonicalizeUnicodeLanguageId(unicodeLanguageId) {
60
56
  /**
61
57
  * If the language subtag matches the type attribute of a languageAlias element in Supplemental Data, replace the language subtag with the replacement value.
62
58
  * 1. If there are additional subtags in the replacement value, add them to the result, but only if there is no corresponding subtag already in the tag.
@@ -70,11 +66,11 @@ function canonicalizeUnicodeLanguageId(unicodeLanguageId) {
70
66
  for (var _i = 0, _a = unicodeLanguageId.variants; _i < _a.length; _i++) {
71
67
  var variant = _a[_i];
72
68
  if ((replacedLang_1 =
73
- aliases_generated_1.languageAlias[(0, emitter_1.emitUnicodeLanguageId)({
69
+ languageAlias[emitUnicodeLanguageId({
74
70
  lang: unicodeLanguageId.lang,
75
71
  variants: [variant],
76
72
  })])) {
77
- var replacedLangAst = (0, parser_1.parseUnicodeLanguageId)(replacedLang_1.split(parser_1.SEPARATOR));
73
+ var replacedLangAst = parseUnicodeLanguageId(replacedLang_1.split(SEPARATOR));
78
74
  finalLangAst = {
79
75
  lang: replacedLangAst.lang,
80
76
  script: finalLangAst.script || replacedLangAst.script,
@@ -88,14 +84,14 @@ function canonicalizeUnicodeLanguageId(unicodeLanguageId) {
88
84
  // language _ script _ country
89
85
  // ug-Arab-CN -> ug-CN
90
86
  if (finalLangAst.script && finalLangAst.region) {
91
- var replacedLang_2 = aliases_generated_1.languageAlias[(0, emitter_1.emitUnicodeLanguageId)({
87
+ var replacedLang_2 = languageAlias[emitUnicodeLanguageId({
92
88
  lang: finalLangAst.lang,
93
89
  script: finalLangAst.script,
94
90
  region: finalLangAst.region,
95
91
  variants: [],
96
92
  })];
97
93
  if (replacedLang_2) {
98
- var replacedLangAst = (0, parser_1.parseUnicodeLanguageId)(replacedLang_2.split(parser_1.SEPARATOR));
94
+ var replacedLangAst = parseUnicodeLanguageId(replacedLang_2.split(SEPARATOR));
99
95
  finalLangAst = {
100
96
  lang: replacedLangAst.lang,
101
97
  script: replacedLangAst.script,
@@ -107,13 +103,13 @@ function canonicalizeUnicodeLanguageId(unicodeLanguageId) {
107
103
  // language _ country
108
104
  // eg. az_AZ -> az_Latn_A
109
105
  if (finalLangAst.region) {
110
- var replacedLang_3 = aliases_generated_1.languageAlias[(0, emitter_1.emitUnicodeLanguageId)({
106
+ var replacedLang_3 = languageAlias[emitUnicodeLanguageId({
111
107
  lang: finalLangAst.lang,
112
108
  region: finalLangAst.region,
113
109
  variants: [],
114
110
  })];
115
111
  if (replacedLang_3) {
116
- var replacedLangAst = (0, parser_1.parseUnicodeLanguageId)(replacedLang_3.split(parser_1.SEPARATOR));
112
+ var replacedLangAst = parseUnicodeLanguageId(replacedLang_3.split(SEPARATOR));
117
113
  finalLangAst = {
118
114
  lang: replacedLangAst.lang,
119
115
  script: finalLangAst.script || replacedLangAst.script,
@@ -124,12 +120,12 @@ function canonicalizeUnicodeLanguageId(unicodeLanguageId) {
124
120
  }
125
121
  // only language
126
122
  // e.g. twi -> ak
127
- var replacedLang = aliases_generated_1.languageAlias[(0, emitter_1.emitUnicodeLanguageId)({
123
+ var replacedLang = languageAlias[emitUnicodeLanguageId({
128
124
  lang: finalLangAst.lang,
129
125
  variants: [],
130
126
  })];
131
127
  if (replacedLang) {
132
- var replacedLangAst = (0, parser_1.parseUnicodeLanguageId)(replacedLang.split(parser_1.SEPARATOR));
128
+ var replacedLangAst = parseUnicodeLanguageId(replacedLang.split(SEPARATOR));
133
129
  finalLangAst = {
134
130
  lang: replacedLangAst.lang,
135
131
  script: finalLangAst.script || replacedLangAst.script,
@@ -139,18 +135,18 @@ function canonicalizeUnicodeLanguageId(unicodeLanguageId) {
139
135
  }
140
136
  if (finalLangAst.region) {
141
137
  var region = finalLangAst.region.toUpperCase();
142
- var regionAlias = aliases_generated_1.territoryAlias[region];
138
+ var regionAlias = territoryAlias[region];
143
139
  var replacedRegion = void 0;
144
140
  if (regionAlias) {
145
141
  var regions = regionAlias.split(' ');
146
142
  replacedRegion = regions[0];
147
- var likelySubtag = likelySubtags_generated_1.likelySubtags[(0, emitter_1.emitUnicodeLanguageId)({
143
+ var likelySubtag = likelySubtags[emitUnicodeLanguageId({
148
144
  lang: finalLangAst.lang,
149
145
  script: finalLangAst.script,
150
146
  variants: [],
151
147
  })];
152
148
  if (likelySubtag) {
153
- var likelyRegion = (0, parser_1.parseUnicodeLanguageId)(likelySubtag.split(parser_1.SEPARATOR)).region;
149
+ var likelyRegion = parseUnicodeLanguageId(likelySubtag.split(SEPARATOR)).region;
154
150
  if (likelyRegion && regions.indexOf(likelyRegion) > -1) {
155
151
  replacedRegion = likelyRegion;
156
152
  }
@@ -165,19 +161,19 @@ function canonicalizeUnicodeLanguageId(unicodeLanguageId) {
165
161
  finalLangAst.script =
166
162
  finalLangAst.script[0].toUpperCase() +
167
163
  finalLangAst.script.slice(1).toLowerCase();
168
- if (aliases_generated_1.scriptAlias[finalLangAst.script]) {
169
- finalLangAst.script = aliases_generated_1.scriptAlias[finalLangAst.script];
164
+ if (scriptAlias[finalLangAst.script]) {
165
+ finalLangAst.script = scriptAlias[finalLangAst.script];
170
166
  }
171
167
  }
172
168
  if (finalLangAst.variants.length) {
173
169
  for (var i = 0; i < finalLangAst.variants.length; i++) {
174
170
  var variant = finalLangAst.variants[i].toLowerCase();
175
- if (aliases_generated_1.variantAlias[variant]) {
176
- var alias = aliases_generated_1.variantAlias[variant];
177
- if ((0, parser_1.isUnicodeVariantSubtag)(alias)) {
171
+ if (variantAlias[variant]) {
172
+ var alias = variantAlias[variant];
173
+ if (isUnicodeVariantSubtag(alias)) {
178
174
  finalLangAst.variants[i] = alias;
179
175
  }
180
- else if ((0, parser_1.isUnicodeLanguageSubtag)(alias)) {
176
+ else if (isUnicodeLanguageSubtag(alias)) {
181
177
  // Yes this can happen per the spec
182
178
  finalLangAst.lang = alias;
183
179
  }
@@ -194,7 +190,7 @@ function canonicalizeUnicodeLanguageId(unicodeLanguageId) {
194
190
  * IMPORTANT: This modifies the object inline
195
191
  * @param locale
196
192
  */
197
- function CanonicalizeUnicodeLocaleId(locale) {
193
+ export function CanonicalizeUnicodeLocaleId(locale) {
198
194
  locale.lang = canonicalizeUnicodeLanguageId(locale.lang);
199
195
  if (locale.extensions) {
200
196
  for (var _i = 0, _a = locale.extensions; _i < _a.length; _i++) {
package/src/emitter.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { UnicodeLanguageId, UnicodeLocaleId } from './types';
1
+ import { UnicodeLanguageId, UnicodeLocaleId } from './types.js';
2
2
  export declare function emitUnicodeLanguageId(lang?: UnicodeLanguageId): string;
3
3
  export declare function emitUnicodeLocaleId({ lang, extensions, }: UnicodeLocaleId): string;
package/src/emitter.js CHANGED
@@ -1,16 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.emitUnicodeLanguageId = emitUnicodeLanguageId;
4
- exports.emitUnicodeLocaleId = emitUnicodeLocaleId;
5
- var tslib_1 = require("tslib");
6
- function emitUnicodeLanguageId(lang) {
1
+ import { __spreadArray } from "tslib";
2
+ export function emitUnicodeLanguageId(lang) {
7
3
  if (!lang) {
8
4
  return '';
9
5
  }
10
- return tslib_1.__spreadArray([lang.lang, lang.script, lang.region], (lang.variants || []), true).filter(Boolean)
6
+ return __spreadArray([lang.lang, lang.script, lang.region], (lang.variants || []), true).filter(Boolean)
11
7
  .join('-');
12
8
  }
13
- function emitUnicodeLocaleId(_a) {
9
+ export function emitUnicodeLocaleId(_a) {
14
10
  var lang = _a.lang, extensions = _a.extensions;
15
11
  var chunks = [emitUnicodeLanguageId(lang)];
16
12
  for (var _i = 0, extensions_1 = extensions; _i < extensions_1.length; _i++) {
@@ -18,10 +14,10 @@ function emitUnicodeLocaleId(_a) {
18
14
  chunks.push(ext.type);
19
15
  switch (ext.type) {
20
16
  case 'u':
21
- chunks.push.apply(chunks, tslib_1.__spreadArray(tslib_1.__spreadArray([], ext.attributes, false), ext.keywords.reduce(function (all, kv) { return all.concat(kv); }, []), false));
17
+ chunks.push.apply(chunks, __spreadArray(__spreadArray([], ext.attributes, false), ext.keywords.reduce(function (all, kv) { return all.concat(kv); }, []), false));
22
18
  break;
23
19
  case 't':
24
- chunks.push.apply(chunks, tslib_1.__spreadArray([emitUnicodeLanguageId(ext.lang)], ext.fields.reduce(function (all, kv) { return all.concat(kv); }, []), false));
20
+ chunks.push.apply(chunks, __spreadArray([emitUnicodeLanguageId(ext.lang)], ext.fields.reduce(function (all, kv) { return all.concat(kv); }, []), false));
25
21
  break;
26
22
  default:
27
23
  chunks.push(ext.value);
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.likelySubtags = void 0;
4
1
  /* @generated */
5
2
  // prettier-ignore
6
- exports.likelySubtags = {
3
+ export var likelySubtags = {
7
4
  "aa": "aa-Latn-ET",
8
5
  "aaa": "aaa-Latn-NG",
9
6
  "aab": "aab-Latn-NG",
package/src/parser.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { UnicodeLocaleId, UnicodeLanguageId } from './types';
1
+ import { UnicodeLocaleId, UnicodeLanguageId } from './types.js';
2
2
  export declare const SEPARATOR = "-";
3
3
  export declare function isUnicodeLanguageSubtag(lang: string): boolean;
4
4
  export declare function isStructurallyValidLanguageTag(tag: string): boolean;
package/src/parser.js CHANGED
@@ -1,14 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SEPARATOR = void 0;
4
- exports.isUnicodeLanguageSubtag = isUnicodeLanguageSubtag;
5
- exports.isStructurallyValidLanguageTag = isStructurallyValidLanguageTag;
6
- exports.isUnicodeRegionSubtag = isUnicodeRegionSubtag;
7
- exports.isUnicodeScriptSubtag = isUnicodeScriptSubtag;
8
- exports.isUnicodeVariantSubtag = isUnicodeVariantSubtag;
9
- exports.parseUnicodeLanguageId = parseUnicodeLanguageId;
10
- exports.parseUnicodeLocaleId = parseUnicodeLocaleId;
11
- var tslib_1 = require("tslib");
1
+ import { __assign } from "tslib";
12
2
  var ALPHANUM_1_8 = /^[a-z0-9]{1,8}$/i;
13
3
  var ALPHANUM_2_8 = /^[a-z0-9]{2,8}$/i;
14
4
  var ALPHANUM_3_8 = /^[a-z0-9]{3,8}$/i;
@@ -21,31 +11,31 @@ var UNICODE_REGION_SUBTAG_REGEX = /^([a-z]{2}|[0-9]{3})$/i;
21
11
  var UNICODE_VARIANT_SUBTAG_REGEX = /^([a-z0-9]{5,8}|[0-9][a-z0-9]{3})$/i;
22
12
  var UNICODE_LANGUAGE_SUBTAG_REGEX = /^([a-z]{2,3}|[a-z]{5,8})$/i;
23
13
  var TKEY_REGEX = /^[a-z][0-9]$/i;
24
- exports.SEPARATOR = '-';
25
- function isUnicodeLanguageSubtag(lang) {
14
+ export var SEPARATOR = '-';
15
+ export function isUnicodeLanguageSubtag(lang) {
26
16
  return UNICODE_LANGUAGE_SUBTAG_REGEX.test(lang);
27
17
  }
28
- function isStructurallyValidLanguageTag(tag) {
18
+ export function isStructurallyValidLanguageTag(tag) {
29
19
  try {
30
- parseUnicodeLanguageId(tag.split(exports.SEPARATOR));
20
+ parseUnicodeLanguageId(tag.split(SEPARATOR));
31
21
  }
32
- catch (e) {
22
+ catch (_a) {
33
23
  return false;
34
24
  }
35
25
  return true;
36
26
  }
37
- function isUnicodeRegionSubtag(region) {
27
+ export function isUnicodeRegionSubtag(region) {
38
28
  return UNICODE_REGION_SUBTAG_REGEX.test(region);
39
29
  }
40
- function isUnicodeScriptSubtag(script) {
30
+ export function isUnicodeScriptSubtag(script) {
41
31
  return ALPHA_4.test(script);
42
32
  }
43
- function isUnicodeVariantSubtag(variant) {
33
+ export function isUnicodeVariantSubtag(variant) {
44
34
  return UNICODE_VARIANT_SUBTAG_REGEX.test(variant);
45
35
  }
46
- function parseUnicodeLanguageId(chunks) {
36
+ export function parseUnicodeLanguageId(chunks) {
47
37
  if (typeof chunks === 'string') {
48
- chunks = chunks.split(exports.SEPARATOR);
38
+ chunks = chunks.split(SEPARATOR);
49
39
  }
50
40
  var lang = chunks.shift();
51
41
  if (!lang) {
@@ -126,7 +116,7 @@ function parseKeyword(chunks) {
126
116
  }
127
117
  var value = '';
128
118
  if (type.length) {
129
- value = type.join(exports.SEPARATOR);
119
+ value = type.join(SEPARATOR);
130
120
  }
131
121
  return [key, value];
132
122
  }
@@ -135,7 +125,7 @@ function parseTransformedExtension(chunks) {
135
125
  try {
136
126
  lang = parseUnicodeLanguageId(chunks);
137
127
  }
138
- catch (e) {
128
+ catch (_a) {
139
129
  // Try just parsing tfield
140
130
  }
141
131
  var fields = [];
@@ -148,7 +138,7 @@ function parseTransformedExtension(chunks) {
148
138
  if (!value.length) {
149
139
  throw new RangeError("Missing tvalue for tkey \"".concat(key, "\""));
150
140
  }
151
- fields.push([key, value.join(exports.SEPARATOR)]);
141
+ fields.push([key, value.join(SEPARATOR)]);
152
142
  }
153
143
  if (fields.length) {
154
144
  return {
@@ -167,7 +157,7 @@ function parsePuExtension(chunks) {
167
157
  if (exts.length) {
168
158
  return {
169
159
  type: 'x',
170
- value: exts.join(exports.SEPARATOR),
160
+ value: exts.join(SEPARATOR),
171
161
  };
172
162
  }
173
163
  throw new RangeError('Malformed private_use_extension');
@@ -178,7 +168,7 @@ function parseOtherExtensionValue(chunks) {
178
168
  exts.push(chunks.shift());
179
169
  }
180
170
  if (exts.length) {
181
- return exts.join(exports.SEPARATOR);
171
+ return exts.join(SEPARATOR);
182
172
  }
183
173
  return '';
184
174
  }
@@ -236,8 +226,8 @@ function parseExtensions(chunks) {
236
226
  } while (chunks.length);
237
227
  return { extensions: extensions };
238
228
  }
239
- function parseUnicodeLocaleId(locale) {
240
- var chunks = locale.split(exports.SEPARATOR);
229
+ export function parseUnicodeLocaleId(locale) {
230
+ var chunks = locale.split(SEPARATOR);
241
231
  var lang = parseUnicodeLanguageId(chunks);
242
- return tslib_1.__assign({ lang: lang }, parseExtensions(chunks));
232
+ return __assign({ lang: lang }, parseExtensions(chunks));
243
233
  }
package/src/types.js CHANGED
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};