JSPM

eldr

1.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q29848F
  • License Apache-2.0

Fast and accurate natural language detector based on eld by Nito TM.

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

npm version License: Apache-2.0

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 eldr

or

yarn add eldr

Quick 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()); // true

Different 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 languages

Result 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 for iso639_1 (backwards compatibility)
  • isReliable(): Returns true if the detection is considered reliable
  • getScores(): 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 text
  • cleanText(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 code
  • languageName: string - Full language name
  • language: string - Alias for iso639_1 (backwards compatibility)

Methods

  • isReliable(): boolean - Returns true if the detection is considered reliable
  • getScores(): 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 build

Testing

npm test

Linting

npm run lint

License

Licensed under the Apache License 2.0. See LICENSE for details.

Credits

  • 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