diff --git a/types/bcp-47/bcp-47-tests.ts b/types/bcp-47/bcp-47-tests.ts new file mode 100644 index 0000000000..fffc5e31fe --- /dev/null +++ b/types/bcp-47/bcp-47-tests.ts @@ -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); diff --git a/types/bcp-47/index.d.ts b/types/bcp-47/index.d.ts new file mode 100644 index 0000000000..3466919b8a --- /dev/null +++ b/types/bcp-47/index.d.ts @@ -0,0 +1,39 @@ +// Type definitions for bcp-47 1.0 +// Project: https://github.com/wooorm/bcp-47#readme +// Definitions by: Chris Barth +// 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, +} diff --git a/types/bcp-47/tsconfig.json b/types/bcp-47/tsconfig.json new file mode 100644 index 0000000000..ea0b31c26d --- /dev/null +++ b/types/bcp-47/tsconfig.json @@ -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" + ] +} diff --git a/types/bcp-47/tslint.json b/types/bcp-47/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/bcp-47/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }