Add types for bcp-47 (#41195)

This commit is contained in:
Chris Barth
2019-12-27 09:12:51 -06:00
committed by Andrew Branch
parent ba94ba69b1
commit a7f75df583
4 changed files with 84 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
import bcp47 = require('bcp-47');
const bcpParse = bcp47.parse;
const bcpStringify = bcp47.stringify;
const result: bcp47.Schema = bcpParse('en-US');
const locale: string = bcpStringify(result);
const schema: bcp47.Schema = {
language: 'en',
region: 'US'
};
bcpStringify(schema);
const parseOptions: bcp47.ParseOptions = {
warning: (message: string, code: number, offset: number) => {},
};
bcpParse('en-US', parseOptions);
+39
View File
@@ -0,0 +1,39 @@
// Type definitions for bcp-47 1.0
// Project: https://github.com/wooorm/bcp-47#readme
// Definitions by: Chris Barth <https://github.com/cjbarth>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export function parse(tag: string, options?: ParseOptions): Schema;
export function stringify(schema: Schema): string;
export interface ParseOptions {
warning?: (errorMessage: string, errorCode: ErrorCodes, offset: number) => void;
forgiving?: boolean;
normalize?: boolean;
}
export interface Schema {
language?: string;
extendedLanguageSubtags?: string[];
script?: string;
region?: string;
variants?: string[];
extensions?: LocaleExtension[];
privateuse?: string[];
regular?: string;
irregular?: string;
}
export interface LocaleExtension {
singleton: string;
extensions: string[];
}
export enum ErrorCodes {
errVariantTooLong = 1,
errExtensionTooLong = 2,
errTooManySubtags = 3,
errEmptyExtension = 4,
errPrivateUseTooLong = 5,
errExtraContent = 6,
}
+23
View File
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"bcp-47-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }