Package Exports
- eldr
- eldr/lib/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (eldr) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
ELDR - Efficient Language Detector, Refactored
A fast and accurate natural language detector for TypeScript/JavaScript, refactored from Nito-ELD to provide better TypeScript support and avoid top-level await for easier bundling.
Features
- ๐ Fast: Optimized for performance with efficient n-gram processing
- ๐ฏ Accurate: High accuracy language detection across 60 supported languages
- ๐ฆ TypeScript: Full TypeScript support with exported type definitions
- ๐ง Flexible: Multiple size variants for different use cases
- ๐ Universal: Works in Node.js and browser environments
- ๐ฑ Lightweight: Choose from different package sizes based on your needs
Installation
npm install eldror
yarn add eldrQuick Start
import { eldr } from "eldr";
const result = eldr.detect("Hola, cรณmo te llamas?");
console.log(result.iso639_1); // "es"
console.log(result.languageName); // "Spanish"
console.log(result.isReliable()); // true
console.log(result.getScores()); // { es: 0.5289, et: 0.2093, ... }Usage
Basic Usage
import { eldr } from "eldr";
// Detect language
const detected = eldr.detect("Hello, how are you?");
console.log(detected.iso639_1); // "en"
console.log(detected.languageName); // "English"
console.log(detected.isReliable()); // trueDifferent Package Sizes
Choose the package size that fits your needs:
// Extra Small (fastest, least accurate)
import { extraSmall as eldr } from "eldr";
// Small
import { small as eldr } from "eldr";
// Medium (default - best balance)
import { medium as eldr } from "eldr";
// Large (most accurate, largest size)
import { large as eldr } from "eldr";Advanced Usage
import { eldr } from "eldr";
// Enable text cleaning (removes URLs, emails, etc.)
eldr.cleanText(true);
const result = eldr.detect(
"Check out https://example.com and email me at test@example.com"
);
// Get detailed information
console.log(result.getScores()); // Detailed scores for all languages
console.log(result.isReliable()); // Whether the detection is reliable
console.log(eldr.info()); // Package information and supported languagesResult Object
The detect() method returns a LanguageResult object with the following properties:
iso639_1: ISO 639-1 language code (e.g., "en", "es", "fr")languageName: Full language name (e.g., "English", "Spanish", "French")language: Alias foriso639_1(backwards compatibility)isReliable(): Returnstrueif the detection is considered reliablegetScores(): Returns detailed scores for all languages
Supported Languages
ELDR supports 60 languages with ISO 639-1 codes:
ISO 639-1 Codes:
'am', 'ar', 'az', 'be', 'bg', 'bn', 'ca', 'cs', 'da', 'de', 'el', 'en', 'es', 'et', 'eu', 'fa', 'fi', 'fr', 'gu', 'he', 'hi', 'hr', 'hu', 'hy', 'is', 'it', 'ja', 'ka', 'kn', 'ko', 'ku', 'lo', 'lt', 'lv', 'ml', 'mr', 'ms', 'nl', 'no', 'or', 'pa', 'pl', 'pt', 'ro', 'ru', 'sk', 'sl', 'sq', 'sr', 'sv', 'ta', 'te', 'th', 'tl', 'tr', 'uk', 'ur', 'vi', 'yo', 'zh'
Full Language Names: Amharic, Arabic, Azerbaijani (Latin), Belarusian, Bulgarian, Bengali, Catalan, Czech, Danish, German, Greek, English, Spanish, Estonian, Basque, Persian, Finnish, French, Gujarati, Hebrew, Hindi, Croatian, Hungarian, Armenian, Icelandic, Italian, Japanese, Georgian, Kannada, Korean, Kurdish (Arabic), Lao, Lithuanian, Latvian, Malayalam, Marathi, Malay (Latin), Dutch, Norwegian, Oriya, Punjabi, Polish, Portuguese, Romanian, Russian, Slovak, Slovene, Albanian, Serbian (Cyrillic), Swedish, Tamil, Telugu, Thai, Tagalog, Turkish, Ukrainian, Urdu, Vietnamese, Yoruba, Chinese
API Reference
ELDR Class
Methods
detect(text: string): LanguageResult- Detect the language of the given textcleanText(doClean: boolean): void- Enable/disable text cleaning (removes URLs, emails, etc.)info(): object- Get package information and supported languages
LanguageResult Class
Properties
iso639_1: string- ISO 639-1 language codelanguageName: string- Full language namelanguage: string- Alias for iso639_1 (backwards compatibility)
Methods
isReliable(): boolean- Returns true if the detection is considered reliablegetScores(): Record<string, number>- Returns detailed scores for all languages
Performance
ELDR is optimized for performance:
- Processes text in chunks to handle large inputs efficiently
- Uses optimized n-gram matching algorithms
- Provides different package sizes for different performance/accuracy trade-offs
- Text processing is limited to the first 1000 characters for optimal performance
Browser Support
ELDR works in all modern browsers that support:
- ES2021 features
- TypedArrays
- String methods (codePointAt, etc.)
Node.js Support
Requires Node.js 16.0.0 or higher.
Development
Building
npm run buildTesting
npm testLinting
npm run lintLicense
Licensed under the Apache License 2.0. See LICENSE for details.
Credits
- Original Author: Nito T.M. - Creator of the original ELD library
- Refactored by: Bernhard K. Weisshuhn - TypeScript refactoring and npm package
Related Projects
- ELD - Original Efficient Language Detector
- franc - Another language detection library
- language-detector - Alternative language detection library
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Changelog
v1.1.0
- Initial release with TypeScript support
- Refactored from original ELD library
- Added multiple package size variants
- Improved bundling compatibility