[accept-language-parser] introduce generic

This commit is contained in:
chatoo2412
2019-01-24 14:26:47 +09:00
parent ca809fa16f
commit 118178afb4
2 changed files with 11 additions and 4 deletions
@@ -20,11 +20,17 @@ const l3: AcceptLanguageParser.Language = {
quality: 0.9
};
type Lang = "en-US" | "ko-KR";
const enUs: Lang = "en-US";
const koKr: Lang = "ko-KR";
const parsed1: AcceptLanguageParser.Language[] = AcceptLanguageParser.parse('');
const pick1: string | null = AcceptLanguageParser.pick([''], '');
const pick2: string | null = AcceptLanguageParser.pick([''], [l1, l2, l3]);
const pick3: string | null = AcceptLanguageParser.pick([''], '', {});
const pick4: string | null = AcceptLanguageParser.pick([''], '', { loose: true });
const pick5: Lang | null = AcceptLanguageParser.pick<Lang>([enUs, koKr], [l1, l2, l3]);
const pick6: Lang | null = AcceptLanguageParser.pick([enUs, koKr], [l1, l2, l3]);
const pickOptions: AcceptLanguageParser.PickOptions = {
loose: true
+5 -4
View File
@@ -1,17 +1,18 @@
// Type definitions for accept-language-parser 1.5
// Project: https://github.com/opentable/accept-language-parser
// Definitions by: Niklas Wulf <https://github.com/kampfgnom>
// Wooram Jun <https://github.com/chatoo2412>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
// https://github.com/opentable/accept-language-parser/blob/v1.4.1/index.js
// https://github.com/opentable/accept-language-parser/blob/v1.5.0/index.js
export function parse(acceptLanguage: string): Language[];
export function pick(
supportedLanguages: string[],
export function pick<T extends string>(
supportedLanguages: T[],
acceptLanguage: string | Language[],
options?: PickOptions
): string | null;
): T | null;
export interface Language {
code: string;