0.1.7 • Published 4 months ago

intl-segmenter-polyfill-rs v0.1.7

Weekly downloads
-
License
MIT OR Apache-2.0
Repository
github
Last release
4 months ago

Intl-Segmenter-Polyfill-rs

About

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

See the bugzilla issue here.

As firefox 122 will support the API, this project will be archived in a predictable future.

Packages are available at:

Usage

Install wasm-pack

cargo install wasm-pack

Install binaryen

Use your package manager to install binaryen.

Install icu4x-datagen

cargo install icu_datagen

Generate the data

bash icu-datagen.sh

Build

bash build.sh

Use it in your project

import * as IntlSegmeterPolyfill from "intl-segmenter-polyfill-rs";
// Browsers like firefox
if (Intl.Segmenter === undefined) {
    Intl.Segmenter = IntlSegmeterPolyfill.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!'
}

Use it directly in the browser

<!-- Modify your src according to your need -->
<script type="module" src="/node_modules/intl-segmenter-polyfill-rs-web/intl_segmenter_polyfill_rs.js"></script>

License

Licensed under either of

at your option.

0.1.7

4 months ago

0.1.6

9 months ago

0.1.5

9 months ago

0.1.4

9 months ago

0.1.3

9 months ago

0.1.2

9 months ago

0.1.1

9 months ago

0.1.0

9 months ago