inital
This commit is contained in:
3
node_modules/bcp-47-normalize/index.d.ts
generated
vendored
Normal file
3
node_modules/bcp-47-normalize/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export { bcp47Normalize } from "./lib/index.js";
|
||||
export type Warning = import('bcp-47').Warning;
|
||||
export type Options = import('./lib/index.js').Options;
|
6
node_modules/bcp-47-normalize/index.js
generated
vendored
Normal file
6
node_modules/bcp-47-normalize/index.js
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
/**
|
||||
* @typedef {import('bcp-47').Warning} Warning
|
||||
* @typedef {import('./lib/index.js').Options} Options
|
||||
*/
|
||||
|
||||
export {bcp47Normalize} from './lib/index.js'
|
24
node_modules/bcp-47-normalize/lib/fields.d.ts
generated
vendored
Normal file
24
node_modules/bcp-47-normalize/lib/fields.d.ts
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* @typedef {'script'|'region'|'variants'} Field
|
||||
*
|
||||
* @typedef AddOrRemove
|
||||
* @property {Field} field
|
||||
* @property {string} value
|
||||
*
|
||||
* @typedef Change
|
||||
* @property {AddOrRemove} from
|
||||
* @property {AddOrRemove} to
|
||||
*/
|
||||
/**
|
||||
* @type {Array<Change>}
|
||||
*/
|
||||
export const fields: Array<Change>;
|
||||
export type Field = 'script' | 'region' | 'variants';
|
||||
export type AddOrRemove = {
|
||||
field: Field;
|
||||
value: string;
|
||||
};
|
||||
export type Change = {
|
||||
from: AddOrRemove;
|
||||
to: AddOrRemove;
|
||||
};
|
3217
node_modules/bcp-47-normalize/lib/fields.js
generated
vendored
Normal file
3217
node_modules/bcp-47-normalize/lib/fields.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
36
node_modules/bcp-47-normalize/lib/index.d.ts
generated
vendored
Normal file
36
node_modules/bcp-47-normalize/lib/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Normalize the given BCP 47 tag according to Unicode CLDR suggestions.
|
||||
*
|
||||
* @param {string} tag
|
||||
* BCP 47 tag.
|
||||
* @param {Options} [options]
|
||||
* Configuration (optional).
|
||||
* @returns {string}
|
||||
* Normal, canonical, and pretty BCP 47 tag.
|
||||
*/
|
||||
export function bcp47Normalize(tag: string, options?: Options | undefined): string;
|
||||
export type Warning = import('bcp-47').Warning;
|
||||
export type Schema = import('bcp-47').Schema;
|
||||
export type Extension = import('bcp-47').Extension;
|
||||
/**
|
||||
* Configuration (optional).
|
||||
*/
|
||||
export type Options = {
|
||||
/**
|
||||
* Passed to `bcp-47` as `options.forgiving`.
|
||||
*/
|
||||
forgiving?: boolean;
|
||||
/**
|
||||
* Passed to `bcp-47` as `options.warning`.
|
||||
*
|
||||
* One additional warning is given:
|
||||
*
|
||||
* | code | reason |
|
||||
* | :--- | :--------------------------------------------------------- |
|
||||
* | 7 | Deprecated region `CURRENT`, expected one of `SUGGESTIONS` |
|
||||
*
|
||||
* This warning is only given if the region cannot be automatically fixed
|
||||
* (when regions split into multiple regions).
|
||||
*/
|
||||
warning?: Warning;
|
||||
};
|
335
node_modules/bcp-47-normalize/lib/index.js
generated
vendored
Normal file
335
node_modules/bcp-47-normalize/lib/index.js
generated
vendored
Normal file
@@ -0,0 +1,335 @@
|
||||
/**
|
||||
* @typedef {import('bcp-47').Warning} Warning
|
||||
* @typedef {import('bcp-47').Schema} Schema
|
||||
* @typedef {import('bcp-47').Extension} Extension
|
||||
*
|
||||
* @typedef Options
|
||||
* Configuration (optional).
|
||||
* @property {boolean} [forgiving]
|
||||
* Passed to `bcp-47` as `options.forgiving`.
|
||||
* @property {Warning} [warning]
|
||||
* Passed to `bcp-47` as `options.warning`.
|
||||
*
|
||||
* One additional warning is given:
|
||||
*
|
||||
* | code | reason |
|
||||
* | :--- | :--------------------------------------------------------- |
|
||||
* | 7 | Deprecated region `CURRENT`, expected one of `SUGGESTIONS` |
|
||||
*
|
||||
* This warning is only given if the region cannot be automatically fixed
|
||||
* (when regions split into multiple regions).
|
||||
*/
|
||||
|
||||
import {parse, stringify} from 'bcp-47'
|
||||
import {extendedFilter} from 'bcp-47-match'
|
||||
import {matches} from './matches.js'
|
||||
import {fields} from './fields.js'
|
||||
import {many} from './many.js'
|
||||
import {likely} from './likely.js'
|
||||
|
||||
const own = {}.hasOwnProperty
|
||||
|
||||
/**
|
||||
* @param {Schema} base
|
||||
* @param {Partial<Schema>} changes
|
||||
* @returns {Schema}
|
||||
*/
|
||||
function merge(base, changes) {
|
||||
if (!base.language) base.language = changes.language
|
||||
if (!base.script) base.script = changes.script
|
||||
if (!base.region) base.region = changes.region
|
||||
if (changes.variants) base.variants.push(...changes.variants)
|
||||
|
||||
return base
|
||||
}
|
||||
|
||||
/**
|
||||
* Mostly like:
|
||||
* <https://github.com/formatjs/formatjs/blob/a15e757/packages/intl-locale/index.ts#L254>
|
||||
* But doesn’t crash.
|
||||
*
|
||||
* @param {Schema} schema
|
||||
* @returns {string}
|
||||
*/
|
||||
function addLikelySubtags(schema) {
|
||||
const {language, script, region} = schema
|
||||
/** @type {string|undefined} */
|
||||
let match
|
||||
|
||||
if (
|
||||
script &&
|
||||
region &&
|
||||
(match = likely[stringify({language, script, region})])
|
||||
) {
|
||||
schema.script = undefined
|
||||
schema.region = undefined
|
||||
} else if (script && (match = likely[stringify({language, script})])) {
|
||||
schema.script = undefined
|
||||
} else if (region && (match = likely[stringify({language, region})])) {
|
||||
schema.region = undefined
|
||||
} else if (language && (match = likely[language])) {
|
||||
// Empty.
|
||||
}
|
||||
|
||||
if (match) {
|
||||
schema.language = undefined
|
||||
merge(schema, parse(match))
|
||||
}
|
||||
|
||||
return stringify(schema)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Schema} schema
|
||||
*/
|
||||
function removeLikelySubtags(schema) {
|
||||
addLikelySubtags(schema)
|
||||
|
||||
const {language, script, region} = schema
|
||||
|
||||
if (!language) return schema
|
||||
|
||||
const maxLocale = stringify({language, script, region})
|
||||
|
||||
if (maxLocale === addLikelySubtags(parse(language))) {
|
||||
schema.script = undefined
|
||||
schema.region = undefined
|
||||
} else if (
|
||||
region &&
|
||||
maxLocale === addLikelySubtags(parse(language + '-' + region))
|
||||
) {
|
||||
schema.script = undefined
|
||||
} else if (
|
||||
script &&
|
||||
maxLocale === addLikelySubtags(parse(language + '-' + script))
|
||||
) {
|
||||
schema.region = undefined
|
||||
}
|
||||
|
||||
return schema
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize the given BCP 47 tag according to Unicode CLDR suggestions.
|
||||
*
|
||||
* @param {string} tag
|
||||
* BCP 47 tag.
|
||||
* @param {Options} [options]
|
||||
* Configuration (optional).
|
||||
* @returns {string}
|
||||
* Normal, canonical, and pretty BCP 47 tag.
|
||||
*/
|
||||
export function bcp47Normalize(tag, options) {
|
||||
const settings = options || {}
|
||||
// 1. normalize and lowercase the tag (`sgn-be-fr` -> `sfb`).
|
||||
const schema = parse(String(tag || '').toLowerCase(), settings)
|
||||
const value = stringify(schema)
|
||||
|
||||
if (!value) {
|
||||
return value
|
||||
}
|
||||
|
||||
let index = -1
|
||||
|
||||
// 2. Do fancy, expensive replaces (`ha-latn-gh` -> `ha-gh`).
|
||||
while (++index < matches.length) {
|
||||
let from = matches[index].from
|
||||
|
||||
if (from.slice(0, 4) === 'und-' && schema.language) {
|
||||
from = schema.language + from.slice(3)
|
||||
}
|
||||
|
||||
if (extendedFilter(value, from).length > 0) {
|
||||
replace(schema, from, matches[index].to)
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Do basic field replaces (`en-840` -> `en-us`).
|
||||
index = -1
|
||||
|
||||
while (++index < fields.length) {
|
||||
if (remove(schema, fields[index].from.field, fields[index].from.value)) {
|
||||
add(schema, fields[index].to.field, fields[index].to.value)
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Minimize.
|
||||
removeLikelySubtags(schema)
|
||||
|
||||
// 5. Sort variants, and sort extensions on singleton.
|
||||
schema.variants.sort()
|
||||
schema.extensions.sort(compareSingleton)
|
||||
|
||||
// 6. Warn if fields (currently only regions) should be updated but have
|
||||
// multiple choices.
|
||||
if (settings.warning) {
|
||||
/** @type {keyof many} */
|
||||
let key
|
||||
|
||||
for (key in many) {
|
||||
if (own.call(many, key)) {
|
||||
const map = many[key]
|
||||
const value = schema[key]
|
||||
if (value && own.call(map, value)) {
|
||||
const replacements = map[value]
|
||||
settings.warning(
|
||||
'Deprecated ' +
|
||||
key +
|
||||
' `' +
|
||||
value +
|
||||
'`, expected one of `' +
|
||||
replacements.join('`, `') +
|
||||
'`',
|
||||
-1,
|
||||
7
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 7. Add proper casing back.
|
||||
// Format script (ISO 15924) as titlecase (example: `Latn`):
|
||||
if (schema.script) {
|
||||
schema.script =
|
||||
schema.script.charAt(0).toUpperCase() + schema.script.slice(1)
|
||||
}
|
||||
|
||||
// Format region (ISO 3166) as uppercase (note: this doesn’t affect numeric
|
||||
// codes, which is fine):
|
||||
if (schema.region) {
|
||||
schema.region = schema.region.toUpperCase()
|
||||
}
|
||||
|
||||
return stringify(schema)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Schema} schema
|
||||
* @param {string} from
|
||||
* @param {string} to
|
||||
* @returns {void}
|
||||
*/
|
||||
function replace(schema, from, to) {
|
||||
const left = parse(from)
|
||||
const right = parse(to)
|
||||
/** @type {Array<string>} */
|
||||
const removed = []
|
||||
/** @type {string|null|undefined} */
|
||||
const lang = left.language
|
||||
/** @type {keyof schema} */
|
||||
let key
|
||||
|
||||
// Remove values from `from`:
|
||||
for (key in left) {
|
||||
if (own.call(left, key)) {
|
||||
const value = left[key]
|
||||
if (value && remove(schema, key, value)) {
|
||||
removed.push(key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add values from `to`:
|
||||
for (key in right) {
|
||||
if (own.call(right, key)) {
|
||||
const value = right[key]
|
||||
// Only add values that are defined on `to`, and that were either removed by
|
||||
// `from` or are currently empty.
|
||||
if (lang && value && (removed.includes(key) || !schema[key])) {
|
||||
add(schema, key, key === 'language' && value === 'und' ? lang : value)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Schema} object
|
||||
* @param {keyof Schema} key
|
||||
* @param {string|Array<string>|Array<Extension>} value
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function remove(object, key, value) {
|
||||
let removed = false
|
||||
/** @type {string|Array<string>|Array<Extension>|null|undefined} */
|
||||
let result
|
||||
|
||||
if (value) {
|
||||
const current = object[key]
|
||||
result = current
|
||||
|
||||
if (Array.isArray(current)) {
|
||||
result = []
|
||||
let index = -1
|
||||
|
||||
while (++index < current.length) {
|
||||
const item = current[index]
|
||||
|
||||
// @ts-expect-error: TS can’t handle the two lists.
|
||||
if (value.includes(item)) {
|
||||
removed = true
|
||||
} else {
|
||||
// @ts-expect-error: TS can’t handle the two lists.
|
||||
result.push(item)
|
||||
}
|
||||
}
|
||||
} else if (current === value) {
|
||||
result = null
|
||||
removed = true
|
||||
}
|
||||
|
||||
// @ts-expect-error: Assume the value matches.
|
||||
object[key] = result
|
||||
}
|
||||
|
||||
return removed
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Schema} object
|
||||
* @param {keyof Schema} key
|
||||
* @param {string|Array<string>|Array<Extension>} value
|
||||
* @returns {void}
|
||||
*/
|
||||
function add(object, key, value) {
|
||||
/** @type {string|Array<string>|Array<Extension>|null|undefined} */
|
||||
const current = object[key]
|
||||
|
||||
if (Array.isArray(current)) {
|
||||
const list = Array.isArray(value) ? value : [value]
|
||||
/** @type {number} */
|
||||
let index = -1
|
||||
|
||||
while (++index < list.length) {
|
||||
const item = list[index]
|
||||
|
||||
// @ts-expect-error: TS can’t handle the two lists.
|
||||
if (!current.includes(item)) {
|
||||
// @ts-expect-error: TS can’t handle the two lists.
|
||||
current.push(item)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// @ts-expect-error: Assume the value matches.
|
||||
object[key] = value
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Extension} left
|
||||
* @param {Extension} right
|
||||
* @returns {number}
|
||||
*/
|
||||
function compareSingleton(left, right) {
|
||||
if (left.singleton > right.singleton) {
|
||||
return 1
|
||||
}
|
||||
|
||||
if (left.singleton < right.singleton) {
|
||||
return -1
|
||||
}
|
||||
|
||||
// It is invalid to have more than one extension with the same singleton so
|
||||
// we should never reach this code.
|
||||
return 0
|
||||
}
|
4
node_modules/bcp-47-normalize/lib/likely.d.ts
generated
vendored
Normal file
4
node_modules/bcp-47-normalize/lib/likely.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* @type {Record<string, string>}
|
||||
*/
|
||||
export const likely: Record<string, string>;
|
8039
node_modules/bcp-47-normalize/lib/likely.js
generated
vendored
Normal file
8039
node_modules/bcp-47-normalize/lib/likely.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
10
node_modules/bcp-47-normalize/lib/many.d.ts
generated
vendored
Normal file
10
node_modules/bcp-47-normalize/lib/many.d.ts
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* @typedef {'script'|'region'|'variants'} Field
|
||||
*/
|
||||
/**
|
||||
* @type {{region: Record<string, Array<string>>}}
|
||||
*/
|
||||
export const many: {
|
||||
region: Record<string, Array<string>>;
|
||||
};
|
||||
export type Field = 'script' | 'region' | 'variants';
|
95
node_modules/bcp-47-normalize/lib/many.js
generated
vendored
Normal file
95
node_modules/bcp-47-normalize/lib/many.js
generated
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* @typedef {'script'|'region'|'variants'} Field
|
||||
*/
|
||||
|
||||
/**
|
||||
* @type {{region: Record<string, Array<string>>}}
|
||||
*/
|
||||
export const many = {
|
||||
region: {
|
||||
172: [
|
||||
'ru',
|
||||
'am',
|
||||
'az',
|
||||
'by',
|
||||
'ge',
|
||||
'kg',
|
||||
'kz',
|
||||
'md',
|
||||
'tj',
|
||||
'tm',
|
||||
'ua',
|
||||
'uz'
|
||||
],
|
||||
200: ['cz', 'sk'],
|
||||
530: ['cw', 'sx', 'bq'],
|
||||
532: ['cw', 'sx', 'bq'],
|
||||
536: ['sa', 'iq'],
|
||||
582: ['fm', 'mh', 'mp', 'pw'],
|
||||
810: [
|
||||
'ru',
|
||||
'am',
|
||||
'az',
|
||||
'by',
|
||||
'ee',
|
||||
'ge',
|
||||
'kz',
|
||||
'kg',
|
||||
'lv',
|
||||
'lt',
|
||||
'md',
|
||||
'tj',
|
||||
'tm',
|
||||
'ua',
|
||||
'uz'
|
||||
],
|
||||
830: ['je', 'gg'],
|
||||
890: ['rs', 'me', 'si', 'hr', 'mk', 'ba'],
|
||||
891: ['rs', 'me'],
|
||||
an: ['cw', 'sx', 'bq'],
|
||||
cs: ['rs', 'me'],
|
||||
fq: ['aq', 'tf'],
|
||||
nt: ['sa', 'iq'],
|
||||
pc: ['fm', 'mh', 'mp', 'pw'],
|
||||
su: [
|
||||
'ru',
|
||||
'am',
|
||||
'az',
|
||||
'by',
|
||||
'ee',
|
||||
'ge',
|
||||
'kz',
|
||||
'kg',
|
||||
'lv',
|
||||
'lt',
|
||||
'md',
|
||||
'tj',
|
||||
'tm',
|
||||
'ua',
|
||||
'uz'
|
||||
],
|
||||
yu: ['rs', 'me'],
|
||||
'062': ['034', '143'],
|
||||
ant: ['cw', 'sx', 'bq'],
|
||||
scg: ['rs', 'me'],
|
||||
ntz: ['sa', 'iq'],
|
||||
sun: [
|
||||
'ru',
|
||||
'am',
|
||||
'az',
|
||||
'by',
|
||||
'ee',
|
||||
'ge',
|
||||
'kz',
|
||||
'kg',
|
||||
'lv',
|
||||
'lt',
|
||||
'md',
|
||||
'tj',
|
||||
'tm',
|
||||
'ua',
|
||||
'uz'
|
||||
],
|
||||
yug: ['rs', 'me']
|
||||
}
|
||||
}
|
13
node_modules/bcp-47-normalize/lib/matches.d.ts
generated
vendored
Normal file
13
node_modules/bcp-47-normalize/lib/matches.d.ts
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* @typedef Change
|
||||
* @property {string} from
|
||||
* @property {string} to
|
||||
*/
|
||||
/**
|
||||
* @type {Array<Change>}
|
||||
*/
|
||||
export const matches: Array<Change>;
|
||||
export type Change = {
|
||||
from: string;
|
||||
to: string;
|
||||
};
|
1859
node_modules/bcp-47-normalize/lib/matches.js
generated
vendored
Normal file
1859
node_modules/bcp-47-normalize/lib/matches.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
22
node_modules/bcp-47-normalize/license
generated
vendored
Normal file
22
node_modules/bcp-47-normalize/license
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2020 Titus Wormer <tituswormer@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
'Software'), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
91
node_modules/bcp-47-normalize/package.json
generated
vendored
Normal file
91
node_modules/bcp-47-normalize/package.json
generated
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
{
|
||||
"name": "bcp-47-normalize",
|
||||
"version": "2.3.0",
|
||||
"description": "Normalize, canonicalize, and format BCP 47 tags",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"bcp",
|
||||
"47",
|
||||
"bcp47",
|
||||
"bcp-47",
|
||||
"language",
|
||||
"region",
|
||||
"script",
|
||||
"tag",
|
||||
"subtag",
|
||||
"format",
|
||||
"pretty",
|
||||
"normal",
|
||||
"canonical"
|
||||
],
|
||||
"repository": "wooorm/bcp-47-normalize",
|
||||
"bugs": "https://github.com/wooorm/bcp-47-normalize/issues",
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/wooorm"
|
||||
},
|
||||
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
|
||||
"contributors": [
|
||||
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
|
||||
],
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"main": "index.js",
|
||||
"types": "index.d.ts",
|
||||
"files": [
|
||||
"lib/",
|
||||
"index.d.ts",
|
||||
"index.js"
|
||||
],
|
||||
"dependencies": {
|
||||
"bcp-47": "^2.0.0",
|
||||
"bcp-47-match": "^2.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.0.0",
|
||||
"@types/node-fetch": "^3.0.0",
|
||||
"@types/xast": "^2.0.0",
|
||||
"c8": "^8.0.0",
|
||||
"cldr-core": "^43.0.0",
|
||||
"node-fetch": "^3.0.0",
|
||||
"prettier": "^3.0.0",
|
||||
"remark-cli": "^11.0.0",
|
||||
"remark-preset-wooorm": "^9.0.0",
|
||||
"type-coverage": "^2.0.0",
|
||||
"typescript": "^5.0.0",
|
||||
"unist-util-visit": "^5.0.0",
|
||||
"xast-util-from-xml": "^3.0.0",
|
||||
"xo": "^0.55.0"
|
||||
},
|
||||
"scripts": {
|
||||
"prepack": "npm run generate && npm run build && npm run format",
|
||||
"generate": "node --conditions development build.js",
|
||||
"build": "tsc --build --clean && tsc --build && type-coverage",
|
||||
"format": "remark . -qfo && prettier . -w --log-level warn && xo --fix",
|
||||
"test-api": "node --conditions development test.js",
|
||||
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
|
||||
"test": "npm run generate && npm run build && npm run format && npm run test-coverage"
|
||||
},
|
||||
"prettier": {
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"singleQuote": true,
|
||||
"bracketSpacing": false,
|
||||
"semi": false,
|
||||
"trailingComma": "none"
|
||||
},
|
||||
"xo": {
|
||||
"prettier": true
|
||||
},
|
||||
"remarkConfig": {
|
||||
"plugins": [
|
||||
"preset-wooorm"
|
||||
]
|
||||
},
|
||||
"typeCoverage": {
|
||||
"atLeast": 100,
|
||||
"detail": true,
|
||||
"strict": true,
|
||||
"ignoreCatch": true
|
||||
}
|
||||
}
|
207
node_modules/bcp-47-normalize/readme.md
generated
vendored
Normal file
207
node_modules/bcp-47-normalize/readme.md
generated
vendored
Normal file
@@ -0,0 +1,207 @@
|
||||
# bcp-47-normalize
|
||||
|
||||
[![Build][build-badge]][build]
|
||||
[![Coverage][coverage-badge]][coverage]
|
||||
[![Downloads][downloads-badge]][downloads]
|
||||
[![Size][size-badge]][size]
|
||||
|
||||
Normalize, canonicalize, and format [BCP 47][spec] tags.
|
||||
|
||||
## Contents
|
||||
|
||||
* [What is this?](#what-is-this)
|
||||
* [When should I use this?](#when-should-i-use-this)
|
||||
* [Install](#install)
|
||||
* [Use](#use)
|
||||
* [API](#api)
|
||||
* [`bcp47Normalize(tag[, options])`](#bcp47normalizetag-options)
|
||||
* [Types](#types)
|
||||
* [Compatibility](#compatibility)
|
||||
* [Security](#security)
|
||||
* [Related](#related)
|
||||
* [Contribute](#contribute)
|
||||
* [License](#license)
|
||||
|
||||
## What is this?
|
||||
|
||||
This package takes BCP 47 tags and makes them uniform.
|
||||
It removes unneeded info (`en-us` -> `en`) and replaces deprecated,
|
||||
overlong, and otherwise unpreferred values with preferred values
|
||||
(`en-bu` -> `en-MM`).
|
||||
It works by applying [Unicode CLDR suggestions][alias].
|
||||
|
||||
## When should I use this?
|
||||
|
||||
You can use this package when dealing with user-provided language tags and want
|
||||
to normalize and clean them.
|
||||
|
||||
## Install
|
||||
|
||||
This package is [ESM only][esm].
|
||||
In Node.js (version 14.14+, 16.0+), install with [npm][]:
|
||||
|
||||
```sh
|
||||
npm install bcp-47-normalize
|
||||
```
|
||||
|
||||
In Deno with [`esm.sh`][esmsh]:
|
||||
|
||||
```js
|
||||
import {bcp47Normalize} from 'https://esm.sh/bcp-47-normalize@2'
|
||||
```
|
||||
|
||||
In browsers with [`esm.sh`][esmsh]:
|
||||
|
||||
```html
|
||||
<script type="module">
|
||||
import {bcp47Normalize} from 'https://esm.sh/bcp-47-normalize@2?bundle'
|
||||
</script>
|
||||
```
|
||||
|
||||
## Use
|
||||
|
||||
```js
|
||||
import {bcp47Normalize} from 'bcp-47-normalize'
|
||||
|
||||
const tags = [
|
||||
'de-de-1901',
|
||||
'en-gb',
|
||||
'en-us',
|
||||
'en-bu',
|
||||
'hy-arevmda',
|
||||
'nld-nl',
|
||||
'no-nyn',
|
||||
'pt-br',
|
||||
'pt-pt',
|
||||
'zh-hans-cn'
|
||||
]
|
||||
|
||||
tags.forEach((tag) => console.log('%s -> %s', tag, bcp47Normalize(tag)))
|
||||
```
|
||||
|
||||
Yields:
|
||||
|
||||
```txt
|
||||
de-de-1901 -> de-1901
|
||||
en-gb -> en-GB
|
||||
en-us -> en
|
||||
en-bu -> en-MM
|
||||
hy-arevmda -> hyw
|
||||
nld-nl -> nl
|
||||
no-nyn -> nn
|
||||
pt-br -> pt
|
||||
pt-pt -> pt-PT
|
||||
zh-hans-cn -> zh
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
This package exports the identifier `bcp47Normalize`.
|
||||
There is no default export.
|
||||
|
||||
### `bcp47Normalize(tag[, options])`
|
||||
|
||||
Normalize the given BCP 47 tag according to [Unicode CLDR suggestions][alias].
|
||||
|
||||
###### Parameters
|
||||
|
||||
* `tag` (`string`)
|
||||
— BCP 47 tag
|
||||
* `options.forgiving` (`boolean`, default: `false`)
|
||||
— passed to `bcp-47` as [`options.forgiving`][forgiving]
|
||||
* `options.warning` (`Function?`, default: `undefined`)
|
||||
— passed to `bcp-47` as [`options.warning`][warning]
|
||||
|
||||
One additional warning is given:
|
||||
|
||||
| code | reason |
|
||||
| :--- | :--------------------------------------------------------- |
|
||||
| 7 | Deprecated region `CURRENT`, expected one of `SUGGESTIONS` |
|
||||
|
||||
This warning is only given if the region cannot be automatically fixed (when
|
||||
regions split into multiple regions).
|
||||
|
||||
###### Returns
|
||||
|
||||
Normal, canonical, and pretty [BCP 47][spec] tag (`string`).
|
||||
|
||||
## Types
|
||||
|
||||
This package is fully typed with [TypeScript][].
|
||||
It exports the additional types `Options` and `Warning`.
|
||||
|
||||
## Compatibility
|
||||
|
||||
This package is at least compatible with all maintained versions of Node.js.
|
||||
As of now, that is Node.js 14.14+ and 16.0+.
|
||||
It also works in Deno and modern browsers.
|
||||
|
||||
## Security
|
||||
|
||||
This package is safe.
|
||||
|
||||
## Related
|
||||
|
||||
* [`wooorm/bcp-47`](https://github.com/wooorm/bcp-47)
|
||||
— parse and stringify BCP 47 language tags
|
||||
* [`wooorm/bcp-47-match`](https://github.com/wooorm/bcp-47-match)
|
||||
— match BCP 47 language tags with language ranges per RFC 4647
|
||||
* [`wooorm/iso-3166`](https://github.com/wooorm/iso-3166)
|
||||
— ISO 3166 codes
|
||||
* [`wooorm/iso-639-2`](https://github.com/wooorm/iso-639-2)
|
||||
— ISO 639-2 codes
|
||||
* [`wooorm/iso-639-3`](https://github.com/wooorm/iso-639-3)
|
||||
— ISO 639-3 codes
|
||||
* [`wooorm/iso-15924`](https://github.com/wooorm/iso-15924)
|
||||
— ISO 15924 codes
|
||||
* [`wooorm/un-m49`](https://github.com/wooorm/un-m49)
|
||||
— UN M49 codes
|
||||
|
||||
## Contribute
|
||||
|
||||
Yes please!
|
||||
See [How to Contribute to Open Source][contribute].
|
||||
|
||||
## License
|
||||
|
||||
[MIT][license] © [Titus Wormer][author]
|
||||
|
||||
<!-- Definitions -->
|
||||
|
||||
[build-badge]: https://github.com/wooorm/bcp-47-normalize/workflows/main/badge.svg
|
||||
|
||||
[build]: https://github.com/wooorm/bcp-47-normalize/actions
|
||||
|
||||
[coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/bcp-47-normalize.svg
|
||||
|
||||
[coverage]: https://codecov.io/github/wooorm/bcp-47-normalize
|
||||
|
||||
[downloads-badge]: https://img.shields.io/npm/dm/bcp-47-normalize.svg
|
||||
|
||||
[downloads]: https://www.npmjs.com/package/bcp-47-normalize
|
||||
|
||||
[size-badge]: https://img.shields.io/bundlephobia/minzip/bcp-47-normalize.svg
|
||||
|
||||
[size]: https://bundlephobia.com/result?p=bcp-47-normalize
|
||||
|
||||
[npm]: https://docs.npmjs.com/cli/install
|
||||
|
||||
[esmsh]: https://esm.sh
|
||||
|
||||
[license]: license
|
||||
|
||||
[author]: https://wooorm.com
|
||||
|
||||
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
|
||||
|
||||
[typescript]: https://www.typescriptlang.org
|
||||
|
||||
[contribute]: https://opensource.guide/how-to-contribute/
|
||||
|
||||
[spec]: https://tools.ietf.org/rfc/bcp/bcp47.html
|
||||
|
||||
[alias]: https://github.com/unicode-org/cldr/blob/142b327/common/supplemental/supplementalMetadata.xml#L32
|
||||
|
||||
[forgiving]: https://github.com/wooorm/bcp-47#optionsforgiving
|
||||
|
||||
[warning]: https://github.com/wooorm/bcp-47#optionswarning
|
Reference in New Issue
Block a user