You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

langdetect-ts

Package Overview
Dependencies
Maintainers
0
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

langdetect-ts

Google langdetect for the web platform. Detects 55 languages of of the box. Minimum 1 sentence input for >90% accurracy.

1.0.0
latest
npmnpm
Version published
Weekly downloads
8
-11.11%
Maintainers
0
Weekly downloads
 
Created
Source

langdetect-ts

Google langdetect for the web platform. Detects 55 languages of of the box. Minimum 1 sentence input for >90% accurracy.

🔬 Fast and precise, platform-independent language detection wasn't availabl for Workers and Browsers - now it is. (langdetect only works server-side).

⚡ Simple and fast

📚 Usage

1. Install langdetect-ts:

npm/yarn/bun install langdetect-ts

2. Use it

import { detectLanguage, type LangProfile } from "langdetect-ts";
import allLanguages from "langdetect-ts/profiles/all.json";

// de out of 55 candidates
const detectDe = detectLanguage("Hallo, Welt, wie geht es Dir?", allLanguages)
console.log('Should be de:', detectDe)

// en out of 55 candidates
const detectEn = detectLanguage("Hello world! How are you?", allLanguages)
console.log('Should be en:', detectEn)

3. Optimized usage

Minimizing the ensemble of languages results in significantly faster results (60x faster for 2 language candidates instead of 55 candidates, 2ms per detection instead of 100ms). It also leads to significantly smaller bundle sizes. Detecting languages using n-grams, as it happens in this library, requires datasets that reflect a languages patterns alongside their frequency probabilities. 55 profiles make up 1 MiB gzipped, while 2 languages only account for 52 KiB gzipped.

import { detectLanguage, type LangProfile } from "langdetect-ts";
import de from "langdetect-ts/profiles/de.json";
import en from "langdetect-ts/profiles/en.json";

// de out of 55 candidates
const detectDe = detectLanguage("Hallo, Welt, wie geht es Dir?", [de, en])
console.log('Should be de:', detectDe)

// en out of 55 candidates
const detectEn = detectLanguage("Hello world! How are you?", [de, en])
console.log('Should be en:', detectEn)

Keywords

language

FAQs

Package last updated on 03 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.