bcp-47-normalize
    TypeScript icon, indicating that this package has built-in type declarations

    2.0.1 • Public • Published

    bcp-47-normalize

    Build Coverage Downloads Size

    Normalize, canonicalize, and format BCP 47 tags.

    Install

    This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required.

    npm:

    npm install bcp-47-normalize

    Use

    import {bcp47Normalize} from 'bcp-47-normalize'
    
    var tags = [
      'de-de-1901',
      'en-gb',
      'en-us',
      'en-bu',
      'hy-arevmda',
      'nld-nl',
      'no-nyn',
      'pt-br',
      'pt-pt',
      'zh-hans-cn'
    ]
    
    tags.forEach(function (tag) {
      console.log('%s -> %s', tag, bcp47Normalize(tag))
    })

    Yields:

    de-de-1901 -> de-1901
    en-gb -> en-GB
    en-us -> en
    en-bu -> en-MM
    hy-arevmda -> hyw
    nld-nl -> nl
    no-nyn -> nn
    pt-br -> pt
    pt-pt -> pt-PT
    zh-hans-cn -> zh
    

    API

    This package exports the following identifiers: bcp47Normalize. There is no default export.

    bcp47Normalize(tag[, options])

    Normalize the given BCP 47 tag according to Unicode CLDR suggestions.

    options.forgiving

    Passed to bcp-47 as options.forgiving.

    options.warning

    Passed to bcp-47 as options.warning.

    One additional warning is given:

    code reason
    7 Deprecated region CURRENT, expected one of SUGGESTIONS

    This warning is only given if the region cannot be automatically fixed (when regions split into multiple regions).

    Returns

    string — Normal, canonical, and pretty BCP 47 tag.

    Related

    License

    MIT © Titus Wormer

    Install

    npm i bcp-47-normalize

    DownloadsWeekly Downloads

    1,710

    Version

    2.0.1

    License

    MIT

    Unpacked Size

    148 kB

    Total Files

    15

    Last publish

    Collaborators

    • wooorm