This package is no longer maintained.
Please use iso-639-1 instead. See: https://www.npmjs.com/package/iso-639-1
Original README below:
A clean, typed, and reliable dataset of ISO 639-1 and 639-2 language codes — complete with English names, native names, and writing scripts. Perfect for internationalized applications.
- 📚 Comprehensive dataset of world languages
- 🔤 ISO 639-1 (2-letter) and ISO 639-2 (3-letter) codes
- 🌍 English and native language names
- 📝 Writing script information (ISO 15924 codes)
- 📦 Zero runtime dependencies
- 🎯 Fully typed with TypeScript
- ✅ 100% test coverage
- 🌲 Tree-shakable
npm install language-codes-collection
import {
languages,
languageMap,
getLanguageByCode,
getNativeName,
getScript,
isValidLanguageCode,
searchLanguageByName,
} from 'language-codes-collection';
// Get all languages
console.log(languages);
// [
// {
// code6391: 'en',
// code6392: 'eng',
// englishName: 'English',
// nativeName: 'English',
// script: 'Latn'
// },
// ...
// ]
// Get language by code (ISO 639-1 or ISO 639-2)
const english = getLanguageByCode('en');
console.log(english);
// {
// code6391: 'en',
// code6392: 'eng',
// englishName: 'English',
// nativeName: 'English',
// script: 'Latn'
// }
// Get native name
console.log(getNativeName('es')); // 'Español'
// Get script
console.log(getScript('ja')); // 'Jpan'
// Check if code is valid
console.log(isValidLanguageCode('en')); // true
console.log(isValidLanguageCode('invalid')); // false
// Search languages by name
const results = searchLanguageByName('Eng');
console.log(results);
// [
// {
// code6391: 'en',
// code6392: 'eng',
// englishName: 'English',
// nativeName: 'English',
// script: 'Latn'
// }
// ]
You can also access the raw language data directly:
import languages from 'language-codes-collection/languages.json';
-
languages: Readonly<Language[]>
- Array of all supported languages -
languageMap: Readonly<Record<ISO6391Code, Language>>
- Map of languages indexed by ISO 639-1 code
type ISO6391Code = string; // e.g., 'en'
type ISO6392Code = string; // e.g., 'eng'
type ScriptCode = string; // e.g., 'Latn', 'Cyrl', 'Arab'
interface Language {
code6391: ISO6391Code;
code6392: ISO6392Code;
englishName: string;
nativeName: string;
script?: ScriptCode;
}
Takes an ISO 639-1 or ISO 639-2 code (case-insensitive) and returns the corresponding language object or undefined if not found.
Takes an ISO 639-1 or ISO 639-2 code (case-insensitive) and returns the native name string or undefined.
Takes an ISO 639-1 or ISO 639-2 code (case-insensitive) and returns the script code string or undefined.
Takes an ISO 639-1 or ISO 639-2 code (case-insensitive) and returns true if it exists in the dataset, false otherwise.
Searches for languages by name (case-insensitive). Matches against both English and native names.
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.