Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cld3-asm

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cld3-asm

WebAssembly based Javascript bindings for google compact language detector 3

  • 3.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8.5K
increased by18.06%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status Build status codecov npm node

cld3-asm

cld3-asm is isomorphic javascript binding to google's compact language detector v3 based on WebAssembly cld3 binary. This module aims to provide thin, lightweight interface to cld3 without requiring native modules.

Install

npm install cld3-asm

Usage

Loading module asynchronously

cld3-asm relies on wasm binary of cld3, which need to be initialized first.

import { loadModule } from 'cld3-asm';

const cldFactory = await loadModule();

loadModule loads wasm binary, initialize it, and returns factory function to create instance of cld3 language identifier.

loadModule({ timeout?: number }): Promise<CldFactory>

It allows to specify timeout to wait until wasm binary compliation & load.

Creating language identifier

create(minBytes?: number, maxBytes?: number): LanguageIdentifier

LanguageIdentifier exposes minimal interfaces to cld3's NNetLanguageIdentifier.

  • findLanguage(text: string): Readonly<LanguageResult> : Finds the most likely language for the given text.
  • findMostFrequentLanguages(text: string, numLangs: number): Array<Readonly<LanguageResult>> : Splits the input text into spans based on the script, predicts a language for each span, and returns a vector storing the top num_langs most frequent languages
  • dispose(): void : Destroy current instance of language identifier. It is important to note created instance will not be destroyed automatically.

There are simple examples for each environments. In each example directory do npm install && npm start.

Building / Testing

Few npm scripts are supported for build / test code.

  • build: Transpiles code to ES5 commonjs to dist.
  • test: Run cld / cld3-asm test both. Does not require build before execute test.
  • test:cld: Run integration test for actual cld3 wasm binary, using cld's test case.
  • test:cld3-asm: Run unit test against cld3-asm interface
  • lint: Run lint over all codebases
  • lint:staged: Run lint only for staged changes. This'll be executed automatically with precommit hook.
  • commit: Commit wizard to write commit message

License

Keywords

FAQs

Package last updated on 19 Jul 2019

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc