├── .github ├── CODEOWNERS ├── dependabot.yml └── workflows │ ├── test.yml │ └── publish-package.yml ├── .gitignore ├── jest.config.js ├── .prettierrc ├── src ├── tests │ ├── languages.test.ts │ ├── getName.test.ts │ ├── ids │ │ ├── getLocale.test.ts │ │ ├── getOSXLocale.test.ts │ │ ├── getISO_639_1.test.ts │ │ ├── getISO_639_2.test.ts │ │ ├── getISO_639_3.test.ts │ │ ├── getOSXCode.test.ts │ │ ├── getAndroidCode.test.ts │ │ ├── getGlottolog.test.ts │ │ └── getIds.test.ts │ ├── getRegion.test.ts │ ├── getDirection.test.ts │ ├── getRegionCode.test.ts │ ├── getCountry.test.ts │ ├── getCountryCode.test.ts │ ├── getNativeName.test.ts │ ├── flag │ │ ├── primaryColor │ │ │ ├── getPrimaryHex.test.ts │ │ │ ├── getPrimaryRGB.test.ts │ │ │ ├── getPrimaryBase10.test.ts │ │ │ ├── getPrimaryCMYK.test.ts │ │ │ └── getPrimaryColor.test.ts │ │ ├── flagColors │ │ │ ├── getBase10FlagColors.test.ts │ │ │ ├── getHexFlagColors.test.ts │ │ │ ├── getRGBFlagColors.test.ts │ │ │ ├── getCMYKFlagColors.test.ts │ │ │ └── getFlagColors.test.ts │ │ ├── getEmoji.test.ts │ │ ├── getImage.test.ts │ │ └── getFlag.test.ts │ ├── getRegionLanguages.test.ts │ ├── findLanguage.test.ts │ ├── getLanguage.test.ts │ └── getCountryLanguages.test.ts ├── functions │ ├── getName.ts │ ├── ids │ │ ├── getIds.ts │ │ ├── getLocale.ts │ │ ├── getOSXCode.ts │ │ ├── getOSXLocale.ts │ │ ├── getAndroidCode.ts │ │ ├── getISO_639_1.ts │ │ ├── getISO_639_2.ts │ │ ├── getISO_639_3.ts │ │ └── getGlottolog.ts │ ├── getCountry.ts │ ├── getNativeName.ts │ ├── getDirection.ts │ ├── getCountryCode.ts │ ├── flag │ │ ├── primaryColor │ │ │ ├── getPrimaryHex.ts │ │ │ ├── getPrimaryRGB.ts │ │ │ ├── getPrimaryBase10.ts │ │ │ ├── getPrimaryCMYK.ts │ │ │ └── getPrimaryColor.ts │ │ ├── flagColors │ │ │ ├── getFlagColors.ts │ │ │ ├── getHexFlagColors.ts │ │ │ ├── getRGBFlagColors.ts │ │ │ ├── getCMYKFlagColors.ts │ │ │ └── getBase10FlagColors.ts │ │ ├── getFlag.ts │ │ ├── getImage.ts │ │ └── getEmoji.ts │ ├── getRegion.ts │ ├── getRegionCode.ts │ ├── getRegionLanguages.ts │ ├── getCountryLanguages.ts │ ├── getLanguage.ts │ └── findLanguage.ts └── index.ts ├── LICENSE ├── package.json ├── cliff.toml ├── CHANGELOG.md ├── tsconfig.json └── README.md /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @Bas950 @ImRodry -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | bin 3 | .vscode 4 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | preset: "ts-jest", 3 | testMatch: ["**/?(*.)+(spec|test).js?(x)"] 4 | }; 5 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "none", 3 | "useTabs": true, 4 | "endOfLine": "lf", 5 | "proseWrap": "never", 6 | "arrowParens": "avoid", 7 | "printWidth": 150, 8 | "semi": true 9 | } 10 | -------------------------------------------------------------------------------- /src/tests/languages.test.ts: -------------------------------------------------------------------------------- 1 | import languages from ".."; 2 | 3 | describe("Languages array", () => { 4 | test("Expect languages to be an array with length", () => { 5 | expect(languages).toBeInstanceOf(Array); 6 | expect(languages[0]).toBeInstanceOf(Object); 7 | expect(languages.length).toBeTruthy(); 8 | }); 9 | }); 10 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "npm" 4 | directory: "/" 5 | schedule: 6 | interval: "weekly" 7 | assignees: 8 | - "ImRodry" 9 | commit-message: 10 | prefix: chore 11 | include: scope 12 | labels: 13 | - "dependencies" 14 | open-pull-requests-limit: 15 15 | -------------------------------------------------------------------------------- /src/functions/getName.ts: -------------------------------------------------------------------------------- 1 | import findLanguage from "./findLanguage"; 2 | 3 | /** 4 | * Gets the name of a language 5 | * @param lang The locale, ISO code or name of the language to find the name of 6 | * @returns The name of the language, or `null` if it is not found 7 | */ 8 | export function getName(lang: string) { 9 | const language = findLanguage(lang); 10 | return language?.name ?? null; 11 | } 12 | -------------------------------------------------------------------------------- /src/functions/ids/getIds.ts: -------------------------------------------------------------------------------- 1 | import findLanguage from "../findLanguage"; 2 | 3 | /** 4 | * Gets the ids of a language 5 | * @param lang The locale, ISO code or name of the language to find the ids of 6 | * @returns The ids of the language, or `null` if it is not found 7 | */ 8 | export function getIds(lang: string) { 9 | const language = findLanguage(lang); 10 | return language?.ids ?? null; 11 | } 12 | -------------------------------------------------------------------------------- /src/functions/ids/getLocale.ts: -------------------------------------------------------------------------------- 1 | import findLanguage from "../findLanguage"; 2 | 3 | /** 4 | * Gets the locale of a language 5 | * @param lang The locale, ISO code or name of the language to find the locale of 6 | * @returns The locale of the language, or `null` if it is not found 7 | */ 8 | export function getLocale(lang: string) { 9 | const language = findLanguage(lang); 10 | return language?.ids.locale ?? null; 11 | } 12 | -------------------------------------------------------------------------------- /src/functions/getCountry.ts: -------------------------------------------------------------------------------- 1 | import findLanguage from "./findLanguage"; 2 | 3 | /** 4 | * Gets the name of a language's country 5 | * @param lang The locale, ISO code or name of the language to find the country name of 6 | * @returns The name of the language's country, or `null` if it is not found 7 | */ 8 | export function getCountry(lang: string) { 9 | const language = findLanguage(lang); 10 | return language?.country ?? null; 11 | } 12 | -------------------------------------------------------------------------------- /src/functions/getNativeName.ts: -------------------------------------------------------------------------------- 1 | import findLanguage from "./findLanguage"; 2 | 3 | /** 4 | * Gets the native name of a language 5 | * @param lang The locale, ISO code or name of the language to find the native name of 6 | * @returns The native name of the language, or `null` if it is not found 7 | */ 8 | export function getNativeName(lang: string) { 9 | const language = findLanguage(lang); 10 | return language?.nativeName ?? null; 11 | } 12 | -------------------------------------------------------------------------------- /src/functions/getDirection.ts: -------------------------------------------------------------------------------- 1 | import findLanguage from "./findLanguage"; 2 | 3 | /** 4 | * Gets the direction of a language's text 5 | * @param lang The locale, ISO code or name of the language to find the direction of 6 | * @returns The direction of the language's text, or `null` if it is not found 7 | */ 8 | export function getDirection(lang: string) { 9 | const language = findLanguage(lang); 10 | return language?.direction ?? null; 11 | } 12 | -------------------------------------------------------------------------------- /src/functions/getCountryCode.ts: -------------------------------------------------------------------------------- 1 | import findLanguage from "./findLanguage"; 2 | 3 | /** 4 | * Gets the code of a language's country 5 | * @param lang The locale, ISO code or name of the language to find the country code of 6 | * @returns The code of the language's country, or `null` if it is not found 7 | */ 8 | export function getCountryCode(lang: string) { 9 | const language = findLanguage(lang); 10 | return language?.countryCode ?? null; 11 | } 12 | -------------------------------------------------------------------------------- /src/functions/flag/primaryColor/getPrimaryHex.ts: -------------------------------------------------------------------------------- 1 | import findLanguage from "../../findLanguage"; 2 | 3 | /** 4 | * Gets the HEX color of a language 5 | * @param lang The locale, ISO code or name of the language to find the color of 6 | * @returns The HEX color of the language, or `null` if it is not found 7 | */ 8 | export function getPrimaryHex(lang: string) { 9 | const language = findLanguage(lang); 10 | return language?.flag.primaryColor.hex ?? null; 11 | } 12 | -------------------------------------------------------------------------------- /src/functions/ids/getOSXCode.ts: -------------------------------------------------------------------------------- 1 | import findLanguage from "../findLanguage"; 2 | 3 | /** 4 | * Gets the OS X locale identifier used to name ".lproj" directories 5 | * @param lang The locale, ISO code or name of the language to find the OS X code of 6 | * @returns The OS X code of the language, or `null` if it is not found 7 | */ 8 | export function getOSXCode(lang: string) { 9 | const language = findLanguage(lang); 10 | return language?.ids.osxCode ?? null; 11 | } 12 | -------------------------------------------------------------------------------- /src/functions/flag/primaryColor/getPrimaryRGB.ts: -------------------------------------------------------------------------------- 1 | import findLanguage from "../../findLanguage"; 2 | 3 | /** 4 | * Gets the RGB color of a language 5 | * @param lang The locale, ISO code or name of the language to find the color of 6 | * @returns The RGB array of colors of the language, or `null` if it is not found 7 | */ 8 | export function getPrimaryRGB(lang: string) { 9 | const language = findLanguage(lang); 10 | return language?.flag.primaryColor.rgb ?? null; 11 | } 12 | -------------------------------------------------------------------------------- /src/functions/flag/primaryColor/getPrimaryBase10.ts: -------------------------------------------------------------------------------- 1 | import findLanguage from "../../findLanguage"; 2 | 3 | /** 4 | * Gets the base-10 color of a language 5 | * @param lang The locale, ISO code or name of the language to find the color of 6 | * @returns The base-10 color of the language, or `null` if it is not found 7 | */ 8 | export function getPrimaryBase10(lang: string) { 9 | const language = findLanguage(lang); 10 | return language?.flag.primaryColor.base10 ?? null; 11 | } 12 | -------------------------------------------------------------------------------- /src/functions/flag/primaryColor/getPrimaryCMYK.ts: -------------------------------------------------------------------------------- 1 | import findLanguage from "../../findLanguage"; 2 | 3 | /** 4 | * Gets the CMYK color of a language 5 | * @param lang The locale, ISO code or name of the language to find the color of 6 | * @returns The CMYK array of colors of the language, or `null` if it is not found 7 | */ 8 | export function getPrimaryCMYK(lang: string) { 9 | const language = findLanguage(lang); 10 | return language?.flag.primaryColor.cmyk ?? null; 11 | } 12 | -------------------------------------------------------------------------------- /src/functions/ids/getOSXLocale.ts: -------------------------------------------------------------------------------- 1 | import findLanguage from "../findLanguage"; 2 | 3 | /** 4 | * Gets the OS X locale used to name translated resources (i.e. uk, zh-Hans, zh_HK) 5 | * @param lang The locale, ISO code or name of the language to find the OS X locale of 6 | * @returns The OS X locale of the language, or `null` if it is not found 7 | */ 8 | export function getOSXLocale(lang: string) { 9 | const language = findLanguage(lang); 10 | return language?.ids.osxLocale ?? null; 11 | } 12 | -------------------------------------------------------------------------------- /src/functions/flag/flagColors/getFlagColors.ts: -------------------------------------------------------------------------------- 1 | import findLanguage from "../../findLanguage"; 2 | 3 | /** 4 | * Gets all the colors in a language's flag 5 | * @param lang The locale, ISO code or name of the language to find the colors of 6 | * @returns An array with objects of all the colors in the language's flag, or `null` if it is not found 7 | */ 8 | export function getFlagColors(lang: string) { 9 | const language = findLanguage(lang); 10 | return language?.flag.flagColors ?? null; 11 | } 12 | -------------------------------------------------------------------------------- /src/functions/getRegion.ts: -------------------------------------------------------------------------------- 1 | import findLanguage from "./findLanguage"; 2 | 3 | /** 4 | * Gets the name of a language's region, if any 5 | * @param lang The locale, ISO code or name of the language to find the region name of 6 | * @returns The language's region name, `null` if no language is found 7 | * or `undefined` if the language doesn't have a region 8 | */ 9 | export function getRegion(lang: string) { 10 | const language = findLanguage(lang); 11 | return language ? language.region : null; 12 | } 13 | -------------------------------------------------------------------------------- /src/functions/ids/getAndroidCode.ts: -------------------------------------------------------------------------------- 1 | import findLanguage from "../findLanguage"; 2 | 3 | /** 4 | * Gets the Android locale identifier used to name "values-" directories in Android-based OSs 5 | * @param lang The locale, ISO code or name of the language to find the Android code of 6 | * @returns The Android code of the language, or `null` if it is not found 7 | */ 8 | export function getAndroidCode(lang: string) { 9 | const language = findLanguage(lang); 10 | return language?.ids.androidCode ?? null; 11 | } 12 | -------------------------------------------------------------------------------- /src/functions/flag/flagColors/getHexFlagColors.ts: -------------------------------------------------------------------------------- 1 | import findLanguage from "../../findLanguage"; 2 | 3 | /** 4 | * Gets the HEX colors in a language's flag 5 | * @param lang The locale, ISO code or name of the language to find the colors of 6 | * @returns An array with all the HEX colors in the language's flag, or `null` if it is not found 7 | */ 8 | export function getHexFlagColors(lang: string) { 9 | const language = findLanguage(lang); 10 | return language?.flag.flagColors.map(c => c.hex) ?? null; 11 | } 12 | -------------------------------------------------------------------------------- /src/functions/flag/flagColors/getRGBFlagColors.ts: -------------------------------------------------------------------------------- 1 | import findLanguage from "../../findLanguage"; 2 | 3 | /** 4 | * Gets the RGB colors in a language's flag 5 | * @param lang The locale, ISO code or name of the language to find the colors of 6 | * @returns An array with all the RGB colors in the language's flag, or `null` if it is not found 7 | */ 8 | export function getRGBFlagColors(lang: string) { 9 | const language = findLanguage(lang); 10 | return language?.flag.flagColors.map(c => c.rgb) ?? null; 11 | } 12 | -------------------------------------------------------------------------------- /src/functions/flag/primaryColor/getPrimaryColor.ts: -------------------------------------------------------------------------------- 1 | import findLanguage from "../../findLanguage"; 2 | 3 | /** 4 | * Gets the primary color of a language 5 | * @param lang The locale, ISO code or name of the language to find the color of 6 | * @returns An object with the HEX, RGB, CMYK and base-10 color values of the language, or `null` if it is not found 7 | */ 8 | export function getPrimaryColor(lang: string) { 9 | const language = findLanguage(lang); 10 | return language?.flag.primaryColor ?? null; 11 | } 12 | -------------------------------------------------------------------------------- /src/functions/flag/flagColors/getCMYKFlagColors.ts: -------------------------------------------------------------------------------- 1 | import findLanguage from "../../findLanguage"; 2 | 3 | /** 4 | * Gets the CMYK colors in a language's flag 5 | * @param lang The locale, ISO code or name of the language to find the colors of 6 | * @returns An array with all the CMYK colors in the language's flag, or `null` if it is not found 7 | */ 8 | export function getCMYKFlagColors(lang: string) { 9 | const language = findLanguage(lang); 10 | return language?.flag.flagColors.map(c => c.cmyk) ?? null; 11 | } 12 | -------------------------------------------------------------------------------- /src/functions/getRegionCode.ts: -------------------------------------------------------------------------------- 1 | import findLanguage from "./findLanguage"; 2 | 3 | /** 4 | * Gets the code of a language's region, if any 5 | * @param lang The locale, ISO code or name of the language to find the region code of 6 | * @returns The language's region code, `null` if no language is found 7 | * or `undefined` if the language doesn't have a region 8 | */ 9 | export function getRegionCode(lang: string) { 10 | const language = findLanguage(lang); 11 | return language ? language.regionCode : null; 12 | } 13 | -------------------------------------------------------------------------------- /src/functions/flag/flagColors/getBase10FlagColors.ts: -------------------------------------------------------------------------------- 1 | import findLanguage from "../../findLanguage"; 2 | 3 | /** 4 | * Gets the base-10 colors in a language's flag 5 | * @param lang The locale, ISO code or name of the language to find the colors of 6 | * @returns An array with all the base-10 colors in the language's flag, or `null` if it is not found 7 | */ 8 | export function getBase10FlagColors(lang: string) { 9 | const language = findLanguage(lang); 10 | return language?.flag.flagColors.map(c => c.base10) ?? null; 11 | } 12 | -------------------------------------------------------------------------------- /src/functions/ids/getISO_639_1.ts: -------------------------------------------------------------------------------- 1 | import findLanguage from "../findLanguage"; 2 | 3 | /** 4 | * Gets the [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) code of a language 5 | * @param lang The locale, ISO code or name of the language to find the ISO 639-1 of 6 | * @returns The ISO 639-1 code of the language, `null` if it is not found or `undefined` if the language doesn't have the code 7 | */ 8 | export function getISO_639_1(lang: string) { 9 | const language = findLanguage(lang); 10 | return language ? language.ids.ISO_639_1 : null; 11 | } 12 | -------------------------------------------------------------------------------- /src/functions/ids/getISO_639_2.ts: -------------------------------------------------------------------------------- 1 | import findLanguage from "../findLanguage"; 2 | 3 | /** 4 | * Gets the [ISO 639-2](https://en.wikipedia.org/wiki/ISO_639-2) code of a language 5 | * @param lang The locale, ISO code or name of the language to find the ISO 639-2 of 6 | * @returns The ISO 639-2 code of the language, `null` if it is not found or `undefined` if the language doesn't have the code 7 | */ 8 | export function getISO_639_2(lang: string) { 9 | const language = findLanguage(lang); 10 | return language ? language.ids.ISO_639_2 : null; 11 | } 12 | -------------------------------------------------------------------------------- /src/functions/ids/getISO_639_3.ts: -------------------------------------------------------------------------------- 1 | import findLanguage from "../findLanguage"; 2 | 3 | /** 4 | * Gets the [ISO 639-3](https://en.wikipedia.org/wiki/ISO_639-3) code of a language 5 | * @param lang The locale, ISO code or name of the language to find the ISO 639-3 of 6 | * @returns The ISO 639-3 code of the language, `null` if it is not found or `undefined` if the language doesn't have the code 7 | */ 8 | export function getISO_639_3(lang: string) { 9 | const language = findLanguage(lang); 10 | return language ? language.ids.ISO_639_3 : null; 11 | } 12 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Test package 2 | on: [push, pull_request] 3 | jobs: 4 | test: 5 | runs-on: ubuntu-latest 6 | permissions: 7 | contents: read 8 | packages: write 9 | steps: 10 | - name: Checkout repository 11 | uses: actions/checkout@v2 12 | 13 | - name: Install Node v16 14 | uses: actions/setup-node@v2 15 | with: 16 | node-version: 16 17 | cache: yarn 18 | 19 | - name: Install dependencies 20 | run: yarn install 21 | 22 | - name: Test package 23 | run: yarn build:ci 24 | -------------------------------------------------------------------------------- /src/functions/getRegionLanguages.ts: -------------------------------------------------------------------------------- 1 | import languages from "../languages"; 2 | 3 | /** 4 | * Gets an array with all the languages belonging to a given region 5 | * @param region The region name or code to find 6 | * @returns An array with all the languages belonging to that region or null if none are found 7 | */ 8 | export function getRegionLanguages(region: string) { 9 | const regionLangs = languages.filter(l => l.region?.toLowerCase() === region.toLowerCase() || l.regionCode?.toLowerCase() === region.toLowerCase()); 10 | return regionLangs.length ? regionLangs : null; 11 | } 12 | -------------------------------------------------------------------------------- /src/functions/getCountryLanguages.ts: -------------------------------------------------------------------------------- 1 | import languages from "../languages"; 2 | 3 | /** 4 | * Gets an array with all the languages belonging to a given country 5 | * @param country The country name or code to find 6 | * @returns An array with all the languages belonging to that country or null if none are found 7 | */ 8 | export function getCountryLanguages(country: string) { 9 | const countryLangs = languages.filter( 10 | l => l.country.toLowerCase() === country.toLowerCase() || l.countryCode.toLowerCase() === country.toLowerCase() 11 | ); 12 | return countryLangs.length ? countryLangs : null; 13 | } 14 | -------------------------------------------------------------------------------- /src/tests/getName.test.ts: -------------------------------------------------------------------------------- 1 | import { getName } from ".."; 2 | 3 | describe("getName()", () => { 4 | test("Getting the name of a language given its locale", () => { 5 | expect(getName("nl-nl")).toStrictEqual("Dutch"); 6 | }); 7 | 8 | test("Getting the name of a language given its ISO codes", () => { 9 | expect(getName("pt")).toStrictEqual("Portuguese"); 10 | expect(getName("nld")).toStrictEqual("Dutch"); 11 | expect(getName("afb")).toStrictEqual("Arabic, Bahrain"); 12 | }); 13 | 14 | test("Getting the name of a language given its name", () => { 15 | expect(getName("english")).toStrictEqual("English"); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /src/tests/ids/getLocale.test.ts: -------------------------------------------------------------------------------- 1 | import { getLocale } from "../.."; 2 | 3 | describe("getLocale()", () => { 4 | test("Getting the locale of a language given its locale", () => { 5 | expect(getLocale("nl-nl")).toStrictEqual("nl-NL"); 6 | }); 7 | 8 | test("Getting the locale of a language given its ISO codes", () => { 9 | expect(getLocale("pt")).toStrictEqual("pt-PT"); 10 | expect(getLocale("nld")).toStrictEqual("nl-NL"); 11 | expect(getLocale("afb")).toStrictEqual("ar-BH"); 12 | }); 13 | 14 | test("Getting the locale of a language given its name", () => { 15 | expect(getLocale("english")).toStrictEqual("en"); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /src/functions/flag/getFlag.ts: -------------------------------------------------------------------------------- 1 | import languages from "../.."; 2 | import findLanguage from "../findLanguage"; 3 | 4 | /** 5 | * Gets the flag of a language 6 | * @param country The country, country code, language locale, ISO code or name to find the flag of 7 | * @returns The flag object of the language, or `null` if it is not found 8 | */ 9 | export function getFlag(country: string) { 10 | const language = 11 | languages.find(l => l.country.toLowerCase() === country.toLowerCase()) ?? 12 | languages.find(l => l.countryCode.toLowerCase() === country.toLowerCase()) ?? 13 | findLanguage(country); 14 | return language?.flag ?? null; 15 | } 16 | -------------------------------------------------------------------------------- /src/tests/getRegion.test.ts: -------------------------------------------------------------------------------- 1 | import { getRegion } from ".."; 2 | 3 | describe("getRegion()", () => { 4 | test("Getting the region of a language given its locale", () => { 5 | expect(getRegion("sco-GB")).toStrictEqual("Scotland"); 6 | }); 7 | 8 | test("Getting the region of a language given its ISO codes", () => { 9 | expect(getRegion("gd")).toStrictEqual("Scotland"); 10 | expect(getRegion("sco")).toStrictEqual("Scotland"); 11 | expect(getRegion("ckb")).toStrictEqual("Kurdistan"); 12 | }); 13 | 14 | test("Getting the region of a language given its name", () => { 15 | expect(getRegion("scottish")).toStrictEqual("Scotland"); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /src/tests/getDirection.test.ts: -------------------------------------------------------------------------------- 1 | import { getDirection } from ".."; 2 | 3 | describe("getDirection()", () => { 4 | test("Getting the direction of a language given its locale", () => { 5 | expect(getDirection("nl-nl")).toStrictEqual("ltr"); 6 | }); 7 | 8 | test("Getting the direction of a language given its ISO codes", () => { 9 | expect(getDirection("pt")).toStrictEqual("ltr"); 10 | expect(getDirection("nld")).toStrictEqual("ltr"); 11 | expect(getDirection("afb")).toStrictEqual("rtl"); 12 | }); 13 | 14 | test("Getting the direction of a language given its name", () => { 15 | expect(getDirection("english")).toStrictEqual("ltr"); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /src/tests/getRegionCode.test.ts: -------------------------------------------------------------------------------- 1 | import { getRegionCode } from ".."; 2 | 3 | describe("getRegion()", () => { 4 | test("Getting the region code of a language given its locale", () => { 5 | expect(getRegionCode("sco-GB")).toStrictEqual("sct"); 6 | }); 7 | 8 | test("Getting the region code of a language given its ISO codes", () => { 9 | expect(getRegionCode("gd")).toStrictEqual("sct"); 10 | expect(getRegionCode("sco")).toStrictEqual("sct"); 11 | expect(getRegionCode("ckb")).toStrictEqual("ku"); 12 | }); 13 | 14 | test("Getting the region code of a language given its name", () => { 15 | expect(getRegionCode("scottish")).toStrictEqual("sct"); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /src/tests/ids/getOSXLocale.test.ts: -------------------------------------------------------------------------------- 1 | import { getOSXLocale } from "../.."; 2 | 3 | describe("getOSXLocale()", () => { 4 | test("Getting the OS X locale of a language given its locale", () => { 5 | expect(getOSXLocale("nl-nl")).toStrictEqual("nl"); 6 | }); 7 | 8 | test("Getting the OS X locale of a language given its ISO codes", () => { 9 | expect(getOSXLocale("pt")).toStrictEqual("pt"); 10 | expect(getOSXLocale("nld")).toStrictEqual("nl"); 11 | expect(getOSXLocale("afb")).toStrictEqual("ar_BH"); 12 | }); 13 | 14 | test("Getting the OS X locale of a language given its name", () => { 15 | expect(getOSXLocale("english")).toStrictEqual("en"); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /src/functions/flag/getImage.ts: -------------------------------------------------------------------------------- 1 | import languages from "../../languages"; 2 | import findLanguage from "../findLanguage"; 3 | 4 | /** 5 | * Gets a country's flag image URL 6 | * @param country The country, country code, language locale, ISO code or name to get the flag image URL of 7 | * @returns The flag image URL of the language, or `null` if it is not found 8 | */ 9 | export function getImage(country: string) { 10 | const language = 11 | languages.find(l => l.country.toLowerCase() === country.toLowerCase()) ?? 12 | languages.find(l => l.countryCode.toLowerCase() === country.toLowerCase()) ?? 13 | findLanguage(country); 14 | return language?.flag.image ?? null; 15 | } 16 | -------------------------------------------------------------------------------- /src/tests/getCountry.test.ts: -------------------------------------------------------------------------------- 1 | import { getCountry } from ".."; 2 | 3 | describe("getCountry()", () => { 4 | test("Getting the country of a language given its locale", () => { 5 | expect(getCountry("nl-nl")).toStrictEqual("Netherlands"); 6 | }); 7 | 8 | test("Getting the country of a language given its ISO codes", () => { 9 | expect(getCountry("pt")).toStrictEqual("Portugal"); 10 | expect(getCountry("nld")).toStrictEqual("Netherlands"); 11 | expect(getCountry("afb")).toStrictEqual("Bahrain"); 12 | }); 13 | 14 | test("Getting the country of a language given its name", () => { 15 | expect(getCountry("english")).toStrictEqual("United States"); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /src/tests/ids/getISO_639_1.test.ts: -------------------------------------------------------------------------------- 1 | import { getISO_639_1 } from "../.."; 2 | 3 | describe("getISO_639_1()", () => { 4 | test("Getting the ISO 639-1 code of a language given its locale", () => { 5 | expect(getISO_639_1("nl-nl")).toStrictEqual("nl"); 6 | }); 7 | 8 | test("Getting the ISO 639-1 code of a language given its ISO codes", () => { 9 | expect(getISO_639_1("pt")).toStrictEqual("pt"); 10 | expect(getISO_639_1("nld")).toStrictEqual("nl"); 11 | expect(getISO_639_1("afb")).toStrictEqual("ar"); 12 | }); 13 | 14 | test("Getting the ISO 639-1 code of a language given its name", () => { 15 | expect(getISO_639_1("english")).toStrictEqual("en"); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /src/tests/getCountryCode.test.ts: -------------------------------------------------------------------------------- 1 | import { getCountryCode } from ".."; 2 | 3 | describe("getCountryCode()", () => { 4 | test("Getting the country code of a language given its locale", () => { 5 | expect(getCountryCode("nl-nl")).toStrictEqual("nl"); 6 | }); 7 | 8 | test("Getting the country code of a language given its ISO codes", () => { 9 | expect(getCountryCode("pt")).toStrictEqual("pt"); 10 | expect(getCountryCode("nld")).toStrictEqual("nl"); 11 | expect(getCountryCode("afb")).toStrictEqual("bh"); 12 | }); 13 | 14 | test("Getting the country code of a language given its name", () => { 15 | expect(getCountryCode("english")).toStrictEqual("us"); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /src/tests/ids/getISO_639_2.test.ts: -------------------------------------------------------------------------------- 1 | import { getISO_639_2 } from "../.."; 2 | 3 | describe("getISO_639_2()", () => { 4 | test("Getting the ISO 639-2 code of a language given its locale", () => { 5 | expect(getISO_639_2("nl-nl")).toStrictEqual("nld"); 6 | }); 7 | 8 | test("Getting the ISO 639-2 code of a language given its ISO codes", () => { 9 | expect(getISO_639_2("pt")).toStrictEqual("por"); 10 | expect(getISO_639_2("nld")).toStrictEqual("nld"); 11 | expect(getISO_639_2("afb")).toStrictEqual("ara"); 12 | }); 13 | 14 | test("Getting the ISO 639-2 code of a language given its name", () => { 15 | expect(getISO_639_2("english")).toStrictEqual("eng"); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /src/tests/ids/getISO_639_3.test.ts: -------------------------------------------------------------------------------- 1 | import { getISO_639_3 } from "../.."; 2 | 3 | describe("getISO_639_3()", () => { 4 | test("Getting the ISO 639-3 code of a language given its locale", () => { 5 | expect(getISO_639_3("nl-nl")).toStrictEqual("nld"); 6 | }); 7 | 8 | test("Getting the ISO 639-3 code of a language given its ISO codes", () => { 9 | expect(getISO_639_3("pt")).toStrictEqual("por"); 10 | expect(getISO_639_3("nld")).toStrictEqual("nld"); 11 | expect(getISO_639_3("afb")).toStrictEqual("afb"); 12 | }); 13 | 14 | test("Getting the ISO 639-3 code of a language given its name", () => { 15 | expect(getISO_639_3("english")).toStrictEqual("eng"); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /src/tests/ids/getOSXCode.test.ts: -------------------------------------------------------------------------------- 1 | import { getOSXCode } from "../.."; 2 | 3 | describe("getOSXCode()", () => { 4 | test("Getting the OS X code of a language given its locale", () => { 5 | expect(getOSXCode("nl-nl")).toStrictEqual("nl.lproj"); 6 | }); 7 | 8 | test("Getting the OS X code of a language given its ISO codes", () => { 9 | expect(getOSXCode("pt")).toStrictEqual("pt.lproj"); 10 | expect(getOSXCode("nld")).toStrictEqual("nl.lproj"); 11 | expect(getOSXCode("afb")).toStrictEqual("ar-BH.lproj"); 12 | }); 13 | 14 | test("Getting the OS X code of a language given its name", () => { 15 | expect(getOSXCode("english")).toStrictEqual("en.lproj"); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /src/tests/ids/getAndroidCode.test.ts: -------------------------------------------------------------------------------- 1 | import { getAndroidCode } from "../.."; 2 | 3 | describe("getAndroidCode()", () => { 4 | test("Getting the Android code of a language given its locale", () => { 5 | expect(getAndroidCode("nl-nl")).toStrictEqual("nl-rNL"); 6 | }); 7 | 8 | test("Getting the Android code of a language given its ISO codes", () => { 9 | expect(getAndroidCode("pt")).toStrictEqual("pt-rPT"); 10 | expect(getAndroidCode("nld")).toStrictEqual("nl-rNL"); 11 | expect(getAndroidCode("afb")).toStrictEqual("ar-rBH"); 12 | }); 13 | 14 | test("Getting the Android code of a language given its name", () => { 15 | expect(getAndroidCode("english")).toStrictEqual("en-rUS"); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /src/tests/getNativeName.test.ts: -------------------------------------------------------------------------------- 1 | import { getNativeName } from ".."; 2 | 3 | describe("getNativeName()", () => { 4 | test("Getting the native name of a language given its locale", () => { 5 | expect(getNativeName("nl-nl")).toStrictEqual("Nederlands"); 6 | }); 7 | 8 | test("Getting the native name of a language given its ISO codes", () => { 9 | expect(getNativeName("pt")).toStrictEqual("Português"); 10 | expect(getNativeName("nld")).toStrictEqual("Nederlands"); 11 | expect(getNativeName("afb")).toStrictEqual("اللهجة البحرينية"); 12 | }); 13 | 14 | test("Getting the native name of a language given its name", () => { 15 | expect(getNativeName("english")).toStrictEqual("English"); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /src/tests/flag/primaryColor/getPrimaryHex.test.ts: -------------------------------------------------------------------------------- 1 | import { getPrimaryHex } from "../../.."; 2 | 3 | describe("getPrimaryHex()", () => { 4 | test("Getting the primary Hex color of a language given its locale", () => { 5 | expect(getPrimaryHex("nl-nl")).toStrictEqual("#FF4F00"); 6 | }); 7 | 8 | test("Getting the primary Hex color of a language given its ISO codes", () => { 9 | expect(getPrimaryHex("pt")).toStrictEqual("#FF0000"); 10 | expect(getPrimaryHex("nld")).toStrictEqual("#FF4F00"); 11 | expect(getPrimaryHex("afb")).toStrictEqual("#F21731"); 12 | }); 13 | 14 | test("Getting the primary Hex color of a language given its name", () => { 15 | expect(getPrimaryHex("english")).toStrictEqual("#0A3161"); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /src/tests/flag/primaryColor/getPrimaryRGB.test.ts: -------------------------------------------------------------------------------- 1 | import { getPrimaryRGB } from "../../.."; 2 | 3 | describe("getPrimaryRGB()", () => { 4 | test("Getting the primary RGB color of a language given its locale", () => { 5 | expect(getPrimaryRGB("nl-nl")).toStrictEqual([255, 79, 0]); 6 | }); 7 | 8 | test("Getting the primary RGB color of a language given its ISO codes", () => { 9 | expect(getPrimaryRGB("pt")).toStrictEqual([255, 0, 0]); 10 | expect(getPrimaryRGB("nld")).toStrictEqual([255, 79, 0]); 11 | expect(getPrimaryRGB("afb")).toStrictEqual([242, 23, 49]); 12 | }); 13 | 14 | test("Getting the primary RGB color of a language given its name", () => { 15 | expect(getPrimaryRGB("english")).toStrictEqual([10, 49, 97]); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /src/tests/flag/primaryColor/getPrimaryBase10.test.ts: -------------------------------------------------------------------------------- 1 | import { getPrimaryBase10 } from "../../.."; 2 | 3 | describe("getPrimaryBase10()", () => { 4 | test("Getting the primary base-10 color of a language given its locale", () => { 5 | expect(getPrimaryBase10("nl-nl")).toStrictEqual(16731904); 6 | }); 7 | 8 | test("Getting the primary base-10 color of a language given its ISO codes", () => { 9 | expect(getPrimaryBase10("pt")).toStrictEqual(16711680); 10 | expect(getPrimaryBase10("nld")).toStrictEqual(16731904); 11 | expect(getPrimaryBase10("afb")).toStrictEqual(15865649); 12 | }); 13 | 14 | test("Getting the primary base-10 color of a language given its name", () => { 15 | expect(getPrimaryBase10("english")).toStrictEqual(668001); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /src/tests/flag/primaryColor/getPrimaryCMYK.test.ts: -------------------------------------------------------------------------------- 1 | import { getPrimaryCMYK } from "../../.."; 2 | 3 | describe("getPrimaryCMYK()", () => { 4 | test("Getting the primary CMYK color of a language given its locale", () => { 5 | expect(getPrimaryCMYK("nl-nl")).toStrictEqual([0, 69, 100, 0]); 6 | }); 7 | 8 | test("Getting the primary CMYK color of a language given its ISO codes", () => { 9 | expect(getPrimaryCMYK("pt")).toStrictEqual([0, 100, 100, 0]); 10 | expect(getPrimaryCMYK("nld")).toStrictEqual([0, 69, 100, 0]); 11 | expect(getPrimaryCMYK("afb")).toStrictEqual([0, 91, 80, 5]); 12 | }); 13 | 14 | test("Getting the primary CMYK color of a language given its name", () => { 15 | expect(getPrimaryCMYK("english")).toStrictEqual([90, 49, 0, 62]); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /src/functions/getLanguage.ts: -------------------------------------------------------------------------------- 1 | import findLanguage from "./findLanguage"; 2 | 3 | import type { Language } from ".."; 4 | 5 | /** 6 | * Gets a full language object matching the given input, or an array of languages if input is an array 7 | * @param lang The locale(s), ISO code(s) or name(s) of the language(s) to find 8 | * @returns An array of language objects or `null` if input is an array, otherwise a language object or `null` 9 | */ 10 | export function getLanguage(lang: string): Language | null; 11 | export function getLanguage(langs: T): { [P in keyof T]: Language | null }; 12 | export function getLanguage(lang: string | string[]) { 13 | if (Array.isArray(lang)) { 14 | return lang.map(l => findLanguage(l) ?? null); 15 | } else return findLanguage(lang) ?? null; 16 | } 17 | -------------------------------------------------------------------------------- /.github/workflows/publish-package.yml: -------------------------------------------------------------------------------- 1 | name: Publish Package 2 | on: 3 | release: 4 | types: [created] 5 | jobs: 6 | publish: 7 | runs-on: ubuntu-latest 8 | permissions: 9 | contents: read 10 | packages: write 11 | steps: 12 | - name: Checkout repository 13 | uses: actions/checkout@v2 14 | 15 | - name: Install Node v16 16 | uses: actions/setup-node@v2 17 | with: 18 | node-version: 16 19 | registry-url: "https://registry.npmjs.org" 20 | cache: yarn 21 | 22 | - name: Install dependencies 23 | run: yarn install 24 | 25 | - name: Compile and test 26 | run: yarn build:prod 27 | 28 | - name: Publish package 29 | run: npm publish 30 | env: 31 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 32 | -------------------------------------------------------------------------------- /src/tests/flag/flagColors/getBase10FlagColors.test.ts: -------------------------------------------------------------------------------- 1 | import { getBase10FlagColors } from "../../.."; 2 | 3 | describe("getBase10FlagColors()", () => { 4 | test("Getting the base-10 flag colors of a language given its locale", () => { 5 | expect(getBase10FlagColors("nl-nl")).toStrictEqual([13111342, 16777215, 15781]); 6 | }); 7 | 8 | test("Getting the base-10 flag colors of a language given its ISO codes", () => { 9 | expect(getBase10FlagColors("pt")).toStrictEqual([289336, 14297372, 16771328, 11634, 16777215, 0]); 10 | expect(getBase10FlagColors("nld")).toStrictEqual([13111342, 16777215, 15781]); 11 | expect(getBase10FlagColors("afb")).toStrictEqual([13504806, 16777215]); 12 | }); 13 | 14 | test("Getting the base-10 flag colors of a language given its name", () => { 15 | expect(getBase10FlagColors("english")).toStrictEqual([11737410, 16777215, 668001]); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /src/tests/flag/flagColors/getHexFlagColors.test.ts: -------------------------------------------------------------------------------- 1 | import { getHexFlagColors } from "../../.."; 2 | 3 | describe("getHexFlagColors()", () => { 4 | test("Getting the Hex flag colors of a language given its locale", () => { 5 | expect(getHexFlagColors("nl-nl")).toStrictEqual(["#C8102E", "#FFFFFF", "#003DA5"]); 6 | }); 7 | 8 | test("Getting the Hex flag colors of a language given its ISO codes", () => { 9 | expect(getHexFlagColors("pt")).toStrictEqual(["#046A38", "#DA291C", "#FFE900", "#002D72", "#FFFFFF", "#000000"]); 10 | expect(getHexFlagColors("nld")).toStrictEqual(["#C8102E", "#FFFFFF", "#003DA5"]); 11 | expect(getHexFlagColors("afb")).toStrictEqual(["#CE1126", "#FFFFFF"]); 12 | }); 13 | 14 | test("Getting the Hex flag colors of a language given its name", () => { 15 | expect(getHexFlagColors("english")).toStrictEqual(["#B31942", "#FFFFFF", "#0A3161"]); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /src/functions/flag/getEmoji.ts: -------------------------------------------------------------------------------- 1 | import languages from "../../languages"; 2 | import findLanguage from "../findLanguage"; 3 | 4 | /** 5 | * Gets a country's flag unicode emoji 6 | * @param country The country, country code, language locale, ISO code or name to get the flag emoji of 7 | * @returns A flag unicode emoji, `null` if no language is found or `undefined` if the language doesn't have an emoji 8 | */ 9 | export function getEmoji(country: string) { 10 | const language = 11 | languages.find(l => l.country.toLowerCase() === country.toLowerCase() && l.flag.emoji) ?? 12 | languages.find(l => l.countryCode.toLowerCase() === country.toLowerCase() && l.flag.emoji) ?? 13 | languages.find(l => l.country.toLowerCase() === country.toLowerCase()) ?? 14 | languages.find(l => l.countryCode.toLowerCase() === country.toLowerCase()) ?? 15 | findLanguage(country); 16 | return language ? language.flag.emoji : null; 17 | } 18 | -------------------------------------------------------------------------------- /src/tests/flag/getEmoji.test.ts: -------------------------------------------------------------------------------- 1 | import { getEmoji } from "../.."; 2 | 3 | describe("getEmoji()", () => { 4 | test("Getting the emoji of a language given its country", () => { 5 | expect(getEmoji("netherlands")).toStrictEqual("🇳🇱"); 6 | }); 7 | 8 | test("Getting the emoji of a language given its country code", () => { 9 | expect(getEmoji("nl")).toStrictEqual("🇳🇱"); 10 | }); 11 | 12 | test("Getting the emoji of a language given its locale", () => { 13 | expect(getEmoji("nl-nl")).toStrictEqual("🇳🇱"); 14 | }); 15 | 16 | test("Getting the emoji of a language given its ISO codes", () => { 17 | expect(getEmoji("pt")).toStrictEqual("🇵🇹"); 18 | expect(getEmoji("nld")).toStrictEqual("🇳🇱"); 19 | expect(getEmoji("afb")).toStrictEqual("🇧🇭"); 20 | }); 21 | 22 | test("Getting the emoji of a language given its name", () => { 23 | expect(getEmoji("english")).toStrictEqual("🇺🇸"); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/functions/ids/getGlottolog.ts: -------------------------------------------------------------------------------- 1 | import findLanguage from "../findLanguage"; 2 | 3 | /** 4 | * Gets the [Glottolog](https://en.wikipedia.org/wiki/Glottolog) code of a language 5 | * @param lang The locale, ISO code or name of the language to find the Glottolog code of 6 | * @param url Whether or not to return the Glottolog URL with the code 7 | * @returns The Glottolog code of the language, or `null` if it is not found 8 | */ 9 | export function getGlottolog(lang: string): string | null | undefined; 10 | export function getGlottolog(lang: string, url: true): `https://glottolog.org/resource/languoid/id/${string}` | null | undefined; 11 | export function getGlottolog(lang: string, url = false) { 12 | const language = findLanguage(lang); 13 | return language 14 | ? url && language.ids.glottolog 15 | ? `https://glottolog.org/resource/languoid/id/${language.ids.glottolog}` 16 | : language.ids.glottolog 17 | : null; 18 | } 19 | -------------------------------------------------------------------------------- /src/tests/flag/primaryColor/getPrimaryColor.test.ts: -------------------------------------------------------------------------------- 1 | import { getPrimaryColor } from "../../.."; 2 | 3 | describe("getPrimaryColor()", () => { 4 | test("Getting the primary color of a language given its locale", () => { 5 | expect(getPrimaryColor("nl-nl")).toStrictEqual({ hex: "#FF4F00", rgb: [255, 79, 0], cmyk: [0, 69, 100, 0], base10: 16731904 }); 6 | }); 7 | 8 | test("Getting the primary color of a language given its ISO codes", () => { 9 | expect(getPrimaryColor("pt")).toStrictEqual({ hex: "#FF0000", rgb: [255, 0, 0], cmyk: [0, 100, 100, 0], base10: 16711680 }); 10 | expect(getPrimaryColor("nld")).toStrictEqual({ hex: "#FF4F00", rgb: [255, 79, 0], cmyk: [0, 69, 100, 0], base10: 16731904 }); 11 | expect(getPrimaryColor("afb")).toStrictEqual({ hex: "#F21731", rgb: [242, 23, 49], cmyk: [0, 91, 80, 5], base10: 15865649 }); 12 | }); 13 | 14 | test("Getting the primary color of a language given its name", () => { 15 | expect(getPrimaryColor("english")).toStrictEqual({ hex: "#0A3161", rgb: [10, 49, 97], cmyk: [90, 49, 0, 62], base10: 668001 }); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Bas950 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/functions/findLanguage.ts: -------------------------------------------------------------------------------- 1 | import languages from "../languages"; 2 | 3 | /** 4 | * Finds a language given its locale, ISO code or name 5 | * @param lang The language to find 6 | * @returns The corresponding language, or undefined if none is found 7 | * @private 8 | */ 9 | export default function findLanguage(lang: string) { 10 | return ( 11 | languages.find(l => l.ids.locale.toLowerCase() === lang.toLowerCase()) ?? 12 | languages.find(l => l.ids.ISO_639_1 === lang.toLowerCase()) ?? 13 | languages.find(l => l.ids.ISO_639_2 === lang.toLowerCase()) ?? 14 | languages.find(l => l.ids.ISO_639_3 === lang.toLowerCase()) ?? 15 | languages.find(l => l.ids.osxLocale.toLowerCase() === lang.toLowerCase()) ?? 16 | languages.find(l => l.ids.osxCode.toLowerCase() === lang.toLowerCase()) ?? 17 | languages.find(l => l.ids.androidCode.toLowerCase() === lang.toLowerCase()) ?? 18 | languages.find(l => l.ids.locale.toLowerCase().includes(lang.toLowerCase())) ?? 19 | languages.find(l => l.name.toLowerCase() === lang.toLowerCase()) ?? 20 | languages.find(l => l.name.toLowerCase().includes(lang.toLowerCase())) 21 | ); 22 | } 23 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "language-flag-colors", 3 | "version": "2.1.2", 4 | "repository": "https://github.com/Bas950/Language-Flag-Colors.git", 5 | "author": "Bas950 ", 6 | "license": "MIT", 7 | "files": [ 8 | "bin" 9 | ], 10 | "main": "bin/index.js", 11 | "module": "bin/index.mjs", 12 | "types": "bin/index.d.ts", 13 | "scripts": { 14 | "test": "jest", 15 | "clean": "rimraf bin", 16 | "clean:tests": "rimraf bin/tests", 17 | "build:ci": "tsc --noEmit", 18 | "build:cjs": "tsc", 19 | "build:esm": "gen-esm-wrapper bin/index.js bin/index.mjs", 20 | "build": "yarn clean && yarn build:cjs && yarn build:esm && yarn test", 21 | "build:prod": "yarn build && yarn clean:tests", 22 | "changelog": "git cliff --output CHANGELOG.md" 23 | }, 24 | "keywords": [ 25 | "language", 26 | "flag", 27 | "colors", 28 | "crowdin", 29 | "locale", 30 | "iso", 31 | "emoji", 32 | "unicode", 33 | "glottolog" 34 | ], 35 | "devDependencies": { 36 | "@types/jest": "^29.5.1", 37 | "gen-esm-wrapper": "^1.1.3", 38 | "jest": "^29.5.0", 39 | "rimraf": "^5.0.0", 40 | "ts-jest": "^29.1.0", 41 | "typescript": "^5.0.4" 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/tests/flag/flagColors/getRGBFlagColors.test.ts: -------------------------------------------------------------------------------- 1 | import { getRGBFlagColors } from "../../.."; 2 | 3 | describe("getRGBFlagColors()", () => { 4 | test("Getting the RGB flag colors of a language given its locale", () => { 5 | expect(getRGBFlagColors("nl-nl")).toStrictEqual([ 6 | [200, 16, 46], 7 | [255, 255, 255], 8 | [0, 61, 165] 9 | ]); 10 | }); 11 | 12 | test("Getting the RGB flag colors of a language given its ISO codes", () => { 13 | expect(getRGBFlagColors("pt")).toStrictEqual([ 14 | [4, 106, 56], 15 | [218, 41, 28], 16 | [255, 233, 0], 17 | [0, 45, 114], 18 | [255, 255, 255], 19 | [0, 0, 0] 20 | ]); 21 | expect(getRGBFlagColors("nld")).toStrictEqual([ 22 | [200, 16, 46], 23 | [255, 255, 255], 24 | [0, 61, 165] 25 | ]); 26 | expect(getRGBFlagColors("afb")).toStrictEqual([ 27 | [206, 17, 38], 28 | [255, 255, 255] 29 | ]); 30 | }); 31 | 32 | test("Getting the RGB flag colors of a language given its name", () => { 33 | expect(getRGBFlagColors("english")).toStrictEqual([ 34 | [179, 25, 66], 35 | [255, 255, 255], 36 | [10, 49, 97] 37 | ]); 38 | }); 39 | }); 40 | -------------------------------------------------------------------------------- /src/tests/flag/getImage.test.ts: -------------------------------------------------------------------------------- 1 | import { getImage } from "../.."; 2 | 3 | describe("getImage()", () => { 4 | test("Getting the image of a language given its country", () => { 5 | expect(getImage("netherlands")).toStrictEqual("https://crowdin.com/images/flags/nl.png"); 6 | }); 7 | 8 | test("Getting the image of a language given its country code", () => { 9 | expect(getImage("nl")).toStrictEqual("https://crowdin.com/images/flags/nl.png"); 10 | }); 11 | 12 | test("Getting the image of a language given its locale", () => { 13 | expect(getImage("nl-nl")).toStrictEqual("https://crowdin.com/images/flags/nl.png"); 14 | }); 15 | 16 | test("Getting the image of a language given its ISO codes", () => { 17 | expect(getImage("pt")).toStrictEqual("https://crowdin.com/images/flags/pt-PT.png"); 18 | expect(getImage("nld")).toStrictEqual("https://crowdin.com/images/flags/nl.png"); 19 | expect(getImage("afb")).toStrictEqual("https://crowdin.com/images/flags/ar-BH.png"); 20 | }); 21 | 22 | test("Getting the image of a language given its name", () => { 23 | expect(getImage("english")).toStrictEqual("https://crowdin.com/images/flags/en.png"); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /src/tests/flag/flagColors/getCMYKFlagColors.test.ts: -------------------------------------------------------------------------------- 1 | import { getCMYKFlagColors } from "../../.."; 2 | 3 | describe("getCMYKFlagColors()", () => { 4 | test("Getting the CMYK flag colors of a language given its locale", () => { 5 | expect(getCMYKFlagColors("nl-nl")).toStrictEqual([ 6 | [0, 100, 80, 5], 7 | [0, 0, 0, 0], 8 | [100, 76, 0, 9] 9 | ]); 10 | }); 11 | 12 | test("Getting the CMYK flag colors of a language given its ISO codes", () => { 13 | expect(getCMYKFlagColors("pt")).toStrictEqual([ 14 | [85, 3, 91, 44], 15 | [0, 95, 100, 0], 16 | [0, 3, 97, 0], 17 | [100, 79, 0, 37], 18 | [0, 0, 0, 0], 19 | [0, 0, 0, 100] 20 | ]); 21 | expect(getCMYKFlagColors("nld")).toStrictEqual([ 22 | [0, 100, 80, 5], 23 | [0, 0, 0, 0], 24 | [100, 76, 0, 9] 25 | ]); 26 | expect(getCMYKFlagColors("afb")).toStrictEqual([ 27 | [0, 95, 100, 0], 28 | [0, 0, 0, 0] 29 | ]); 30 | }); 31 | 32 | test("Getting the CMYK flag colors of a language given its name", () => { 33 | expect(getCMYKFlagColors("english")).toStrictEqual([ 34 | [0, 100, 66, 13], 35 | [0, 0, 0, 0], 36 | [100, 68, 0, 54] 37 | ]); 38 | }); 39 | }); 40 | -------------------------------------------------------------------------------- /src/tests/ids/getGlottolog.test.ts: -------------------------------------------------------------------------------- 1 | import { getGlottolog } from "../.."; 2 | 3 | describe("getGlottolog()", () => { 4 | test("Getting the Glottolog code of a language given its locale", () => { 5 | expect(getGlottolog("nl-nl")).toStrictEqual("mode1257"); 6 | }); 7 | 8 | test("Getting the Glottolog code of a language given its ISO codes", () => { 9 | expect(getGlottolog("pt")).toStrictEqual("port1283"); 10 | expect(getGlottolog("nld")).toStrictEqual("mode1257"); 11 | expect(getGlottolog("afb")).toStrictEqual("gulf1241"); 12 | }); 13 | 14 | test("Getting the Glottolog code of a language given its name", () => { 15 | expect(getGlottolog("english")).toStrictEqual("stan1293"); 16 | }); 17 | }); 18 | 19 | describe("getGlottolog(url: true)", () => { 20 | test("Getting the Glottolog URL of a language given its locale", () => { 21 | expect(getGlottolog("nl-nl", true)).toStrictEqual("https://glottolog.org/resource/languoid/id/mode1257"); 22 | }); 23 | 24 | test("Getting the Glottolog URL of a language given its ISO codes", () => { 25 | expect(getGlottolog("pt", true)).toStrictEqual("https://glottolog.org/resource/languoid/id/port1283"); 26 | expect(getGlottolog("nld", true)).toStrictEqual("https://glottolog.org/resource/languoid/id/mode1257"); 27 | expect(getGlottolog("afb", true)).toStrictEqual("https://glottolog.org/resource/languoid/id/gulf1241"); 28 | }); 29 | 30 | test("Getting the Glottolog URL of a language given its name", () => { 31 | expect(getGlottolog("english", true)).toStrictEqual("https://glottolog.org/resource/languoid/id/stan1293"); 32 | }); 33 | }); 34 | -------------------------------------------------------------------------------- /src/tests/ids/getIds.test.ts: -------------------------------------------------------------------------------- 1 | import { getIds } from "../.."; 2 | 3 | describe("getIds()", () => { 4 | test("Getting the ids of a language given its locale", () => { 5 | expect(getIds("nl-nl")).toStrictEqual({ 6 | locale: "nl-NL", 7 | ISO_639_1: "nl", 8 | ISO_639_2: "nld", 9 | ISO_639_3: "nld", 10 | androidCode: "nl-rNL", 11 | osxCode: "nl.lproj", 12 | osxLocale: "nl", 13 | glottolog: "mode1257" 14 | }); 15 | }); 16 | 17 | test("Getting the ids of a language given its ISO codes", () => { 18 | expect(getIds("pt")).toStrictEqual({ 19 | locale: "pt-PT", 20 | ISO_639_1: "pt", 21 | ISO_639_2: "por", 22 | ISO_639_3: "por", 23 | androidCode: "pt-rPT", 24 | osxCode: "pt.lproj", 25 | osxLocale: "pt", 26 | glottolog: "port1283" 27 | }); 28 | expect(getIds("nld")).toStrictEqual({ 29 | locale: "nl-NL", 30 | ISO_639_1: "nl", 31 | ISO_639_2: "nld", 32 | ISO_639_3: "nld", 33 | androidCode: "nl-rNL", 34 | osxCode: "nl.lproj", 35 | osxLocale: "nl", 36 | glottolog: "mode1257" 37 | }); 38 | expect(getIds("afb")).toStrictEqual({ 39 | locale: "ar-BH", 40 | ISO_639_1: "ar", 41 | ISO_639_2: "ara", 42 | ISO_639_3: "afb", 43 | androidCode: "ar-rBH", 44 | osxCode: "ar-BH.lproj", 45 | osxLocale: "ar_BH", 46 | glottolog: "gulf1241" 47 | }); 48 | }); 49 | 50 | test("Getting the ids of a language given its name", () => { 51 | expect(getIds("english")).toStrictEqual({ 52 | locale: "en", 53 | ISO_639_1: "en", 54 | ISO_639_2: "eng", 55 | ISO_639_3: "eng", 56 | androidCode: "en-rUS", 57 | osxCode: "en.lproj", 58 | osxLocale: "en", 59 | glottolog: "stan1293" 60 | }); 61 | }); 62 | }); 63 | -------------------------------------------------------------------------------- /src/tests/flag/flagColors/getFlagColors.test.ts: -------------------------------------------------------------------------------- 1 | import { getFlagColors } from "../../.."; 2 | 3 | describe("getFlagColors()", () => { 4 | test("Getting the flag colors of a language given its locale", () => { 5 | expect(getFlagColors("nl-nl")).toStrictEqual([ 6 | { hex: "#C8102E", rgb: [200, 16, 46], cmyk: [0, 100, 80, 5], base10: 13111342 }, 7 | { hex: "#FFFFFF", rgb: [255, 255, 255], cmyk: [0, 0, 0, 0], base10: 16777215 }, 8 | { hex: "#003DA5", rgb: [0, 61, 165], cmyk: [100, 76, 0, 9], base10: 15781 } 9 | ]); 10 | }); 11 | 12 | test("Getting the flag colors of a language given its ISO codes", () => { 13 | expect(getFlagColors("pt")).toStrictEqual([ 14 | { hex: "#046A38", rgb: [4, 106, 56], cmyk: [85, 3, 91, 44], base10: 289336 }, 15 | { hex: "#DA291C", rgb: [218, 41, 28], cmyk: [0, 95, 100, 0], base10: 14297372 }, 16 | { hex: "#FFE900", rgb: [255, 233, 0], cmyk: [0, 3, 97, 0], base10: 16771328 }, 17 | { hex: "#002D72", rgb: [0, 45, 114], cmyk: [100, 79, 0, 37], base10: 11634 }, 18 | { hex: "#FFFFFF", rgb: [255, 255, 255], cmyk: [0, 0, 0, 0], base10: 16777215 }, 19 | { hex: "#000000", rgb: [0, 0, 0], cmyk: [0, 0, 0, 100], base10: 0 } 20 | ]); 21 | expect(getFlagColors("nld")).toStrictEqual([ 22 | { hex: "#C8102E", rgb: [200, 16, 46], cmyk: [0, 100, 80, 5], base10: 13111342 }, 23 | { hex: "#FFFFFF", rgb: [255, 255, 255], cmyk: [0, 0, 0, 0], base10: 16777215 }, 24 | { hex: "#003DA5", rgb: [0, 61, 165], cmyk: [100, 76, 0, 9], base10: 15781 } 25 | ]); 26 | expect(getFlagColors("afb")).toStrictEqual([ 27 | { hex: "#CE1126", rgb: [206, 17, 38], cmyk: [0, 95, 100, 0], base10: 13504806 }, 28 | { hex: "#FFFFFF", rgb: [255, 255, 255], cmyk: [0, 0, 0, 0], base10: 16777215 } 29 | ]); 30 | }); 31 | 32 | test("Getting the flag colors of a language given its name", () => { 33 | expect(getFlagColors("english")).toStrictEqual([ 34 | { hex: "#B31942", rgb: [179, 25, 66], cmyk: [0, 100, 66, 13], base10: 11737410 }, 35 | { hex: "#FFFFFF", rgb: [255, 255, 255], cmyk: [0, 0, 0, 0], base10: 16777215 }, 36 | { hex: "#0A3161", rgb: [10, 49, 97], cmyk: [100, 68, 0, 54], base10: 668001 } 37 | ]); 38 | }); 39 | }); 40 | -------------------------------------------------------------------------------- /src/tests/getRegionLanguages.test.ts: -------------------------------------------------------------------------------- 1 | import { getRegionLanguages } from ".."; 2 | 3 | describe("getRegionLanguges()", () => { 4 | const langs = [ 5 | { 6 | name: "Scots", 7 | nativeName: "Scoats leid", 8 | ids: { 9 | locale: "sco-GB", 10 | ISO_639_2: "sco", 11 | ISO_639_3: "sco", 12 | androidCode: "sco-rGB", 13 | osxCode: "sco.lproj", 14 | osxLocale: "sco", 15 | glottolog: "scot1243" 16 | }, 17 | direction: "ltr", 18 | country: "United Kingdom", 19 | countryCode: "gb", 20 | flag: { 21 | image: "https://crowdin.com/images/flags/sco.png", 22 | emoji: "🏴󠁧󠁢󠁳󠁣󠁴󠁿", 23 | primaryColor: { hex: "#005EB8", rgb: [0, 94, 184], cmyk: [100, 49, 0, 28], base10: 24248 }, 24 | flagColors: [ 25 | { hex: "#005EB8", rgb: [0, 94, 184], cmyk: [100, 56, 0, 3], base10: 24248 }, 26 | { hex: "#FFFFFF", rgb: [255, 255, 255], cmyk: [0, 0, 0, 0], base10: 16777215 } 27 | ] 28 | }, 29 | region: "Scotland", 30 | regionCode: "sct" 31 | }, 32 | { 33 | name: "Scottish Gaelic", 34 | nativeName: "Gàidhlig", 35 | ids: { 36 | locale: "gd-GB", 37 | ISO_639_1: "gd", 38 | ISO_639_2: "gla", 39 | ISO_639_3: "gla", 40 | androidCode: "gd-rGB", 41 | osxCode: "gd.lproj", 42 | osxLocale: "gd", 43 | glottolog: "scot1245" 44 | }, 45 | direction: "ltr", 46 | country: "United Kingdom", 47 | countryCode: "gb", 48 | flag: { 49 | image: "https://crowdin.com/images/flags/gd.png", 50 | emoji: "🏴󠁧󠁢󠁳󠁣󠁴󠁿", 51 | primaryColor: { hex: "#005EB8", rgb: [0, 94, 184], cmyk: [100, 49, 0, 28], base10: 24248 }, 52 | flagColors: [ 53 | { hex: "#005EB8", rgb: [0, 94, 184], cmyk: [100, 56, 0, 3], base10: 24248 }, 54 | { hex: "#FFFFFF", rgb: [255, 255, 255], cmyk: [0, 0, 0, 0], base10: 16777215 } 55 | ] 56 | }, 57 | region: "Scotland", 58 | regionCode: "sct" 59 | } 60 | ]; 61 | 62 | test("Getting all the languages specific to a region given its name", () => { 63 | expect(getRegionLanguages("scotland")).toStrictEqual(langs); 64 | }); 65 | 66 | test("Getting all the languages specific to a region given its code", () => { 67 | expect(getRegionLanguages("sct")).toStrictEqual(langs); 68 | }); 69 | }); 70 | -------------------------------------------------------------------------------- /cliff.toml: -------------------------------------------------------------------------------- 1 | [changelog] 2 | header = """ 3 | # Changelog 4 | All notable changes to this project will be documented in this file.\n 5 | """ 6 | body = """ 7 | {% if version %}\ 8 | # [{{ version | trim_start_matches(pat="v") }}]\ 9 | {% if previous %}\ 10 | {% if previous.version %}\ 11 | (https://github.com/Bas950/Language-Flag-Colors/compare/{{ previous.version }}...{{ version }})\ 12 | {% else %} 13 | (https://github.com/Bas950/Language-Flag-Colors/tree/{{ version }}\ 14 | {% endif %}\ 15 | {% endif %} \ 16 | - ({{ timestamp | date(format="%d-%m-%Y") }}) 17 | {% else %}\ 18 | # [unreleased] 19 | {% endif %}\ 20 | {% for group, commits in commits | group_by(attribute="group") %} 21 | ## {{ group | upper_first }} 22 | {% for commit in commits %} 23 | - {% if commit.breaking %}\ 24 | [**breaking**] \ 25 | {% endif %}\ 26 | {% if commit.scope %}\ 27 | **{{commit.scope}}:** \ 28 | {% endif %}\ 29 | {{ commit.message | upper_first }} ([{{ commit.id | truncate(length=7, end="") }}](https://github.com/Bas950/Language-Flag-Colors/commit/{{ commit.id }}))\ 30 | {% endfor %} 31 | {% endfor %}\n 32 | """ 33 | trim = true 34 | footer = "" 35 | 36 | [git] 37 | conventional_commits = true 38 | filter_unconventional = true 39 | commit_parsers = [ 40 | { message = "^feat", group = "Features"}, 41 | { message = "^fix", group = "Bug Fixes"}, 42 | { message = "^docs", group = "Documentation"}, 43 | { message = "^perf", group = "Performance"}, 44 | { message = "^refactor", group = "Refactor"}, 45 | { message = "^typings", group = "Types"}, 46 | { message = "^types", group = "Types"}, 47 | { message = ".*deprecated", body = ".*deprecated", group = "Deprecation"}, 48 | { message = "^revert", skip = true}, 49 | { message = "^style", group = "Styling"}, 50 | { message = "^test", group = "Testing"}, 51 | { message = "^chore", skip = true}, 52 | { message = "^ci", skip = true}, 53 | { message = "^build", skip = true}, 54 | { body = ".*security", group = "Security"}, 55 | ] 56 | filter_commits = true 57 | tag_pattern = "[0-9]*" 58 | ignore_tags = "" 59 | topo_order = false 60 | sort_commits = "newest" 61 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./functions/flag/flagColors/getBase10FlagColors"; 2 | export * from "./functions/flag/flagColors/getCMYKFlagColors"; 3 | export * from "./functions/flag/flagColors/getFlagColors"; 4 | export * from "./functions/flag/flagColors/getHexFlagColors"; 5 | export * from "./functions/flag/flagColors/getRGBFlagColors"; 6 | export * from "./functions/flag/getEmoji"; 7 | export * from "./functions/flag/getFlag"; 8 | export * from "./functions/flag/getImage"; 9 | export * from "./functions/flag/primaryColor/getPrimaryBase10"; 10 | export * from "./functions/flag/primaryColor/getPrimaryCMYK"; 11 | export * from "./functions/flag/primaryColor/getPrimaryColor"; 12 | export * from "./functions/flag/primaryColor/getPrimaryHex"; 13 | export * from "./functions/flag/primaryColor/getPrimaryRGB"; 14 | export * from "./functions/getCountry"; 15 | export * from "./functions/getCountryCode"; 16 | export * from "./functions/getCountryLanguages"; 17 | export * from "./functions/getDirection"; 18 | export * from "./functions/getLanguage"; 19 | export * from "./functions/getName"; 20 | export * from "./functions/getNativeName"; 21 | export * from "./functions/getRegion"; 22 | export * from "./functions/getRegionCode"; 23 | export * from "./functions/getRegionLanguages"; 24 | export * from "./functions/ids/getAndroidCode"; 25 | export * from "./functions/ids/getGlottolog"; 26 | export * from "./functions/ids/getIds"; 27 | export * from "./functions/ids/getISO_639_1"; 28 | export * from "./functions/ids/getISO_639_2"; 29 | export * from "./functions/ids/getISO_639_3"; 30 | export * from "./functions/ids/getLocale"; 31 | export * from "./functions/ids/getOSXCode"; 32 | export * from "./functions/ids/getOSXLocale"; 33 | import languages from "./languages"; 34 | 35 | export default languages; 36 | 37 | export interface Language { 38 | name: string; 39 | nativeName: string; 40 | ids: LanguageIds; 41 | direction: "ltr" | "rtl"; 42 | country: string; 43 | countryCode: string; 44 | flag: LanguageFlag; 45 | region?: string; 46 | regionCode?: string; 47 | } 48 | 49 | export interface LanguageIds { 50 | locale: string; 51 | ISO_639_1?: string; 52 | ISO_639_2?: string; 53 | ISO_639_3?: string; 54 | androidCode: string; 55 | osxCode: string; 56 | osxLocale: string; 57 | glottolog?: string; 58 | } 59 | 60 | export interface LanguageFlag { 61 | image: `https://crowdin.com/images/flags/${string}.png`; 62 | emoji?: string; 63 | primaryColor: Color; 64 | flagColors: Color[]; 65 | } 66 | 67 | export interface Color { 68 | hex: `#${string}`; 69 | rgb: [number, number, number]; 70 | cmyk: [number, number, number, number]; 71 | base10: number; 72 | } 73 | -------------------------------------------------------------------------------- /src/tests/flag/getFlag.test.ts: -------------------------------------------------------------------------------- 1 | import { getFlag } from "../.."; 2 | 3 | describe("getIds()", () => { 4 | test("Getting the ids of a language given its locale", () => { 5 | expect(getFlag("nl-nl")).toStrictEqual({ 6 | image: "https://crowdin.com/images/flags/nl.png", 7 | emoji: "🇳🇱", 8 | primaryColor: { hex: "#FF4F00", rgb: [255, 79, 0], cmyk: [0, 69, 100, 0], base10: 16731904 }, 9 | flagColors: [ 10 | { hex: "#C8102E", rgb: [200, 16, 46], cmyk: [0, 100, 80, 5], base10: 13111342 }, 11 | { hex: "#FFFFFF", rgb: [255, 255, 255], cmyk: [0, 0, 0, 0], base10: 16777215 }, 12 | { hex: "#003DA5", rgb: [0, 61, 165], cmyk: [100, 76, 0, 9], base10: 15781 } 13 | ] 14 | }); 15 | }); 16 | 17 | test("Getting the ids of a language given its ISO codes", () => { 18 | expect(getFlag("pt")).toStrictEqual({ 19 | image: "https://crowdin.com/images/flags/pt-PT.png", 20 | emoji: "🇵🇹", 21 | primaryColor: { hex: "#FF0000", rgb: [255, 0, 0], cmyk: [0, 100, 100, 0], base10: 16711680 }, 22 | flagColors: [ 23 | { hex: "#046A38", rgb: [4, 106, 56], cmyk: [85, 3, 91, 44], base10: 289336 }, 24 | { hex: "#DA291C", rgb: [218, 41, 28], cmyk: [0, 95, 100, 0], base10: 14297372 }, 25 | { hex: "#FFE900", rgb: [255, 233, 0], cmyk: [0, 3, 97, 0], base10: 16771328 }, 26 | { hex: "#002D72", rgb: [0, 45, 114], cmyk: [100, 79, 0, 37], base10: 11634 }, 27 | { hex: "#FFFFFF", rgb: [255, 255, 255], cmyk: [0, 0, 0, 0], base10: 16777215 }, 28 | { hex: "#000000", rgb: [0, 0, 0], cmyk: [0, 0, 0, 100], base10: 0 } 29 | ] 30 | }); 31 | expect(getFlag("nld")).toStrictEqual({ 32 | image: "https://crowdin.com/images/flags/nl.png", 33 | emoji: "🇳🇱", 34 | primaryColor: { hex: "#FF4F00", rgb: [255, 79, 0], cmyk: [0, 69, 100, 0], base10: 16731904 }, 35 | flagColors: [ 36 | { hex: "#C8102E", rgb: [200, 16, 46], cmyk: [0, 100, 80, 5], base10: 13111342 }, 37 | { hex: "#FFFFFF", rgb: [255, 255, 255], cmyk: [0, 0, 0, 0], base10: 16777215 }, 38 | { hex: "#003DA5", rgb: [0, 61, 165], cmyk: [100, 76, 0, 9], base10: 15781 } 39 | ] 40 | }); 41 | expect(getFlag("afb")).toStrictEqual({ 42 | image: "https://crowdin.com/images/flags/ar-BH.png", 43 | emoji: "🇧🇭", 44 | primaryColor: { hex: "#F21731", rgb: [242, 23, 49], cmyk: [0, 91, 80, 5], base10: 15865649 }, 45 | flagColors: [ 46 | { hex: "#CE1126", rgb: [206, 17, 38], cmyk: [0, 95, 100, 0], base10: 13504806 }, 47 | { hex: "#FFFFFF", rgb: [255, 255, 255], cmyk: [0, 0, 0, 0], base10: 16777215 } 48 | ] 49 | }); 50 | }); 51 | 52 | test("Getting the ids of a language given its name", () => { 53 | expect(getFlag("english")).toStrictEqual({ 54 | image: "https://crowdin.com/images/flags/en.png", 55 | emoji: "🇺🇸", 56 | primaryColor: { hex: "#0A3161", rgb: [10, 49, 97], cmyk: [90, 49, 0, 62], base10: 668001 }, 57 | flagColors: [ 58 | { hex: "#B31942", rgb: [179, 25, 66], cmyk: [0, 100, 66, 13], base10: 11737410 }, 59 | { hex: "#FFFFFF", rgb: [255, 255, 255], cmyk: [0, 0, 0, 0], base10: 16777215 }, 60 | { hex: "#0A3161", rgb: [10, 49, 97], cmyk: [100, 68, 0, 54], base10: 668001 } 61 | ] 62 | }); 63 | }); 64 | }); 65 | -------------------------------------------------------------------------------- /src/tests/findLanguage.test.ts: -------------------------------------------------------------------------------- 1 | import findLanguage from "../functions/findLanguage"; 2 | 3 | const NL = { 4 | name: "Dutch", 5 | nativeName: "Nederlands", 6 | ids: { 7 | locale: "nl-NL", 8 | ISO_639_1: "nl", 9 | ISO_639_2: "nld", 10 | ISO_639_3: "nld", 11 | androidCode: "nl-rNL", 12 | osxCode: "nl.lproj", 13 | osxLocale: "nl", 14 | glottolog: "mode1257" 15 | }, 16 | direction: "ltr", 17 | country: "Netherlands", 18 | countryCode: "nl", 19 | flag: { 20 | image: "https://crowdin.com/images/flags/nl.png", 21 | emoji: "🇳🇱", 22 | primaryColor: { hex: "#FF4F00", rgb: [255, 79, 0], cmyk: [0, 69, 100, 0], base10: 16731904 }, 23 | flagColors: [ 24 | { hex: "#C8102E", rgb: [200, 16, 46], cmyk: [0, 100, 80, 5], base10: 13111342 }, 25 | { hex: "#FFFFFF", rgb: [255, 255, 255], cmyk: [0, 0, 0, 0], base10: 16777215 }, 26 | { hex: "#003DA5", rgb: [0, 61, 165], cmyk: [100, 76, 0, 9], base10: 15781 } 27 | ] 28 | } 29 | }, 30 | PT = { 31 | name: "Portuguese", 32 | nativeName: "Português", 33 | ids: { 34 | locale: "pt-PT", 35 | ISO_639_1: "pt", 36 | ISO_639_2: "por", 37 | ISO_639_3: "por", 38 | androidCode: "pt-rPT", 39 | osxCode: "pt.lproj", 40 | osxLocale: "pt", 41 | glottolog: "port1283" 42 | }, 43 | direction: "ltr", 44 | country: "Portugal", 45 | countryCode: "pt", 46 | flag: { 47 | image: "https://crowdin.com/images/flags/pt-PT.png", 48 | emoji: "🇵🇹", 49 | primaryColor: { hex: "#FF0000", rgb: [255, 0, 0], cmyk: [0, 100, 100, 0], base10: 16711680 }, 50 | flagColors: [ 51 | { hex: "#046A38", rgb: [4, 106, 56], cmyk: [85, 3, 91, 44], base10: 289336 }, 52 | { hex: "#DA291C", rgb: [218, 41, 28], cmyk: [0, 95, 100, 0], base10: 14297372 }, 53 | { hex: "#FFE900", rgb: [255, 233, 0], cmyk: [0, 3, 97, 0], base10: 16771328 }, 54 | { hex: "#002D72", rgb: [0, 45, 114], cmyk: [100, 79, 0, 37], base10: 11634 }, 55 | { hex: "#FFFFFF", rgb: [255, 255, 255], cmyk: [0, 0, 0, 0], base10: 16777215 }, 56 | { hex: "#000000", rgb: [0, 0, 0], cmyk: [0, 0, 0, 100], base10: 0 } 57 | ] 58 | } 59 | }, 60 | BH = { 61 | name: "Arabic, Bahrain", 62 | nativeName: "اللهجة البحرينية", 63 | ids: { 64 | locale: "ar-BH", 65 | ISO_639_1: "ar", 66 | ISO_639_2: "ara", 67 | ISO_639_3: "afb", 68 | androidCode: "ar-rBH", 69 | osxCode: "ar-BH.lproj", 70 | osxLocale: "ar_BH", 71 | glottolog: "gulf1241" 72 | }, 73 | direction: "rtl", 74 | country: "Bahrain", 75 | countryCode: "bh", 76 | flag: { 77 | image: "https://crowdin.com/images/flags/ar-BH.png", 78 | emoji: "🇧🇭", 79 | primaryColor: { hex: "#F21731", rgb: [242, 23, 49], cmyk: [0, 91, 80, 5], base10: 15865649 }, 80 | flagColors: [ 81 | { hex: "#CE1126", rgb: [206, 17, 38], cmyk: [0, 95, 100, 0], base10: 13504806 }, 82 | { hex: "#FFFFFF", rgb: [255, 255, 255], cmyk: [0, 0, 0, 0], base10: 16777215 } 83 | ] 84 | } 85 | }, 86 | EN = { 87 | name: "English", 88 | nativeName: "English", 89 | ids: { 90 | locale: "en", 91 | ISO_639_1: "en", 92 | ISO_639_2: "eng", 93 | ISO_639_3: "eng", 94 | androidCode: "en-rUS", 95 | osxCode: "en.lproj", 96 | osxLocale: "en", 97 | glottolog: "stan1293" 98 | }, 99 | direction: "ltr", 100 | country: "United States", 101 | countryCode: "us", 102 | flag: { 103 | image: "https://crowdin.com/images/flags/en.png", 104 | emoji: "🇺🇸", 105 | primaryColor: { hex: "#0A3161", rgb: [10, 49, 97], cmyk: [90, 49, 0, 62], base10: 668001 }, 106 | flagColors: [ 107 | { hex: "#B31942", rgb: [179, 25, 66], cmyk: [0, 100, 66, 13], base10: 11737410 }, 108 | { hex: "#FFFFFF", rgb: [255, 255, 255], cmyk: [0, 0, 0, 0], base10: 16777215 }, 109 | { hex: "#0A3161", rgb: [10, 49, 97], cmyk: [100, 68, 0, 54], base10: 668001 } 110 | ] 111 | } 112 | }; 113 | 114 | describe("findLanguage()", () => { 115 | test("Finding the language of a language given its locale", () => { 116 | expect(findLanguage("nl-nl")).toStrictEqual(NL); 117 | }); 118 | 119 | test("Finding the language of a language given its ISO codes", () => { 120 | expect(findLanguage("pt")).toStrictEqual(PT); 121 | expect(findLanguage("nld")).toStrictEqual(NL); 122 | expect(findLanguage("afb")).toStrictEqual(BH); 123 | }); 124 | 125 | test("Finding the language of a language given its name", () => { 126 | expect(findLanguage("english")).toStrictEqual(EN); 127 | }); 128 | 129 | test("Finding the language of a language given its osxCode", () => { 130 | expect(findLanguage("en.lproj")).toStrictEqual(EN); 131 | }); 132 | 133 | test("Finding the language of a language given its osxLocale", () => { 134 | expect(findLanguage("ar_BH")).toStrictEqual(BH); 135 | }); 136 | 137 | test("Finding the language of a language given its android code", () => { 138 | expect(findLanguage("ar-rBH")).toStrictEqual(BH); 139 | }); 140 | }); 141 | -------------------------------------------------------------------------------- /src/tests/getLanguage.test.ts: -------------------------------------------------------------------------------- 1 | import { getLanguage } from ".."; 2 | 3 | const NL = { 4 | name: "Dutch", 5 | nativeName: "Nederlands", 6 | ids: { 7 | locale: "nl-NL", 8 | ISO_639_1: "nl", 9 | ISO_639_2: "nld", 10 | ISO_639_3: "nld", 11 | androidCode: "nl-rNL", 12 | osxCode: "nl.lproj", 13 | osxLocale: "nl", 14 | glottolog: "mode1257" 15 | }, 16 | direction: "ltr", 17 | country: "Netherlands", 18 | countryCode: "nl", 19 | flag: { 20 | image: "https://crowdin.com/images/flags/nl.png", 21 | emoji: "🇳🇱", 22 | primaryColor: { hex: "#FF4F00", rgb: [255, 79, 0], cmyk: [0, 69, 100, 0], base10: 16731904 }, 23 | flagColors: [ 24 | { hex: "#C8102E", rgb: [200, 16, 46], cmyk: [0, 100, 80, 5], base10: 13111342 }, 25 | { hex: "#FFFFFF", rgb: [255, 255, 255], cmyk: [0, 0, 0, 0], base10: 16777215 }, 26 | { hex: "#003DA5", rgb: [0, 61, 165], cmyk: [100, 76, 0, 9], base10: 15781 } 27 | ] 28 | } 29 | }, 30 | PT = { 31 | name: "Portuguese", 32 | nativeName: "Português", 33 | ids: { 34 | locale: "pt-PT", 35 | ISO_639_1: "pt", 36 | ISO_639_2: "por", 37 | ISO_639_3: "por", 38 | androidCode: "pt-rPT", 39 | osxCode: "pt.lproj", 40 | osxLocale: "pt", 41 | glottolog: "port1283" 42 | }, 43 | direction: "ltr", 44 | country: "Portugal", 45 | countryCode: "pt", 46 | flag: { 47 | image: "https://crowdin.com/images/flags/pt-PT.png", 48 | emoji: "🇵🇹", 49 | primaryColor: { hex: "#FF0000", rgb: [255, 0, 0], cmyk: [0, 100, 100, 0], base10: 16711680 }, 50 | flagColors: [ 51 | { hex: "#046A38", rgb: [4, 106, 56], cmyk: [85, 3, 91, 44], base10: 289336 }, 52 | { hex: "#DA291C", rgb: [218, 41, 28], cmyk: [0, 95, 100, 0], base10: 14297372 }, 53 | { hex: "#FFE900", rgb: [255, 233, 0], cmyk: [0, 3, 97, 0], base10: 16771328 }, 54 | { hex: "#002D72", rgb: [0, 45, 114], cmyk: [100, 79, 0, 37], base10: 11634 }, 55 | { hex: "#FFFFFF", rgb: [255, 255, 255], cmyk: [0, 0, 0, 0], base10: 16777215 }, 56 | { hex: "#000000", rgb: [0, 0, 0], cmyk: [0, 0, 0, 100], base10: 0 } 57 | ] 58 | } 59 | }, 60 | BH = { 61 | name: "Arabic, Bahrain", 62 | nativeName: "اللهجة البحرينية", 63 | ids: { 64 | locale: "ar-BH", 65 | ISO_639_1: "ar", 66 | ISO_639_2: "ara", 67 | ISO_639_3: "afb", 68 | androidCode: "ar-rBH", 69 | osxCode: "ar-BH.lproj", 70 | osxLocale: "ar_BH", 71 | glottolog: "gulf1241" 72 | }, 73 | direction: "rtl", 74 | country: "Bahrain", 75 | countryCode: "bh", 76 | flag: { 77 | image: "https://crowdin.com/images/flags/ar-BH.png", 78 | emoji: "🇧🇭", 79 | primaryColor: { hex: "#F21731", rgb: [242, 23, 49], cmyk: [0, 91, 80, 5], base10: 15865649 }, 80 | flagColors: [ 81 | { hex: "#CE1126", rgb: [206, 17, 38], cmyk: [0, 95, 100, 0], base10: 13504806 }, 82 | { hex: "#FFFFFF", rgb: [255, 255, 255], cmyk: [0, 0, 0, 0], base10: 16777215 } 83 | ] 84 | } 85 | }, 86 | EN = { 87 | name: "English", 88 | nativeName: "English", 89 | ids: { 90 | locale: "en", 91 | ISO_639_1: "en", 92 | ISO_639_2: "eng", 93 | ISO_639_3: "eng", 94 | androidCode: "en-rUS", 95 | osxCode: "en.lproj", 96 | osxLocale: "en", 97 | glottolog: "stan1293" 98 | }, 99 | direction: "ltr", 100 | country: "United States", 101 | countryCode: "us", 102 | flag: { 103 | image: "https://crowdin.com/images/flags/en.png", 104 | emoji: "🇺🇸", 105 | primaryColor: { hex: "#0A3161", rgb: [10, 49, 97], cmyk: [90, 49, 0, 62], base10: 668001 }, 106 | flagColors: [ 107 | { hex: "#B31942", rgb: [179, 25, 66], cmyk: [0, 100, 66, 13], base10: 11737410 }, 108 | { hex: "#FFFFFF", rgb: [255, 255, 255], cmyk: [0, 0, 0, 0], base10: 16777215 }, 109 | { hex: "#0A3161", rgb: [10, 49, 97], cmyk: [100, 68, 0, 54], base10: 668001 } 110 | ] 111 | } 112 | }; 113 | 114 | describe("getLanguage()", () => { 115 | test("Getting the language of a language given its locale", () => { 116 | expect(getLanguage("nl-nl")).toStrictEqual(NL); 117 | }); 118 | 119 | test("Getting the language of a language given its ISO codes", () => { 120 | expect(getLanguage("pt")).toStrictEqual(PT); 121 | expect(getLanguage("nld")).toStrictEqual(NL); 122 | expect(getLanguage("afb")).toStrictEqual(BH); 123 | }); 124 | 125 | test("Getting the language of a language given its name", () => { 126 | expect(getLanguage("english")).toStrictEqual(EN); 127 | }); 128 | }); 129 | 130 | describe("getLanguage(array)", () => { 131 | test("Getting the language of a language given its locale", () => { 132 | expect(getLanguage(["nl-nl"])).toStrictEqual([NL]); 133 | }); 134 | 135 | test("Getting the language of a language given its ISO codes", () => { 136 | expect(getLanguage(["pt", "nld", "afb"])).toStrictEqual([PT, NL, BH]); 137 | }); 138 | 139 | test("Getting the language of a language given its name", () => { 140 | expect(getLanguage(["english"])).toStrictEqual([EN]); 141 | }); 142 | }); 143 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | # [2.1.2](https://github.com/Bas950/Language-Flag-Colors/compare/2.1.1...2.1.2) - (20-09-2022) 6 | 7 | ## Refactor 8 | 9 | - Use gen-esm-wrapper for esm compatibility ([f5dec65](https://github.com/Bas950/Language-Flag-Colors/commit/f5dec6541e247c7a01779a4eef7ed9b2509f0e06)) 10 | 11 | # [2.1.1](https://github.com/Bas950/Language-Flag-Colors/compare/2.1.0...2.1.1) - (21-08-2022) 12 | 13 | ## Features 14 | 15 | - Allow osx locale/code and android code when searching for a language ([cc3904d](https://github.com/Bas950/Language-Flag-Colors/commit/cc3904d0475b749fe64e9e1030303c6e9a1a81db)) 16 | 17 | # [2.1.0](https://github.com/Bas950/Language-Flag-Colors/compare/2.0.4...2.1.0) - (19-06-2022) 18 | 19 | ## Features 20 | 21 | - Add support for ESM (#13) ([ebcc496](https://github.com/Bas950/Language-Flag-Colors/commit/ebcc496f8cc34b74f78817e2dbff260a440cdd5e)) 22 | 23 | ## Refactor 24 | 25 | - Use named exports ([70cb958](https://github.com/Bas950/Language-Flag-Colors/commit/70cb958227b32e0e29d7368d034c521040e18502)) 26 | 27 | # [2.0.4](https://github.com/Bas950/Language-Flag-Colors/compare/2.0.2...2.0.4) - (18-01-2022) 28 | 29 | ## Bug Fixes 30 | 31 | - Correct country names and codes ([40e69fe](https://github.com/Bas950/Language-Flag-Colors/commit/40e69fe1a94098ec1e62861570313a3c0fa1b3c2)) 32 | - **getEmoji:** Try to find a language with an emoji first ([9a598b5](https://github.com/Bas950/Language-Flag-Colors/commit/9a598b57b995269db92a796b116e076685825c0c)) 33 | - Remove incorrect emojis/add more accurate ones ([1f1aac1](https://github.com/Bas950/Language-Flag-Colors/commit/1f1aac1c981f8de7203d0fe95632cdbf0a91176c)) 34 | - Add ALL missing emojis (sorry) ([201419d](https://github.com/Bas950/Language-Flag-Colors/commit/201419dc2ec056aff36908ab33149dcad2739e0d)) 35 | 36 | # [2.0.2](https://github.com/Bas950/Language-Flag-Colors/compare/2.0.1...2.0.2) - (17-01-2022) 37 | 38 | ## Bug Fixes 39 | 40 | - Add missing emojis ([111deb2](https://github.com/Bas950/Language-Flag-Colors/commit/111deb27b6d87b651029da4fdc30d38f173368c3)) 41 | 42 | # [2.0.1](https://github.com/Bas950/Language-Flag-Colors/compare/2.0.0...2.0.1) - (01-01-2022) 43 | 44 | ## Documentation 45 | 46 | - Fix space ([7e311d1](https://github.com/Bas950/Language-Flag-Colors/commit/7e311d13dbbb33cc3bdc59f0c18e89db7c9b8793)) 47 | 48 | # [2.0.0](https://github.com/Bas950/Language-Flag-Colors/compare/1.2.0...2.0.0) - (01-01-2022) 49 | 50 | ## Documentation 51 | 52 | - Support for new functions ([8906fb2](https://github.com/Bas950/Language-Flag-Colors/commit/8906fb2cf62dbbe2ca20746ba7bd0aa3cc03fb39)) 53 | 54 | ## Features 55 | 56 | - **getGlottolog:** Add function ([0ca52cd](https://github.com/Bas950/Language-Flag-Colors/commit/0ca52cda608b85ab83dd3b2c86415f61e4e4b916)) 57 | - **getOSXLocale:** Add function ([cf1a2c7](https://github.com/Bas950/Language-Flag-Colors/commit/cf1a2c7911dfb5f30d740dad0a5e6b8ebb7e4a7c)) 58 | - **getOSXCode:** Add function ([9791501](https://github.com/Bas950/Language-Flag-Colors/commit/9791501eee42bdd2be2170353ff6bc8a0153d3c4)) 59 | - **getAndroidCode:** Add function ([f855891](https://github.com/Bas950/Language-Flag-Colors/commit/f8558910ad3228b20732aa9fcc3c07c1a54cc24f)) 60 | - **getISO_639_3:** Add function ([165b6e5](https://github.com/Bas950/Language-Flag-Colors/commit/165b6e550bbaa90140e2218defa9b9dfb7527a22)) 61 | - **getISO_639_2:** Add function ([e40ff58](https://github.com/Bas950/Language-Flag-Colors/commit/e40ff58b5a845a5c795d50c872617d7ce2074344)) 62 | - **getISO_639_1:** Add function ([2a348bc](https://github.com/Bas950/Language-Flag-Colors/commit/2a348bc7e25e147fba39132f05142a3854275729)) 63 | - **getIds:** Add function ([c0cca5e](https://github.com/Bas950/Language-Flag-Colors/commit/c0cca5ed3a5bb7c07f2f18bcf5b323ed1cd37def)) 64 | - **getPrimaryCMYK:** Add function ([7b885ce](https://github.com/Bas950/Language-Flag-Colors/commit/7b885ce5855d196681264f2e803dcccca6e40612)) 65 | - **getBase10FlagColors:** Add function ([30ebb48](https://github.com/Bas950/Language-Flag-Colors/commit/30ebb48521f7aed2f953f1de0e828d71ef5c664a)) 66 | - **getCMYKFlagColors:** Add function ([6e1b867](https://github.com/Bas950/Language-Flag-Colors/commit/6e1b867248a1ec6b6f5171dbf2330ebc6d2250a3)) 67 | - **getRGBFlagColors:** Add function ([033e4c1](https://github.com/Bas950/Language-Flag-Colors/commit/033e4c1c11cfcc06c375acf8013e8cb28f681cc7)) 68 | - **getHexFlagColors:** Add function ([6bdb0cd](https://github.com/Bas950/Language-Flag-Colors/commit/6bdb0cd1821defd46d9162b92f681b91bfc15fdf)) 69 | - **getFlagColors:** Add function ([8f726e1](https://github.com/Bas950/Language-Flag-Colors/commit/8f726e117c7d497c7cb0a15f5b0dd3f1d9d9b474)) 70 | - **getImage:** Add function ([2c3f37d](https://github.com/Bas950/Language-Flag-Colors/commit/2c3f37d7e0b467c5f45bcffb13a3903e6eceb53f)) 71 | - **getFlag:** Add function ([b4a3dc7](https://github.com/Bas950/Language-Flag-Colors/commit/b4a3dc7686b0d8e7cb42ead026279010a5dce876)) 72 | - **Changelog:** Use git cliff with cliff config ([9119357](https://github.com/Bas950/Language-Flag-Colors/commit/911935701e05d99616aed5fddc78465b387055e7)) 73 | - **Languages:** Added new ids, flag colors, CMYK, and flag image ([eb79ddc](https://github.com/Bas950/Language-Flag-Colors/commit/eb79ddc787dffb3c8d1b7f52dde5110a130f08d3)) 74 | 75 | ## Refactor 76 | 77 | - **index:** Use functions from files ([9c36893](https://github.com/Bas950/Language-Flag-Colors/commit/9c36893900861844b8052331f05e9f463fe19d95)) 78 | - Move functions to their own files, tests too ([ff8cc19](https://github.com/Bas950/Language-Flag-Colors/commit/ff8cc191802dd648f44eb528694dc5fecbc524b9)) 79 | 80 | # [1.2.0](https://github.com/Bas950/Language-Flag-Colors/compare/1.1.1...1.2.0) - (28-12-2021) 81 | 82 | ## Features 83 | 84 | - NativeName and direction ([3b134b9](https://github.com/Bas950/Language-Flag-Colors/commit/3b134b9170d66e566f2541a90c4fde69d975d724)) 85 | 86 | # [1.1.1](https://github.com/Bas950/Language-Flag-Colors/compare/1.1.0...1.1.1) - (30-11-2021) 87 | 88 | ## Bug Fixes 89 | 90 | - Typo in method names ([8f5591c](https://github.com/Bas950/Language-Flag-Colors/commit/8f5591ca33215bf1cc5ab98d5a153e0e47130475)) 91 | - **getEmoji:** Improve country searching ([31179f4](https://github.com/Bas950/Language-Flag-Colors/commit/31179f464142ac4d6623bdb8e53fe793f217fb34)) 92 | 93 | ## Documentation 94 | 95 | - Add missing info from last update ([bbfe372](https://github.com/Bas950/Language-Flag-Colors/commit/bbfe37221b8ea97550d9926e6792bf268c70edcb)) 96 | 97 | ## Styling 98 | 99 | - Add prettier config and format files ([82f4ffe](https://github.com/Bas950/Language-Flag-Colors/commit/82f4ffe6b29dba6afce283326520d92ccd88bf7a)) 100 | 101 | ## Testing 102 | 103 | - Added tests ([ab258c1](https://github.com/Bas950/Language-Flag-Colors/commit/ab258c15ffcd8316d695430f6f110987bdd40341)) 104 | 105 | # [1.1.0](https://github.com/Bas950/Language-Flag-Colors/compare/1.0.2...1.1.0) - (27-11-2021) 106 | 107 | ## Documentation 108 | 109 | - Add getEmoji examples ([fb15807](https://github.com/Bas950/Language-Flag-Colors/commit/fb15807e7f6f8363d3988683811a5932e14e65f4)) 110 | - Use nullish type notation ([ea1e4f8](https://github.com/Bas950/Language-Flag-Colors/commit/ea1e4f85b059151c786ebf8a6ae9b3e94bb9e0fb)) 111 | 112 | ## Features 113 | 114 | - Add emojis and getEmoji method ([394df65](https://github.com/Bas950/Language-Flag-Colors/commit/394df6592196e35e2f383d9dce996e1a6614d432)) 115 | 116 | ## Refactor 117 | 118 | - Make findLanguage return undefined ([6477454](https://github.com/Bas950/Language-Flag-Colors/commit/647745416c8911aa24a94ed3b332246e8dce808d)) 119 | 120 | ## Types 121 | 122 | - Specify return types for all methods ([610c581](https://github.com/Bas950/Language-Flag-Colors/commit/610c58193430884f8923f3d4c13eee91b5a81f4e)) 123 | 124 | # [1.0.2](https://github.com/Bas950/Language-Flag-Colors/compare/1.0.1...1.0.2) - (27-10-2021) 125 | 126 | ## Bug Fixes 127 | 128 | - **Languages:** Make Irish green ([6787383](https://github.com/Bas950/Language-Flag-Colors/commit/67873838028f3a7a4d7ffa9a6a4d6474e98dbfb3)) 129 | 130 | # [1.0.1](https://github.com/Bas950/Language-Flag-Colors/compare/1.0.0...1.0.1) - (23-10-2021) 131 | 132 | ## Documentation 133 | 134 | - Fix installation script ([1145812](https://github.com/Bas950/Language-Flag-Colors/commit/11458121e174bb7b381300d4fa5bca241211849f)) 135 | 136 | # [1.0.0] 137 | 138 | (https://github.com/Bas950/Language-Flag-Colors/tree/1.0.0 - (23-10-2021) 139 | 140 | ## Features 141 | 142 | - Add keywords ([42ffb76](https://github.com/Bas950/Language-Flag-Colors/commit/42ffb7604156287c9703296579114a37fa788007)) 143 | - Add languages and functions ([2201bd2](https://github.com/Bas950/Language-Flag-Colors/commit/2201bd2cc4a1b57b834bb34cad1706c21e5ba598)) 144 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Visit https://aka.ms/tsconfig.json to read more about this file */ 4 | 5 | /* Projects */ 6 | // "incremental": true, /* Enable incremental compilation */ 7 | // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ 8 | // "tsBuildInfoFile": "./", /* Specify the folder for .tsbuildinfo incremental compilation files. */ 9 | // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects */ 10 | // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ 11 | // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ 12 | 13 | /* Language and Environment */ 14 | "target": "es2022" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, 15 | "lib": ["es2022"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ 16 | // "jsx": "preserve", /* Specify what JSX code is generated. */ 17 | // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ 18 | // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ 19 | // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */ 20 | // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ 21 | // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.` */ 22 | // "reactNamespace": "", /* Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit. */ 23 | // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ 24 | // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ 25 | 26 | /* Modules */ 27 | "module": "commonjs" /* Specify what module code is generated. */, 28 | "rootDir": "./src" /* Specify the root folder within your source files. */, 29 | "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ 30 | // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ 31 | // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ 32 | // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ 33 | // "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */ 34 | // "types": [], /* Specify type package names to be included without being referenced in a source file. */ 35 | // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ 36 | // "resolveJsonModule": true, /* Enable importing .json files */ 37 | // "noResolve": true, /* Disallow `import`s, `require`s or ``s from expanding the number of files TypeScript should add to a project. */ 38 | 39 | /* JavaScript Support */ 40 | // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */ 41 | // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ 42 | // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */ 43 | 44 | /* Emit */ 45 | "declaration": true /* Generate .d.ts files from TypeScript and JavaScript files in your project. */, 46 | // "declarationMap": true /* Create sourcemaps for d.ts files. */, 47 | // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ 48 | // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ 49 | // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */ 50 | "outDir": "./bin" /* Specify an output folder for all emitted files. */, 51 | // "removeComments": true, /* Disable emitting comments. */ 52 | // "noEmit": true, /* Disable emitting files from a compilation. */ 53 | // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ 54 | // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */ 55 | // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ 56 | // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ 57 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ 58 | // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ 59 | // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ 60 | // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ 61 | // "newLine": "crlf", /* Set the newline character for emitting files. */ 62 | // "stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */ 63 | // "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */ 64 | // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ 65 | // "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */ 66 | // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ 67 | 68 | /* Interop Constraints */ 69 | // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ 70 | // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ 71 | "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */, 72 | // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ 73 | "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */, 74 | 75 | /* Type Checking */ 76 | "strict": true /* Enable all strict type-checking options. */, 77 | // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */ 78 | // "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */ 79 | // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ 80 | // "strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */ 81 | // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ 82 | // "noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */ 83 | // "useUnknownInCatchVariables": true, /* Type catch clause variables as 'unknown' instead of 'any'. */ 84 | // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ 85 | "noUnusedLocals": true /* Enable error reporting when a local variables aren't read. */, 86 | "noUnusedParameters": true /* Raise an error when a function parameter isn't read */, 87 | "exactOptionalPropertyTypes": true /* Interpret optional property types as written, rather than adding 'undefined'. */ 88 | // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ 89 | // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ 90 | // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ 91 | // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ 92 | // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type */ 93 | // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ 94 | // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ 95 | 96 | /* Completeness */ 97 | // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ 98 | // "skipLibCheck": true /* Skip type checking all .d.ts files. */ 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # THIS PACKAGE HAS BEEN MOVED TO [Bas950/Packages](https://github.com/Bas950/packages/tree/main/packages/Language-Flag-Colors) 2 | 3 | 4 | # Language-Flag-Colors [![Version](https://img.shields.io/npm/v/language-flag-colors.svg)](https://www.npmjs.com/package/language-flag-colors) 5 | 6 | A package with the color of every language's flag 7 | 8 | ## Instalation 9 | 10 | ```bash 11 | # npm 12 | npm install language-flag-colors 13 | 14 | # yarn 15 | yarn add language-flag-colors 16 | ``` 17 | 18 | ## Usage 19 | 20 | ### Importing 21 | 22 | #### TypeScript 23 | 24 | ```ts 25 | // Here we're importing the default export "languages", which is an array with all the language objects 26 | // as well as the getLanguage function which is used to get a language object or an array of language objects 27 | import languages, { getLanguage } from "language-flag-colors"; 28 | ``` 29 | 30 | #### JavaScript 31 | 32 | ```js 33 | // Here we're importing the default export "languages", which is an array with all the language objects 34 | // as well as the getLanguage function which is used to get a language object or an array of language objects 35 | const { getLanguage, default: languages } = require("language-flag-colors"); 36 | ``` 37 | 38 | Or, if you only want the default array export 39 | 40 | ```js 41 | const languages = require("language-flag-colors"); 42 | ``` 43 | 44 | Or if you only want a function 45 | 46 | ```js 47 | const { getLanguage } = require("language-flag-colors"); 48 | ``` 49 | 50 | ### Using our custom methods 51 | 52 | ```js 53 | // Every method's input is case-insensitive! 54 | 55 | // Getting the full language object for one language 56 | // This method accepts a language's name, locale or ISO 639-(1/2/3) code 57 | const dutch = getLanguage("Dutch"); 58 | const portuguese = getLanguage("pt-pt"); 59 | 60 | // Getting an array of language objects for multiple languages 61 | const [dutch, portuguese] = getLanguage(["nl-nl", "portuguese"]); // This will return an array with the language objects corresponding to Dutch and Portuguese 62 | 63 | // Getting the name of a language 64 | // This method accepts a language's name, locale or ISO 639-(1/2/3) code 65 | const ptName = getName("pt-pt"); // Will return "Portuguese" 66 | 67 | // Getting the native name of a language 68 | // This method accepts a language's name, locale or ISO 639-(1/2/3) code 69 | const ptNativeName = getNativeName("pt-pt"); // Will return "Português" 70 | 71 | // Getting a language's IDs. This will return an object with the language's locale, ISO_639_1, ISO_639_2, ISO_639_3 codes, androidCode, osxCode, osxLocale and glottolog ID 72 | // This method accepts a language's name, locale or ISO 639-(1/2/3) code 73 | const dutchIds = getIds("nld"); 74 | 75 | // Getting the locale of a language 76 | // This method accepts a language's name, locale or ISO 639-(1/2/3) code 77 | const dutchLocale = getLocale("dutch"); // Will return "nl-NL" 78 | 79 | // Getting the language's ISO 639-1 code 80 | // This method accepts a language's name, locale or ISO 639-(1/2/3) code 81 | const ptISO_639_1 = getISO_639_1("PORTUGUESE"); // Will return "pt" 82 | 83 | // Getting the language's ISO 639-2 code 84 | // This method accepts a language's name, locale or ISO 639-(1/2/3) code 85 | const dutchISO_639_2 = getISO_639_2("dutch"); // Will return "nld" 86 | 87 | // Getting the language's ISO 639-3 code 88 | // This method accepts a language's name, locale or ISO 639-(1/2/3) code 89 | const englishISO_639_3 = getISO_639_3("English"); // Will return "eng" 90 | 91 | // Getting the language's Android code. This is used to name "values-" directories in Android-based OSs 92 | // This method accepts a language's name, locale or ISO 639-(1/2/3) code 93 | const ptAndroidCode = getAndroidCode("PORTUGUESE"); // Will return "pt-rPT" 94 | 95 | // Getting the language's OS X code 96 | // This method accepts a language's name, locale or ISO 639-(1/2/3) code 97 | const dutchOSXCode = getOSXCode("nl-nl"); // Will return "nl.lproj" 98 | 99 | // Getting the language's OS X locale 100 | // This method accepts a language's name, locale or ISO 639-(1/2/3) code 101 | const englishOSXLocale = getOSXLocale("eng"); // Will return "en" 102 | 103 | // Getting the language's Glottolog ID. This will return the link to the glottolog page on the language provided if the second parameter is passed as true 104 | // This method accepts a language's name, locale or ISO 639-(1/2/3) code 105 | const ptGlottologUrl = getGlottolog("pt-pt", true); // Will return "https://glottolog.org/resource/languoid/id/port1283" 106 | const dutchGlottologId = getGlottolog("nl-nl"); // Will return "mode1257" 107 | 108 | // Getting a language's text direction. This can be "rtl" or "ltr" for "right-to-left" and "left-to-right" respectively 109 | const dutchDirection = getDirection("Dutch"); // Will return "ltr" 110 | const arabicDirection = getDirection("ar"); // Will return "rtl" 111 | 112 | // Getting the language's country name 113 | // This method accepts a language's name, locale or ISO 639-(1/2/3) code 114 | const ptCountry = getCountry("pt"); // Will return "Portugal" 115 | 116 | // Getting the language's country code 117 | // This method accepts a language's name, locale or ISO 639-(1/2/3) code 118 | const dutchCountryCode = getCountryCode("dutch"); // Will return "nl" 119 | 120 | // Getting all the languages in a country 121 | const netherlandsLangs = getCountryLanguages("netherlands"); // Will return an array with the language objects for Dutch, Frisian, Limburgish and Zeelandic 122 | 123 | // Getting the language's flag. This will return an object with a link to the language's flag image from Crowdin, the flag's unicode emoji, if any, the flag's primaryColor and flagColors all in hexadecimal, RGB, CMYK and base-10 124 | // This method accepts a language's name, locale or ISO 639-(1/2/3) code 125 | const ptFlag = getFlag("pt"); 126 | 127 | // Getting the language's flag image URL 128 | // This method accepts a language's name, locale or ISO 639-(1/2/3) code 129 | const dutchFlagImage = getImage("nl"); // Will return "https://crowdin.com/images/flags/nl.png" 130 | 131 | // Getting the flag unicode emoji of a language 132 | // This method accepts a country's name or code, or a language's name, locale or ISO 639-(1/2/3) code 133 | const ptEmoji = getEmoji("pt-pt"); // Will return "🇵🇹" 134 | const dutchEmoji = getEmoji("dutch"); // Will return "🇳🇱" 135 | const ukEmoji = getEmoji("United Kingdom"); // Will return "🇬🇧" 136 | const usEmoji = getEmoji("us"); // Will return "🇺🇸" 137 | 138 | // Getting the language's primary color. This will return an object with the language's primary color in hexadecimal, RGB, CMYK and base-10 139 | // This method accepts a language's name, locale or ISO 639-(1/2/3) code 140 | const ptPrimaryColor = getPrimaryColor("pt"); 141 | 142 | // Getting the primary hexadecimal color value for a language. 143 | // This method accepts a language's name, locale or ISO 639-(1/2/3) code 144 | const ptPrimaryHex = getPrimaryHex("pt-pt"); // Will return "#FF0000" 145 | const dutchPrimaryHex = getPrimaryHex("dutch"); // Will return "#FF4F00" 146 | 147 | // Getting the primary RGB color values for a language. 148 | // This method accepts a language's name, locale or ISO 639-(1/2/3) code 149 | const ptPrimaryRGB = getPrimaryRGB("pt-pt"); // Will return [255, 0, 0] 150 | const dutchPrimaryRGB = getPrimaryRGB("dutch"); // Will return [255, 79, 0] 151 | 152 | // Getting the primary CMYK color values for a language. 153 | // This method accepts a language's name, locale or ISO 639-(1/2/3) code 154 | const ptPrimaryCMYK = getPrimaryCMYK("pt-pt"); // Will return [0, 100, 100, 0] 155 | const dutchPrimaryCMYK = getPrimaryCMYK("dutch"); // Will return [0, 69, 100, 0] 156 | 157 | // Getting the primary base-10 color value for a language. 158 | // This method accepts a language's name, locale or ISO 639-(1/2/3) code 159 | const ptPrimaryBase10 = getPrimaryBase10("pt-pt"); // Will return 16711680 160 | const dutchPrimaryBase10 = getPrimaryBase10("dutch"); // Will return 16731904 161 | 162 | // Getting the language's flag colors. This will return an array of objects with the language's primary color in hexadecimal, RGB, CMYK and base-10 163 | // This method accepts a language's name, locale or ISO 639-(1/2/3) code 164 | const dutchFlagColors = getFlagColors("nl"); 165 | 166 | // Getting the hexadecimal color values for a language. 167 | // This method accepts a language's name, locale or ISO 639-(1/2/3) code 168 | const ptHexFlagColors = getHexFlagColors("pt-pt"); 169 | const dutchHexFlagColors = getHexFlagColors("dutch"); 170 | 171 | // Getting the RGB color values for a language. 172 | // This method accepts a language's name, locale or ISO 639-(1/2/3) code 173 | const ptRGBFlagColors = getRGBFlagColors("pt-pt"); 174 | const dutchRGBFlagColors = getRGBFlagColors("dutch"); 175 | 176 | // Getting the CMYK color values for a language. 177 | // This method accepts a language's name, locale or ISO 639-(1/2/3) code 178 | const ptCMYKFlagColors = getCMYKFlagColors("pt-pt"); 179 | const dutchCMYKFlagColors = getCMYKFlagColors("dutch"); 180 | 181 | // Getting the base-10 color values for a language. 182 | // This method accepts a language's name, locale or ISO 639-(1/2/3) code 183 | const ptBase10FlagColors = getBase10FlagColors("pt-pt"); 184 | const dutchBase10FlagColors = getBase10FlagColors("dutch"); 185 | 186 | // Getting the language's region name, if any 187 | // This method accepts a language's name, locale or ISO 639-(1/2/3) code 188 | const sardinianRegion = getRegion("Sardinian"); // Will return "Sardinia" 189 | 190 | // Getting the language's region code, if any 191 | // This method accepts a language's name, locale or ISO 639-(1/2/3) code 192 | const basqueRegionCode = getRegionCode("eu-ES"); // Will return "pv" 193 | 194 | // Getting all the languages specific to a region 195 | const scotlandLangs = getRegionLanguages("scotland"); // Will return an array with the language objects for Scots and Scottish Gaelic 196 | ``` 197 | 198 | ### Contributing 199 | 200 | Due to the large amount of languages we support in this package, it is possible that some information may be inaccurate. If you believe so, feel free to [open a pull request](https://github.com/Bas950/Language-Flag-Colors/compare). 201 | 202 | ### Inspiration 203 | 204 | We got all the language names and locale from [Crowdin](https://crowdin.com)'s officially supported languages (with some minor differences) and added all the colors, countries and regions manually. We hope to keep this list updated whenever they add new languages, but we may also add other ones not supported by them if these are requested by anyone. This package was created by [Bas950](https://github.com/Bas950) and [Rodry](https://github.com/ImRodry) and is not officially endorsed by Crowdin nor affiliated with the company in any way. 205 | -------------------------------------------------------------------------------- /src/tests/getCountryLanguages.test.ts: -------------------------------------------------------------------------------- 1 | import { getCountryLanguages } from ".."; 2 | 3 | describe("getCountryLanguages()", () => { 4 | test("Getting the country languages of a language given its country name", () => { 5 | expect(getCountryLanguages("netherlands")).toStrictEqual([ 6 | { 7 | name: "Dutch", 8 | nativeName: "Nederlands", 9 | ids: { 10 | locale: "nl-NL", 11 | ISO_639_1: "nl", 12 | ISO_639_2: "nld", 13 | ISO_639_3: "nld", 14 | androidCode: "nl-rNL", 15 | osxCode: "nl.lproj", 16 | osxLocale: "nl", 17 | glottolog: "mode1257" 18 | }, 19 | direction: "ltr", 20 | country: "Netherlands", 21 | countryCode: "nl", 22 | flag: { 23 | image: "https://crowdin.com/images/flags/nl.png", 24 | emoji: "🇳🇱", 25 | primaryColor: { hex: "#FF4F00", rgb: [255, 79, 0], cmyk: [0, 69, 100, 0], base10: 16731904 }, 26 | flagColors: [ 27 | { hex: "#C8102E", rgb: [200, 16, 46], cmyk: [0, 100, 80, 5], base10: 13111342 }, 28 | { hex: "#FFFFFF", rgb: [255, 255, 255], cmyk: [0, 0, 0, 0], base10: 16777215 }, 29 | { hex: "#003DA5", rgb: [0, 61, 165], cmyk: [100, 76, 0, 9], base10: 15781 } 30 | ] 31 | } 32 | }, 33 | { 34 | name: "Frisian", 35 | nativeName: "Frysk", 36 | ids: { 37 | locale: "fy-NL", 38 | ISO_639_1: "fy", 39 | ISO_639_2: "fry", 40 | ISO_639_3: "fry", 41 | androidCode: "fy-rNL", 42 | osxCode: "fy.lproj", 43 | osxLocale: "fy", 44 | glottolog: "fris1239" 45 | }, 46 | direction: "ltr", 47 | country: "Netherlands", 48 | countryCode: "nl", 49 | flag: { 50 | image: "https://crowdin.com/images/flags/fy-NL.png", 51 | primaryColor: { hex: "#0155A5", rgb: [1, 85, 165], cmyk: [99, 48, 0, 35], base10: 87461 }, 52 | flagColors: [ 53 | { hex: "#0155A5", rgb: [1, 85, 165], cmyk: [99, 48, 0, 35], base10: 87461 }, 54 | { hex: "#FFFFFF", rgb: [255, 255, 255], cmyk: [0, 0, 0, 0], base10: 16777215 }, 55 | { hex: "#EE3E34", rgb: [238, 62, 52], cmyk: [0, 74, 78, 7], base10: 15613492 } 56 | ] 57 | }, 58 | region: "Friesland", 59 | regionCode: "fr" 60 | }, 61 | { 62 | name: "Limburgish", 63 | nativeName: "Limburgs", 64 | ids: { 65 | locale: "li-LI", 66 | ISO_639_1: "li", 67 | ISO_639_2: "lim", 68 | ISO_639_3: "lim", 69 | androidCode: "li-rLI", 70 | osxCode: "li.lproj", 71 | osxLocale: "li", 72 | glottolog: "limb1263" 73 | }, 74 | direction: "ltr", 75 | country: "Netherlands", 76 | countryCode: "nl", 77 | flag: { 78 | image: "https://crowdin.com/images/flags/li.png", 79 | primaryColor: { hex: "#2D558E", rgb: [45, 85, 142], cmyk: [68, 40, 0, 44], base10: 2971022 }, 80 | flagColors: [ 81 | { hex: "#FFFFFF", rgb: [255, 255, 255], cmyk: [0, 0, 0, 0], base10: 16777215 }, 82 | { hex: "#2D558E", rgb: [45, 85, 142], cmyk: [68, 40, 0, 44], base10: 2971022 }, 83 | { hex: "#F8C60B", rgb: [248, 198, 11], cmyk: [0, 20, 96, 3], base10: 16303627 }, 84 | { hex: "#E34220", rgb: [227, 66, 32], cmyk: [0, 71, 86, 11], base10: 14893600 } 85 | ] 86 | }, 87 | region: "Limburg", 88 | regionCode: "li" 89 | }, 90 | { 91 | name: "Zeelandic", 92 | nativeName: "Zeêuws", 93 | ids: { locale: "zea-ZEA", ISO_639_3: "zea", androidCode: "zea-rZEA", osxCode: "zea.lproj", osxLocale: "zea", glottolog: "zeeu1238" }, 94 | direction: "ltr", 95 | country: "Netherlands", 96 | countryCode: "nl", 97 | flag: { 98 | image: "https://crowdin.com/images/flags/zea.png", 99 | primaryColor: { hex: "#1E09A2", rgb: [30, 9, 162], cmyk: [81, 94, 0, 36], base10: 1968546 }, 100 | flagColors: [ 101 | { hex: "#1E09A2", rgb: [30, 9, 162], cmyk: [81, 94, 0, 36], base10: 1968546 }, 102 | { hex: "#FFFFFF", rgb: [255, 255, 255], cmyk: [0, 0, 0, 0], base10: 16777215 }, 103 | { hex: "#F3E01B", rgb: [243, 224, 27], cmyk: [0, 8, 89, 5], base10: 15982619 }, 104 | { hex: "#CC182C", rgb: [204, 24, 44], cmyk: [0, 88, 78, 20], base10: 13375532 } 105 | ] 106 | }, 107 | region: "Zeeland", 108 | regionCode: "zea" 109 | } 110 | ]); 111 | }); 112 | 113 | test("Getting the country languages of a language given its country code", () => { 114 | expect(getCountryLanguages("us")).toStrictEqual([ 115 | { 116 | name: "Cherokee", 117 | nativeName: "ᏣᎳᎩ", 118 | ids: { 119 | locale: "chr-US", 120 | ISO_639_2: "chr", 121 | ISO_639_3: "chr", 122 | androidCode: "chr-rUS", 123 | osxCode: "chr.lproj", 124 | osxLocale: "chr", 125 | glottolog: "cher1273" 126 | }, 127 | direction: "ltr", 128 | country: "United States", 129 | countryCode: "us", 130 | flag: { 131 | image: "https://crowdin.com/images/flags/chr.png", 132 | emoji: "🇺🇸", 133 | primaryColor: { hex: "#0A3161", rgb: [10, 49, 97], cmyk: [90, 49, 0, 62], base10: 668001 }, 134 | flagColors: [ 135 | { hex: "#B31942", rgb: [179, 25, 66], cmyk: [0, 100, 66, 13], base10: 11737410 }, 136 | { hex: "#FFFFFF", rgb: [255, 255, 255], cmyk: [0, 0, 0, 0], base10: 16777215 }, 137 | { hex: "#0A3161", rgb: [10, 49, 97], cmyk: [100, 68, 0, 54], base10: 668001 } 138 | ] 139 | }, 140 | region: "Oklahoma", 141 | regionCode: "ok" 142 | }, 143 | { 144 | name: "English", 145 | nativeName: "English", 146 | ids: { 147 | locale: "en", 148 | ISO_639_1: "en", 149 | ISO_639_2: "eng", 150 | ISO_639_3: "eng", 151 | androidCode: "en-rUS", 152 | osxCode: "en.lproj", 153 | osxLocale: "en", 154 | glottolog: "stan1293" 155 | }, 156 | direction: "ltr", 157 | country: "United States", 158 | countryCode: "us", 159 | flag: { 160 | image: "https://crowdin.com/images/flags/en.png", 161 | emoji: "🇺🇸", 162 | primaryColor: { hex: "#0A3161", rgb: [10, 49, 97], cmyk: [90, 49, 0, 62], base10: 668001 }, 163 | flagColors: [ 164 | { hex: "#B31942", rgb: [179, 25, 66], cmyk: [0, 100, 66, 13], base10: 11737410 }, 165 | { hex: "#FFFFFF", rgb: [255, 255, 255], cmyk: [0, 0, 0, 0], base10: 16777215 }, 166 | { hex: "#0A3161", rgb: [10, 49, 97], cmyk: [100, 68, 0, 54], base10: 668001 } 167 | ] 168 | } 169 | }, 170 | { 171 | name: "English (upside down)", 172 | nativeName: "ɥsıןƃuƎ", 173 | ids: { 174 | locale: "en-UD", 175 | androidCode: "en-rUD", 176 | osxCode: "en-UD.lproj", 177 | osxLocale: "en_UD" 178 | }, 179 | direction: "ltr", 180 | country: "United States", 181 | countryCode: "us", 182 | flag: { 183 | image: "https://crowdin.com/images/flags/en-UD.png", 184 | emoji: "🇺🇸", 185 | primaryColor: { hex: "#0A3161", rgb: [10, 49, 97], cmyk: [90, 49, 0, 62], base10: 668001 }, 186 | flagColors: [ 187 | { hex: "#B31942", rgb: [179, 25, 66], cmyk: [0, 100, 66, 13], base10: 11737410 }, 188 | { hex: "#FFFFFF", rgb: [255, 255, 255], cmyk: [0, 0, 0, 0], base10: 16777215 }, 189 | { hex: "#0A3161", rgb: [10, 49, 97], cmyk: [100, 68, 0, 54], base10: 668001 } 190 | ] 191 | } 192 | }, 193 | { 194 | name: "English, Caribbean", 195 | nativeName: "English, Caribbean", 196 | ids: { 197 | locale: "en-CB", 198 | ISO_639_1: "en", 199 | ISO_639_2: "eng", 200 | ISO_639_3: "eng", 201 | androidCode: "en-rCB", 202 | osxCode: "en-CB.lproj", 203 | osxLocale: "en_CB", 204 | glottolog: "stan1293" 205 | }, 206 | direction: "ltr", 207 | country: "United States", 208 | countryCode: "us", 209 | flag: { 210 | image: "https://crowdin.com/images/flags/en-CB.png", 211 | emoji: "🇺🇸", 212 | primaryColor: { hex: "#0A3161", rgb: [10, 49, 97], cmyk: [90, 49, 0, 62], base10: 668001 }, 213 | flagColors: [ 214 | { hex: "#B31942", rgb: [179, 25, 66], cmyk: [0, 100, 66, 13], base10: 11737410 }, 215 | { hex: "#FFFFFF", rgb: [255, 255, 255], cmyk: [0, 0, 0, 0], base10: 16777215 }, 216 | { hex: "#0A3161", rgb: [10, 49, 97], cmyk: [100, 68, 0, 54], base10: 668001 } 217 | ] 218 | }, 219 | region: "Caribbean", 220 | regionCode: "cb" 221 | }, 222 | { 223 | name: "English, United States", 224 | nativeName: "English, United States", 225 | ids: { 226 | locale: "en-US", 227 | ISO_639_1: "en", 228 | ISO_639_2: "eng", 229 | ISO_639_3: "eng", 230 | androidCode: "en-rUS", 231 | osxCode: "en-US.lproj", 232 | osxLocale: "en_US", 233 | glottolog: "stan1293" 234 | }, 235 | direction: "ltr", 236 | country: "United States", 237 | countryCode: "us", 238 | flag: { 239 | image: "https://crowdin.com/images/flags/en-US.png", 240 | emoji: "🇺🇸", 241 | primaryColor: { hex: "#0A3161", rgb: [10, 49, 97], cmyk: [90, 49, 0, 62], base10: 668001 }, 242 | flagColors: [ 243 | { hex: "#B31942", rgb: [179, 25, 66], cmyk: [0, 100, 66, 13], base10: 11737410 }, 244 | { hex: "#FFFFFF", rgb: [255, 255, 255], cmyk: [0, 0, 0, 0], base10: 16777215 }, 245 | { hex: "#0A3161", rgb: [10, 49, 97], cmyk: [100, 68, 0, 54], base10: 668001 } 246 | ] 247 | } 248 | }, 249 | { 250 | name: "Hawaiian", 251 | nativeName: "Ōlelo Hawaiʻi", 252 | ids: { 253 | locale: "haw-US", 254 | ISO_639_2: "haw", 255 | ISO_639_3: "haw", 256 | androidCode: "haw-rUS", 257 | osxCode: "haw.lproj", 258 | osxLocale: "haw", 259 | glottolog: "hawa1245" 260 | }, 261 | direction: "ltr", 262 | country: "United States", 263 | countryCode: "us", 264 | flag: { 265 | image: "https://crowdin.com/images/flags/haw.png", 266 | primaryColor: { hex: "#00247D", rgb: [0, 36, 125], cmyk: [100, 71, 0, 51], base10: 9341 }, 267 | flagColors: [ 268 | { hex: "#012169", rgb: [1, 33, 105], cmyk: [99, 69, 0, 59], base10: 74089 }, 269 | { hex: "#FFFFFF", rgb: [255, 255, 255], cmyk: [0, 0, 0, 0], base10: 16777215 }, 270 | { hex: "#C8102E", rgb: [200, 16, 46], cmyk: [0, 92, 77, 22], base10: 13111342 } 271 | ] 272 | }, 273 | region: "Hawaii", 274 | regionCode: "hi" 275 | }, 276 | { 277 | name: "Klingon", 278 | nativeName: " ", 279 | ids: { 280 | locale: "tlh-AA", 281 | ISO_639_2: "tlh", 282 | ISO_639_3: "tlh", 283 | androidCode: "tlh-rAA", 284 | osxCode: "tlh.lproj", 285 | osxLocale: "tlh", 286 | glottolog: "klin1234" 287 | }, 288 | direction: "ltr", 289 | country: "United States", 290 | countryCode: "us", 291 | flag: { 292 | image: "https://crowdin.com/images/flags/tlh-AA.png", 293 | emoji: "🇺🇸", 294 | primaryColor: { hex: "#008852", rgb: [0, 136, 82], cmyk: [100, 0, 40, 47], base10: 34898 }, 295 | flagColors: [ 296 | { hex: "#008852", rgb: [0, 136, 82], cmyk: [100, 0, 40, 47], base10: 34898 }, 297 | { hex: "#FFFFFF", rgb: [255, 255, 255], cmyk: [0, 0, 0, 0], base10: 16777215 } 298 | ] 299 | } 300 | }, 301 | { 302 | name: "Lojban", 303 | nativeName: "La .lojban.", 304 | ids: { 305 | locale: "jbo-EN", 306 | ISO_639_2: "jbo", 307 | ISO_639_3: "jbo", 308 | androidCode: "jbo-rEN", 309 | osxCode: "jbo.lproj", 310 | osxLocale: "jbo", 311 | glottolog: "lojb1234" 312 | }, 313 | direction: "ltr", 314 | country: "United States", 315 | countryCode: "us", 316 | flag: { 317 | image: "https://crowdin.com/images/flags/jbo.png", 318 | emoji: "🇺🇸", 319 | primaryColor: { hex: "#000063", rgb: [0, 0, 99], cmyk: [100, 100, 0, 61], base10: 99 }, 320 | flagColors: [ 321 | { hex: "#209E6C", rgb: [32, 158, 108], cmyk: [80, 0, 32, 38], base10: 2137708 }, 322 | { hex: "#960016", rgb: [150, 0, 22], cmyk: [0, 100, 85, 41], base10: 9830422 }, 323 | { hex: "#000063", rgb: [0, 0, 99], cmyk: [100, 100, 0, 61], base10: 99 } 324 | ] 325 | } 326 | }, 327 | { 328 | name: "LOLCAT", 329 | nativeName: "LOLCAT", 330 | ids: { 331 | locale: "lol-US", 332 | androidCode: "lol-rUS", 333 | osxCode: "lol.lproj", 334 | osxLocale: "lol" 335 | }, 336 | direction: "ltr", 337 | country: "United States", 338 | countryCode: "us", 339 | flag: { 340 | image: "https://crowdin.com/images/flags/lol.png", 341 | primaryColor: { hex: "#B8D251", rgb: [184, 210, 81], cmyk: [12, 0, 61, 18], base10: 12112465 }, 342 | flagColors: [ 343 | { hex: "#B8D251", rgb: [184, 210, 81], cmyk: [12, 0, 61, 18], base10: 12112465 }, 344 | { hex: "#509C89", rgb: [80, 156, 137], cmyk: [49, 0, 12, 39], base10: 5282953 }, 345 | { hex: "#5CB59F", rgb: [92, 181, 159], cmyk: [49, 0, 12, 29], base10: 6075807 }, 346 | { hex: "#19909B", rgb: [25, 144, 155], cmyk: [84, 7, 0, 39], base10: 1675419 } 347 | ] 348 | } 349 | }, 350 | { 351 | name: "Spanish, United States", 352 | nativeName: "Español estadounidense", 353 | ids: { 354 | locale: "es-US", 355 | ISO_639_1: "es", 356 | ISO_639_2: "spa", 357 | ISO_639_3: "spa", 358 | androidCode: "es-rUS", 359 | osxCode: "es-US.lproj", 360 | osxLocale: "es_US", 361 | glottolog: "stan1288" 362 | }, 363 | direction: "ltr", 364 | country: "United States", 365 | countryCode: "us", 366 | flag: { 367 | image: "https://crowdin.com/images/flags/es-US.png", 368 | emoji: "🇺🇸", 369 | primaryColor: { hex: "#0A3161", rgb: [10, 49, 97], cmyk: [90, 49, 0, 62], base10: 668001 }, 370 | flagColors: [ 371 | { hex: "#B31942", rgb: [179, 25, 66], cmyk: [0, 100, 66, 13], base10: 11737410 }, 372 | { hex: "#FFFFFF", rgb: [255, 255, 255], cmyk: [0, 0, 0, 0], base10: 16777215 }, 373 | { hex: "#0A3161", rgb: [10, 49, 97], cmyk: [100, 68, 0, 54], base10: 668001 } 374 | ] 375 | } 376 | } 377 | ]); 378 | }); 379 | }); 380 | --------------------------------------------------------------------------------