language-codes-collection
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

⚠️ DEPRECATED

This package is no longer maintained.

Please use iso-639-1 instead. See: https://www.npmjs.com/package/iso-639-1


Original README below:


language-codes-collection

npm version License: MIT

[ TypeScript

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.

Features

  • 📚 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

Installation

npm install language-codes-collection

Usage

Basic Usage

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'
//   }
// ]

Direct JSON Access

You can also access the raw language data directly:

import languages from 'language-codes-collection/languages.json';

API Reference

Data Exports

  • languages: Readonly<Language[]> - Array of all supported languages
  • languageMap: Readonly<Record<ISO6391Code, Language>> - Map of languages indexed by ISO 639-1 code

Types

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;
}

Functions

getLanguageByCode(code: string): Language | undefined

Takes an ISO 639-1 or ISO 639-2 code (case-insensitive) and returns the corresponding language object or undefined if not found.

getNativeName(code: string): string | undefined

Takes an ISO 639-1 or ISO 639-2 code (case-insensitive) and returns the native name string or undefined.

getScript(code: string): ScriptCode | undefined

Takes an ISO 639-1 or ISO 639-2 code (case-insensitive) and returns the script code string or undefined.

isValidLanguageCode(code: string): boolean

Takes an ISO 639-1 or ISO 639-2 code (case-insensitive) and returns true if it exists in the dataset, false otherwise.

searchLanguageByName(query: string): Language[]

Searches for languages by name (case-insensitive). Matches against both English and native names.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Package Sidebar

Install

npm i language-codes-collection

Weekly Downloads

13

Version

1.0.2

License

MIT

Unpacked Size

33.5 kB

Total Files

10

Last publish

Collaborators

  • zenluv