# ⚠️ 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-scripts-map

[![npm version](https://img.shields.io/npm/v/language-scripts-map.svg)](https://www.npmjs.com/package/language-scripts-map)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

[![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue.svg)](https://www.typescriptlang.org/)

A reliable mapping of ISO 639-1 language codes to their default writing scripts (using ISO 15924 codes like "Latn", "Cyrl", "Arab", "Deva"). This library is useful for localization engines, font selection tools, language-aware rendering, and multi-language form logic.

## Features

- 🎯 Accurate mapping of ISO 639-1 language codes to ISO 15924 script codes
- 📦 Zero runtime dependencies
- 🔒 TypeScript-first with strict type checking
- 🧪 Comprehensive test coverage
- 📚 Well-documented API
- 🌐 Support for both ESM and CommonJS
- 🎨 Includes script grouping (RTL/LTR)

## Installation

```bash
npm install language-scripts-map
```

## Usage

```typescript
import {
  getScriptByLanguageCode,
  getLanguagesByScript,
  isValidScript,
  isScriptMatch,
  languageScriptsMap,
  SCRIPT_GROUPS,
} from 'language-scripts-map';

// Get script for a language
getScriptByLanguageCode('en'); // returns 'Latn'
getScriptByLanguageCode('ar'); // returns 'Arab'
getScriptByLanguageCode('ru'); // returns 'Cyrl'

// Get languages using a script
getLanguagesByScript('Latn'); // returns ['en', 'fr', 'de', ...]
getLanguagesByScript('Arab'); // returns ['ar', 'fa', 'ur', ...]

// Check if a script is valid
isValidScript('Latn'); // returns true
isValidScript('invalid'); // returns false

// Check if a script matches a language
isScriptMatch('en', 'Latn'); // returns true
isScriptMatch('ar', 'Arab'); // returns true
isScriptMatch('en', 'Arab'); // returns false

// Access the raw mapping data
console.log(languageScriptsMap.en); // 'Latn'
console.log(languageScriptsMap.ar); // 'Arab'

// Access script groups
console.log(SCRIPT_GROUPS.RTL); // ['Arab', 'Hebr', ...]
console.log(SCRIPT_GROUPS.LTR); // ['Latn', 'Cyrl', ...]
```

## API Reference

### Types

```typescript
type ISO6391Code = string; // e.g., 'en', 'fr', 'de'
type ISO15924ScriptCode = string; // e.g., 'Latn', 'Cyrl', 'Arab', 'Deva'

interface LanguageScriptMapData {
  [languageCode: ISO6391Code]: ISO15924ScriptCode;
}

interface ScriptGroups {
  RTL: ISO15924ScriptCode[];
  LTR: ISO15924ScriptCode[];
}
```

### Functions

#### `getScriptByLanguageCode(languageCode: ISO6391Code | string): ISO15924ScriptCode | undefined`

Gets the default script code for a given language code.

- `languageCode`: ISO 639-1 language code (case-insensitive)
- Returns: The ISO 15924 script code for the language, or undefined if not found

#### `getLanguagesByScript(scriptCode: ISO15924ScriptCode | string): ISO6391Code[]`

Gets all language codes that use a given script.

- `scriptCode`: ISO 15924 script code (case-insensitive)
- Returns: Array of ISO 639-1 language codes that use the script

#### `isValidScript(scriptInput: string): boolean`

Checks if a given script code is valid (exists in the dataset).

- `scriptInput`: ISO 15924 script code to check (case-insensitive)
- Returns: true if the script code exists in the dataset

#### `isScriptMatch(languageCode: ISO6391Code | string, scriptInput: ISO15924ScriptCode | string): boolean`

Checks if a given script is the default script for a language.

- `languageCode`: ISO 639-1 language code (case-insensitive)
- `scriptInput`: ISO 15924 script code to check (case-insensitive)
- Returns: true if the script is the default for the language

### Constants

#### `languageScriptsMap: Readonly<LanguageScriptMapData>`

The primary immutable object/map where keys are ISO 639-1 language codes and values are their default ISO 15924 script codes.

#### `SCRIPT_GROUPS: Readonly<ScriptGroups>`

Groups of scripts by writing direction (RTL/LTR).

## Data Source

The language-to-script mapping data is sourced from the Common Locale Data Repository (CLDR) and official ISO standards. The data represents the default or most common script for each language.

## Contributing

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

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
