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

intl-segmenter-polyfill-rs

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

intl-segmenter-polyfill-rs

A polyfill for Intl.Segmenter

  • 0.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.6K
increased by133.18%
Maintainers
1
Weekly downloads
 
Created
Source

Intl-Segmenter-Polyfill-rs

About

This project polyfills the Intl.Segmenter API for browsers that do not support it.

See the bugzilla issue here.

Usage

Install wasm-pack

cargo install wasm-pack

Install icu4x-datagen

cargo install icu_datagen

Generate the data

sh icu-datagen.sh

Build with wasm-pack build

wasm-pack build --target nodejs --release

Run the following commands to standardize the package.json

sh before-publish.sh

Use it in your project

// Browsers like firefox
import init, { Segmenter } from "intl-segmenter-polyfill-rs";
if (Intl.Segmenter === undefined) {
    // If you don't call init, the wasm won't be load.
    await init().then(
        () => {
            Intl.Segmenter = Segmenter;
            const segmenterFr = new Intl.Segmenter('fr', { granularity: 'sentence' });
            const string1 = 'Hello World. Xin chào thế giới!';
    
            const iterator1 = segmenterFr.segment(string1)[Symbol.iterator]();
    
            console.log(iterator1.next().value.segment);
            // Expected output: 'Hello World. '
    
            console.log(iterator1.next().value.segment);
            // Expected output: 'Xin chào thế giới!'
        }
    );
}

License

Licensed under either of

at your option.

FAQs

Package last updated on 02 Aug 2023

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