npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cldr-language-country

v0.6.1

Published

A small utility to get CLDR, country code (cc) and language code (lc) data.

Downloads

175

Readme

cldr-language-country

Tiny util that maps 2-character language codes (lc) and country codes (cc) to CLDR locale data. Especially useful for generating search queries.

Install

npm i cldr-language-country

Usage

| function | parameters | returns | |------------------|----------------|----------------------------------------------------------------| | generateData | none | Data for all locales | | getLocales | none | Array of all locales (string) | | getCountries | none | Array of all country data, with name and code | | getLanguages | none | Array of all language data, with name, native, and code | | keyByCC | none | Object containing all data, keyed by country code | | keyByLC | none | Object containing all data, keyed by language code | | getByCC | cc(String) | Array of all data whose country.code matches cc. | | getByLC | lc(String) | Array of all data whose language.code matches lc. | | getByCountryName | name(string) | Array of all data whose country.name matches name. | | getByLanguage | name(String) | Array of all data whose language.name matches name. | | getByLocale | locale(String) | Array of all data whose locale matches the provided locale | | getByNativeName | name(String) | Array of all data whose language.name matches name. |

generateData()

import { generateData } from 'cldr-language-country';

const locales = generateData();

Result:

[
    {
        language: {
            code: 'en',
            name: 'English',
            native: 'English'
        },
        country: {
            code: 'us',
            name: 'United States'
        },
        locale: 'en-US'
    } 
]

getLocales()

import { getLocales } from 'cldr-language-country';

const locales = getLocales();

Result:

[
  'ps-AF', 'fa-AF', 'uz-AF', 'sv-AX', 'sq-AL', 'en-AL', 'ar-DZ',
  'fr-DZ', 'en-AS', 'ca-AD', 'en-AD', 'ln-AO', 'pt-AO', 'en-AI',
  ...continued
]

getCountries()

import { getCountries } from 'cldr-language-country';

const countries = countries();

Result:

[
  { code: 'AF', name: 'Afghanistan' },
  { code: 'AX', name: 'Åland Islands' },
  { code: 'AL', name: 'Albania' },
  { code: 'DZ', name: 'Algeria' },
  { code: 'AS', name: 'American Samoa' },
  ...continued
]

getLanguages()

import { getLanguages } from 'cldr-language-country';

const languages = getLanguages();

Result:

[
  { code: 'aa', name: 'Afar', native: 'Afar' },
  { code: 'ab', name: 'Abkhazian', native: 'Аҧсуа' },
  { code: 'af', name: 'Afrikaans', native: 'Afrikaans' },
  { code: 'ak', name: 'Akan', native: 'Akana' },
  { code: 'am', name: 'Amharic', native: 'አማርኛ' },
  ...continued
]

keyByCC()

import { keyByCC } from 'cldr-language-country';

const locales = keyByCC();

Result:

{
    'CA': [
        {
            language: {
                code: 'en',
                name: 'English',
                native: 'English'
            },
            country: {
                code: 'CA',
                name: 'Canada'
            },
            locale: 'en-CA'
        },
        {
            language: {
                code: 'fr',
                name: 'French',
                native: 'Français'
            },
            country: {
                code: 'CA',
                name: 'Canada'
            },
            locale: 'fr-CA' 
        }
    ]
}

keyByLC()

import { keyByLC } from 'cldr-language-country';

const locales = keyByLC();

Result:

{
    'en': [
        {
            language: {
                code: 'en',
                name: 'English',
                native: 'English'
            },
            country: {
                code: 'AE',
                name: 'United Arab Emirates'
            },
            locale: 'en-AE'
        },
        {
            language: {
                code: 'en',
                name: 'English',
                native: 'English'
            },
            country: {
                code: 'AG',
                name: 'Antigua and Barbuda'
            },
            locale: 'en-AG'
        },
        ...continued
    ]
}

getByCC(cc)

import { getByCC } from 'cldr-language-country';

const locales = getByCC('US');

Result:

[
  {
    language: { code: 'en', name: 'English', native: 'English' },
    country: { code: 'US', name: 'United States' },
    locale: 'en-US'
  },
  {
    language: { code: 'es', name: 'Spanish', native: 'Español' },
    country: { code: 'US', name: 'United States' },
    locale: 'es-US'
  }
]

getByLC(lc)

import { getByLC } from 'cldr-language-country';

const locales = getByLC('zh');

Result:

[
  {
    language: { code: 'zh', name: 'Chinese', native: '中文' },
    country: { code: 'CN', name: 'China' },
    locale: 'zh-CN'
  },
  {
    language: { code: 'zh', name: 'Chinese', native: '中文' },
    country: { code: 'CN', name: 'China' },
    locale: 'zh-CN'
  },
  ...continued
]

getByCountryName(name)

import { getByCountryName } from 'cldr-language-country';

const locales = getByCountryName('Japan');

Result:

[
  {
    language: { code: 'en', name: 'English', native: 'English' },
    country: { code: 'JP', name: 'Japan' },
    locale: 'en-JP'
  },
  {
    language: { code: 'ja', name: 'Japanese', native: '日本語' },
    country: { code: 'JP', name: 'Japan' },
    locale: 'ja-JP'
  }
]

getByLanguageName(name)

import { getByLanguageName } from 'cldr-language-country';

const locales = getByLanguageName('Tagalog');

Result:

[
  {
    language: { code: 'tl', name: 'Tagalog / Filipino', native: 'Tagalog' },
    country: { code: 'PH', name: 'Philippines' },
    locale: 'tl-PH'
  }
]

getByLocale(locale)

import { getByLocale } from 'cldr-language-country';

const locales = getByLocale('km-KH');

Result:

[
  {
    language: { code: 'km', name: 'Khmer', native: 'ភាសាខ្មែរ' },
    country: { code: 'KH', name: 'Cambodia' },
    locale: 'km-KH'
  }
]

getByNativeName(name)

import { getByNativeName } from 'cldr-language-country';

const locales = getByNativeName('فارسی');

Result:

[
  {
    language: { code: 'fa', name: 'Persian', native: 'فارسی', rtl: 1 },
    country: { code: 'AF', name: 'Afghanistan' },
    locale: 'fa-AF'
  },
  {
    language: { code: 'fa', name: 'Persian', native: 'فارسی', rtl: 1 },
    country: { code: 'IR', name: 'Iran, Islamic Republic of' },
    locale: 'fa-IR'
  }
]