Install iso-639-1 via npm
masterInstall the package using npm to use the ISO-639-1 language code interface in your project.
npm install iso-639-1repository·master·Indexed 42 days ago
https://github.com/meikidd/iso-639-1A simple interface for working with ISO-639-1 language codes version 3.1.6. Provides methods to look up English names, native names, and codes, as well as validation and bulk retrieval of language objects.
Install the package using npm to use the ISO-639-1 language code interface in your project.
npm install iso-639-1To use the library in a browser, include the build file via a <script> tag. The library will be available under the global variable ISO6391.
<script type="text/javascript" src="./node_modules/iso-639-1/build/index.js"></script>
<script>
console.log(ISO6391.getName('en')); // 'English'
</script>In a Node.js environment using CommonJS, require the module to access the ISO6391 object.
const ISO6391 = require('iso-639-1');
console.log(ISO6391.getName('en')); // 'English'In an ES Module environment, use the import statement to access the ISO6391 object.
import ISO6391 from 'iso-639-1';
console.log(ISO6391.getName('en')); // 'English'Use getCode(name) to find a language code using either its English name or its native name. Use getAllCodes() to retrieve an array of all ISO-639-1 codes.
console.log(ISO6391.getCode('Chinese')); // 'zh'
console.log(ISO6391.getCode('中文')); // 'zh'
console.log(ISO6391.getAllCodes()); // ['aa','ab',...,'zu']Use getName(code) to retrieve the English name of a language, or getNativeName(code) to retrieve its native name. Use getAllNames() and getAllNativeNames() to get arrays of all available names.
console.log(ISO6391.getName('zh')); // 'Chinese'
console.log(ISO6391.getNativeName('zh')); // '中文'
console.log(ISO6391.getAllNames()); // ['Afar','Abkhaz', ... ,'Zulu']
console.log(ISO6391.getAllNativeNames()); // ['Afaraf','аҧсуа бызшәа', ... ,'isiZulu']Use validate(code) to check if a given string is a valid ISO-639-1 code. Returns true if valid, false otherwise.
console.log(ISO6391.validate('en')); // true
console.log(ISO6391.validate('xx')); // falseUse getLanguages(codes) to retrieve an array of language objects for a provided list of codes. Each object contains the code, name, and nativeName.
console.log(ISO6391.getLanguages(['en', 'zh']));
// [
// {code:'en', name:'English', nativeName:'English'},
// {code:'zh', name:'Chinese', nativeName:'中文'}
// ]Retrieve an array of language objects for a given list of ISO-639-1 codes. If a code is valid, it returns an object containing { code, name, nativeName }. If a code is invalid, it returns an object with empty strings for name and nativeName.
const ISO6391 = require('iso-639-1');
const languages = ISO6391.getLanguages(['en', 'fr', 'invalid']);
// Returns:
// [
// { code: 'en', name: 'English', nativeName: 'English' },
// { code: 'fr', name: 'French', nativeName: 'Français' },
// { code: 'invalid', name: '', nativeName: '' }
// ]Returns the English name of the language associated with the provided ISO-639-1 code. Returns an empty string if the code is invalid.
const ISO6391 = require('iso-639-1');
const name = ISO6391.getName('en'); // 'English'
const invalid = ISO6391.getName('xx'); // ''Checks if a given string is a valid ISO-639-1 code present in the dataset. Returns true if valid, otherwise false.
const ISO6391 = require('iso-639-1');
const isValid = ISO6391.validate('en'); // true
const isInvalid = ISO6391.validate('xyz'); // falseReturns a copy of the array containing all English language names available in the dataset.
const ISO6391 = require('iso-639-1');
const allNames = ISO6391.getAllNames();