mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-12 04:50:18 +00:00
Add types for bcp-47 (#41195)
This commit is contained in:
committed by
Andrew Branch
parent
ba94ba69b1
commit
a7f75df583
@@ -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);
|
||||
Vendored
+39
@@ -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,
|
||||
}
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user