@formatjs/intl-getcanonicallocales 2.0.3 → 2.0.4
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 +6 -0
- package/index.d.ts.map +1 -0
- package/index.js +42 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +31 -0
- package/lib/polyfill.d.ts +2 -0
- package/lib/polyfill.d.ts.map +1 -0
- package/lib/polyfill.js +24 -0
- package/lib/should-polyfill.d.ts +2 -0
- package/lib/should-polyfill.d.ts.map +1 -0
- package/lib/should-polyfill.js +8 -0
- package/lib/src/aliases.generated.d.ts +5 -0
- package/lib/src/aliases.generated.d.ts.map +1 -0
- package/lib/src/aliases.generated.js +1137 -0
- package/lib/src/canonicalizer.d.ts +20 -0
- package/lib/src/canonicalizer.d.ts.map +1 -0
- package/lib/src/canonicalizer.js +219 -0
- package/lib/src/emitter.d.ts +4 -0
- package/lib/src/emitter.d.ts.map +1 -0
- package/lib/src/emitter.js +28 -0
- package/lib/src/likelySubtags.generated.d.ts +2 -0
- package/lib/src/likelySubtags.generated.d.ts.map +1 -0
- package/lib/src/likelySubtags.generated.js +1870 -0
- package/lib/src/parser.d.ts +10 -0
- package/lib/src/parser.d.ts.map +1 -0
- package/lib/src/parser.js +233 -0
- package/lib/src/types.d.ts +33 -0
- package/lib/src/types.d.ts.map +1 -0
- package/lib/src/types.js +1 -0
- package/package.json +1 -1
- package/polyfill.d.ts +2 -0
- package/polyfill.d.ts.map +1 -0
- package/polyfill.iife.js +3512 -0
- package/polyfill.js +26 -0
- package/should-polyfill.d.ts +2 -0
- package/should-polyfill.d.ts.map +1 -0
- package/should-polyfill.js +12 -0
- package/src/aliases.generated.d.ts +5 -0
- package/src/aliases.generated.d.ts.map +1 -0
- package/src/aliases.generated.js +1140 -0
- package/src/canonicalizer.d.ts +20 -0
- package/src/canonicalizer.d.ts.map +1 -0
- package/src/canonicalizer.js +224 -0
- package/src/emitter.d.ts +4 -0
- package/src/emitter.d.ts.map +1 -0
- package/src/emitter.js +33 -0
- package/src/likelySubtags.generated.d.ts +2 -0
- package/src/likelySubtags.generated.d.ts.map +1 -0
- package/src/likelySubtags.generated.js +1873 -0
- package/src/parser.d.ts +10 -0
- package/src/parser.d.ts.map +1 -0
- package/src/parser.js +243 -0
- package/src/types.d.ts +33 -0
- package/src/types.d.ts.map +1 -0
- package/src/types.js +2 -0
- package/BUILD +0 -116
- package/CHANGELOG.md +0 -290
- package/index.ts +0 -43
- package/polyfill.ts +0 -23
- package/scripts/aliases.ts +0 -70
- package/scripts/likely-subtags.ts +0 -20
- package/should-polyfill.ts +0 -10
- package/src/aliases.generated.ts +0 -1137
- package/src/canonicalizer.ts +0 -272
- package/src/emitter.ts +0 -39
- package/src/likelySubtags.generated.ts +0 -1870
- package/src/parser.ts +0 -259
- package/src/types.ts +0 -63
- package/tests/index.test.ts +0 -24
- package/tests/parser.test.ts +0 -204
- package/tsconfig.json +0 -5
package/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function getCanonicalLocales(locales?: string[] | string): string[];
|
|
2
|
+
export { parseUnicodeLocaleId, parseUnicodeLanguageId, isStructurallyValidLanguageTag, isUnicodeRegionSubtag, isUnicodeScriptSubtag, isUnicodeLanguageSubtag, } from './src/parser';
|
|
3
|
+
export * from './src/types';
|
|
4
|
+
export * from './src/emitter';
|
|
5
|
+
export * from './src/likelySubtags.generated';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
package/index.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AA2BA,wBAAgB,mBAAmB,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,MAAM,EAAE,CAEzE;AAED,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,8BAA8B,EAC9B,qBAAqB,EACrB,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,cAAc,CAAA;AACrB,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAE7B,cAAc,+BAA+B,CAAA"}
|
package/index.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isUnicodeLanguageSubtag = exports.isUnicodeScriptSubtag = exports.isUnicodeRegionSubtag = exports.isStructurallyValidLanguageTag = exports.parseUnicodeLanguageId = exports.parseUnicodeLocaleId = exports.getCanonicalLocales = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var parser_1 = require("./src/parser");
|
|
6
|
+
var emitter_1 = require("./src/emitter");
|
|
7
|
+
var canonicalizer_1 = require("./src/canonicalizer");
|
|
8
|
+
/**
|
|
9
|
+
* https://tc39.es/ecma402/#sec-canonicalizelocalelist
|
|
10
|
+
* @param locales
|
|
11
|
+
*/
|
|
12
|
+
function CanonicalizeLocaleList(locales) {
|
|
13
|
+
if (locales === undefined) {
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
var seen = [];
|
|
17
|
+
if (typeof locales === 'string') {
|
|
18
|
+
locales = [locales];
|
|
19
|
+
}
|
|
20
|
+
for (var _i = 0, locales_1 = locales; _i < locales_1.length; _i++) {
|
|
21
|
+
var locale = locales_1[_i];
|
|
22
|
+
var canonicalizedTag = (0, emitter_1.emitUnicodeLocaleId)((0, canonicalizer_1.canonicalizeUnicodeLocaleId)((0, parser_1.parseUnicodeLocaleId)(locale)));
|
|
23
|
+
if (seen.indexOf(canonicalizedTag) < 0) {
|
|
24
|
+
seen.push(canonicalizedTag);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return seen;
|
|
28
|
+
}
|
|
29
|
+
function getCanonicalLocales(locales) {
|
|
30
|
+
return CanonicalizeLocaleList(locales);
|
|
31
|
+
}
|
|
32
|
+
exports.getCanonicalLocales = getCanonicalLocales;
|
|
33
|
+
var parser_2 = require("./src/parser");
|
|
34
|
+
Object.defineProperty(exports, "parseUnicodeLocaleId", { enumerable: true, get: function () { return parser_2.parseUnicodeLocaleId; } });
|
|
35
|
+
Object.defineProperty(exports, "parseUnicodeLanguageId", { enumerable: true, get: function () { return parser_2.parseUnicodeLanguageId; } });
|
|
36
|
+
Object.defineProperty(exports, "isStructurallyValidLanguageTag", { enumerable: true, get: function () { return parser_2.isStructurallyValidLanguageTag; } });
|
|
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, "isUnicodeLanguageSubtag", { enumerable: true, get: function () { return parser_2.isUnicodeLanguageSubtag; } });
|
|
40
|
+
tslib_1.__exportStar(require("./src/types"), exports);
|
|
41
|
+
tslib_1.__exportStar(require("./src/emitter"), exports);
|
|
42
|
+
tslib_1.__exportStar(require("./src/likelySubtags.generated"), exports);
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function getCanonicalLocales(locales?: string[] | string): string[];
|
|
2
|
+
export { parseUnicodeLocaleId, parseUnicodeLanguageId, isStructurallyValidLanguageTag, isUnicodeRegionSubtag, isUnicodeScriptSubtag, isUnicodeLanguageSubtag, } from './src/parser';
|
|
3
|
+
export * from './src/types';
|
|
4
|
+
export * from './src/emitter';
|
|
5
|
+
export * from './src/likelySubtags.generated';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AA2BA,wBAAgB,mBAAmB,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,GAAG,MAAM,EAAE,CAEzE;AAED,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,8BAA8B,EAC9B,qBAAqB,EACrB,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,cAAc,CAAA;AACrB,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAE7B,cAAc,+BAA+B,CAAA"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { parseUnicodeLocaleId } from './src/parser';
|
|
2
|
+
import { emitUnicodeLocaleId } from './src/emitter';
|
|
3
|
+
import { canonicalizeUnicodeLocaleId } from './src/canonicalizer';
|
|
4
|
+
/**
|
|
5
|
+
* https://tc39.es/ecma402/#sec-canonicalizelocalelist
|
|
6
|
+
* @param locales
|
|
7
|
+
*/
|
|
8
|
+
function CanonicalizeLocaleList(locales) {
|
|
9
|
+
if (locales === undefined) {
|
|
10
|
+
return [];
|
|
11
|
+
}
|
|
12
|
+
var seen = [];
|
|
13
|
+
if (typeof locales === 'string') {
|
|
14
|
+
locales = [locales];
|
|
15
|
+
}
|
|
16
|
+
for (var _i = 0, locales_1 = locales; _i < locales_1.length; _i++) {
|
|
17
|
+
var locale = locales_1[_i];
|
|
18
|
+
var canonicalizedTag = emitUnicodeLocaleId(canonicalizeUnicodeLocaleId(parseUnicodeLocaleId(locale)));
|
|
19
|
+
if (seen.indexOf(canonicalizedTag) < 0) {
|
|
20
|
+
seen.push(canonicalizedTag);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return seen;
|
|
24
|
+
}
|
|
25
|
+
export function getCanonicalLocales(locales) {
|
|
26
|
+
return CanonicalizeLocaleList(locales);
|
|
27
|
+
}
|
|
28
|
+
export { parseUnicodeLocaleId, parseUnicodeLanguageId, isStructurallyValidLanguageTag, isUnicodeRegionSubtag, isUnicodeScriptSubtag, isUnicodeLanguageSubtag, } from './src/parser';
|
|
29
|
+
export * from './src/types';
|
|
30
|
+
export * from './src/emitter';
|
|
31
|
+
export * from './src/likelySubtags.generated';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"polyfill.d.ts","sourceRoot":"","sources":["../polyfill.ts"],"names":[],"mappings":""}
|
package/lib/polyfill.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { getCanonicalLocales } from './';
|
|
2
|
+
import { shouldPolyfill } from './should-polyfill';
|
|
3
|
+
if (typeof Intl === 'undefined') {
|
|
4
|
+
if (typeof window !== 'undefined') {
|
|
5
|
+
Object.defineProperty(window, 'Intl', {
|
|
6
|
+
value: {},
|
|
7
|
+
});
|
|
8
|
+
// @ts-ignore we don't include @types/node so global isn't a thing
|
|
9
|
+
}
|
|
10
|
+
else if (typeof global !== 'undefined') {
|
|
11
|
+
// @ts-ignore we don't include @types/node so global isn't a thing
|
|
12
|
+
Object.defineProperty(global, 'Intl', {
|
|
13
|
+
value: {},
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
if (shouldPolyfill()) {
|
|
18
|
+
Object.defineProperty(Intl, 'getCanonicalLocales', {
|
|
19
|
+
value: getCanonicalLocales,
|
|
20
|
+
writable: true,
|
|
21
|
+
enumerable: false,
|
|
22
|
+
configurable: true,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"should-polyfill.d.ts","sourceRoot":"","sources":["../should-polyfill.ts"],"names":[],"mappings":"AAAA,wBAAgB,cAAc,YAS7B"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export function shouldPolyfill() {
|
|
2
|
+
return (typeof Intl === 'undefined' ||
|
|
3
|
+
!('getCanonicalLocales' in Intl) ||
|
|
4
|
+
// Native Intl.getCanonicalLocales is just buggy
|
|
5
|
+
// https://bugs.chromium.org/p/v8/issues/detail?id=10682
|
|
6
|
+
Intl.getCanonicalLocales('und-x-private')[0] ===
|
|
7
|
+
'x-private');
|
|
8
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const languageAlias: Record<string, string>;
|
|
2
|
+
export declare const territoryAlias: Record<string, string>;
|
|
3
|
+
export declare const scriptAlias: Record<string, string>;
|
|
4
|
+
export declare const variantAlias: Record<string, string>;
|
|
5
|
+
//# sourceMappingURL=aliases.generated.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aliases.generated.d.ts","sourceRoot":"","sources":["../../src/aliases.generated.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAqehD,CAAC;AACF,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAioBjD,CAAC;AACF,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAE9C,CAAC;AACF,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAG/C,CAAC"}
|