language-codes-collection
Version:
[DEPRECATED] A clean, typed, and reliable dataset of ISO 639-1 and 639-2 language codes — complete with English names, native names, and writing scripts.
169 lines (122 loc) • 4.3 kB
Markdown
**This package is no longer maintained.**
Please use iso-639-1 instead.
See: https://www.npmjs.com/package/iso-639-1
---
Original README below:
---
[](https://www.npmjs.com/package/language-codes-collection)
[](https://opensource.org/licenses/MIT)
[
[](https://www.typescriptlang.org/)
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
## Installation
```bash
npm install language-codes-collection
```
## Usage
### Basic Usage
```typescript
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:
```typescript
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
```typescript
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.
## 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](LICENSE) file for details.