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

@trenskow/language

v1.4.3

Published

A small library for getting a full language identifier (RFC 5646).

Downloads

33

Readme

@trenskow/language

A small library for getting a full language identifier (RFC 5646).

Usage

const { expand, collapse, match, all } = require('@trenskow/language');

expand(identifier)

Takes an RFC 5646 string and expands it to include language, script and country.

Example

expand('da'); // Returns 'da-Latn-DK'
expand('en-US'); // Returns 'en-Latn-US

collapse(identifier)

Takes a (partially) full RFC 5646 string and reduces it to its minimum value.

Example

collapse('da-Latn-DK'); // -> 'da'
collapse('da-DK') // -> 'da'
collapse('en-US') // -> 'en-US'

match(identifier, supported, [default])

Takes an HTTP Accept-Header value and returns the language to use based on an array of supported languages.

If default is omitted the first supported language becomes the default.

Example

match('da, en-US; en-GB;q=0.8, en', ['da', 'en-US'], 'en-US'); // -> 'da'
match('en-GB;q=0.8, en', ['en-US', 'da-DK']); // -> 'en-US'
match('de-DE', ['da-DK', 'en-US'], 'en-US'); // -> 'en-US'

all

Returns all posible identifier combinations.

Example

all /* -> [
    'af-Latn-NA', 'af-NA',      'af-Latn-ZA', 'af-ZA',      'am-Ethi-ET',
    'am-ET',      'am',         'ar-Arab-AE', 'ar-Arab-BH', 'ar-Arab-DJ',
    'ar-Arab-DZ', 'ar-Arab-EG', 'ar-Arab-EH', 'ar-Arab-ER', 'ar-Arab-IL',
    'ar-Arab-IQ', 'ar-Arab-JO', 'ar-Arab-KM', 'ar-Arab-KW', 'ar-Arab-LB',
    'ar-Arab-LY', 'ar-Arab-MA', 'ar-Arab-MR', 'ar-Arab-OM', 'ar-Arab-PS',
    'ar-Arab-QA', 'ar-Arab-SA', 'ar-Arab-SD', 'ar-Arab-SO', 'ar-Arab-SY',
    'ar-Arab-TD', 'ar-Arab-TN', 'ar-Arab-YE', 'ar-Syrc-IR', 'ar-Syrc-SS',
    'ay-Latn-BO', 'ay-BO',      'ay',         'az-Arab-AZ', 'az-Cyrl-AZ',
    'az-Latn-AZ', 'be-Cyrl-BY', 'be-BY',      'be',         'bg-Cyrl-BG',
    'bg-BG',      'bg',         'bi-Latn-VU', 'bi-VU',      'bi',
    'bn-Beng-BD', 'bn-BD',      'bn',         'bs-Cyrl-BA', 'bs-Latn-BA',
    'ca-Latn-AD', 'ca-AD',      'ca',         'ch-Latn-GU', 'ch-GU',
    'ch',         'cs-Latn-CZ', 'cs-CZ',      'cs',         'da-Latn-DK',
    'da-DK',      'da',         'de-Latn-AT', 'de-AT',      'de-Latn-BE',
    'de-BE',      'de-Latn-CH', 'de-CH',      'de-Latn-DE', 'de-DE',
    'de-Latn-LI', 'de-LI',      'de-Latn-LU', 'de-LU',      'dv-Thaa-MV',
    'dv-MV',      'dv',         'dz-Tibt-BT', 'dz-BT',      'dz',
    'el-Grek-CY', 'el-CY',      'el-Grek-GR', 'el-GR',      'en-Latn-AG',
    'en-Latn-AI', 'en-Latn-AS', 'en-Latn-AU', 'en-Latn-BB', 'en-Latn-BI',
    'en-Latn-BM', 'en-Latn-BS', 'en-Latn-BW', 'en-Latn-BZ', 'en-Latn-CA',
    ... 623 more items
  ]
*/

License

See LICENSE.