From fa3092076d1516d9a6392f1d311e4f3e1425f023 Mon Sep 17 00:00:00 2001 From: jatawatsafe Date: Mon, 28 Dec 2020 23:37:51 +0700 Subject: [PATCH] [ADD] nameTH in function --- index.d.ts | 9 ++++++--- src/index.js | 22 ++++++++++++++++------ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/index.d.ts b/index.d.ts index 5178545..8b5cb55 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,15 +1,18 @@ declare module "iso-639-1" { interface ISO6391 { - getName: (code: string) => string; - getAllNames: () => Array; + getNameEN: (code: string) => string; + getNameTH: (code: string) => string; getNativeName: (code: string) => string; + getAllNamesTH: () => Array; + getAllNamesEN: () => Array; getAllNativeNames: () => Array; getCode: (name: string) => string; getAllCodes: () => Array; validate: (code: string) => boolean; getLanguages: (codes: Array) => Array<{ code: string; - name: string; + nameTH: string; + nameEN: string; nativeName: string; }>; } diff --git a/src/index.js b/src/index.js index 9069e2d..d1a888a 100644 --- a/src/index.js +++ b/src/index.js @@ -4,17 +4,26 @@ export default class ISO6391 { static getLanguages(codes = []) { return codes.map(code => ({ code, - name: ISO6391.getName(code), + nameTH: ISO6391.getNameTH(code), + nameEN: ISO6391.getNameEN(code), nativeName: ISO6391.getNativeName(code), })); } - static getName(code) { - return ISO6391.validate(code) ? LANGUAGES_LIST[code].name : ''; + static getNameTH(code) { + return ISO6391.validate(code) ? LANGUAGES_LIST[code].nameTH : ''; } - static getAllNames() { - return Object.values(LANGUAGES_LIST).map(l => l.name); + static getNameEN(code) { + return ISO6391.validate(code) ? LANGUAGES_LIST[code].nameEN : ''; + } + + static getAllNamesEN() { + return Object.values(LANGUAGES_LIST).map(l => l.nameEN); + } + + static getAllNamesTH() { + return Object.values(LANGUAGES_LIST).map(l => l.nameTH); } static getNativeName(code) { @@ -30,7 +39,8 @@ export default class ISO6391 { const language = LANGUAGES_LIST[code]; return ( - language.name.toLowerCase() === name.toLowerCase() || + language.nameEN.toLowerCase() === name.toLowerCase() || + language.nameTH === name || language.nativeName.toLowerCase() === name.toLowerCase() ); });