Have ideas to improve npm?Join in the discussion! »

@ovl/iso-639-1TypeScript icon, indicating that this package has built-in type declarations

3.0.4 • Public • Published

@ovl/iso-639-1


⚠️ This is a fork of the original iso-639-1 package.

I needed an untranspiled version without static class properties. If you do need transpiling out of the box or want to use the package directly in the browser, use the original package.


NPM Version Build Status

Simple interface for ISO-639-1 language codes

Installation

npm install @ovl/iso-639-1

Usage

Node.js

const ISO6391 = require('@ovl/iso-639-1')

const lang = new ISO6391()

console.log(lang.getName('en')) // 'English'

Browsers

Import

import ISO6391 from '@ovl/iso-639-1'

const lang = new ISO6391()

console.log(lang.getName('en')) // 'English'

Methods

getName(code)

  • @param code {string}
  • @return {string}

Lookup language english name by code

getAllNames()

  • @return {array}

Get array of all language english names

getNativeName(code)

  • @param code {string}
  • @return {string}

Lookup language native name by code

getAllNativeNames()

  • @return {array}

Get array of all language native names

getCode(name)

  • @param name {string}
  • @return {string}

Lookup code by english name or native name

getAllCodes()

  • @return {array}

Get array of all codes

validate(code)

  • @param code {string}
  • @return {boolean}

Check whether the given code is in the list of ISO-639-1

getLanguages(codes)

  • @param codes {array}
  • @return {array}

Get the array of the language objects by the given codes

Usage

const ISO6391 = require('@ovl/iso-639-1')

console.log(ISO6391.getName('zh')) // 'Chinese'
console.log(ISO6391.getNativeName('zh')) // '中文'

console.log(ISO6391.getAllNames()) // ['Afar','Abkhaz', ... ,'Zulu']
console.log(ISO6391.getAllNativeNames()) //['Afaraf','аҧсуа бызшәа', ... ,'isiZulu' ]

console.log(ISO6391.getCode('Chinese')) // 'zh'
console.log(ISO6391.getCode('中文')) // 'zh'

console.log(ISO6391.getAllCodes()) //['aa','ab',...,'zu']

console.log(ISO6391.validate('en')) // true
console.log(ISO6391.validate('xx')) // false

console.log(ISO6391.getLanguages(['en', 'zh']))
// [{code:'en',name:'English',nativeName:'English'},{code:'zh',name:'Chinese',nativeName:'中文'}]

Install

npm i @ovl/iso-639-1

DownloadsWeekly Downloads

1

Version

3.0.4

License

MIT

Unpacked Size

32.2 kB

Total Files

5

Last publish

Collaborators

  • avatar