Skip to content

Commit

Permalink
[ADD] nameTH in function
Browse files Browse the repository at this point in the history
  • Loading branch information
safesit23 committed Dec 28, 2020
1 parent 4c8752b commit fa30920
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
9 changes: 6 additions & 3 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
declare module "iso-639-1" {
interface ISO6391 {
getName: (code: string) => string;
getAllNames: () => Array<string>;
getNameEN: (code: string) => string;
getNameTH: (code: string) => string;
getNativeName: (code: string) => string;
getAllNamesTH: () => Array<string>;
getAllNamesEN: () => Array<string>;
getAllNativeNames: () => Array<string>;
getCode: (name: string) => string;
getAllCodes: () => Array<string>;
validate: (code: string) => boolean;
getLanguages: (codes: Array<string>) => Array<{
code: string;
name: string;
nameTH: string;
nameEN: string;
nativeName: string;
}>;
}
Expand Down
22 changes: 16 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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()
);
});
Expand Down

0 comments on commit fa30920

Please sign in to comment.