intl-segmenter-polyfill

This repo builds .wasm module using icu4c for breaking text into words, so that we can polyfill [Intl Segmenter Proposal](https://github.com/tc39/proposal-intl-segmenter) with full compatibility, even on browsers that do not expose v8BreakIterator api.

ISC 18 个版本
安装
npm install intl-segmenter-polyfill
yarn add intl-segmenter-polyfill
pnpm add intl-segmenter-polyfill
bun add intl-segmenter-polyfill
README

Intl Segmenter Polyfill

npm version Build WASM Test

Provides .wasm module built with icu4c for breaking text into words, so that we can polyfill Intl Segmenter Proposal with full compatibility, even on browsers that do not expose v8BreakIterator api.

By default it bundles only Thai language dictionary. Modify filters.json if you need to support other exotic languages.

Usage

npm install --save intl-segmenter-polyfill

Web – fetch

This is the most efficient way as you can lazily load the wasm module only when you need it and use instantiateStreaming for the best performance. Serve break_iterator.wasm as a static asset with application/wasm content-type and you are good to go.

index.js

import { createIntlSegmenterPolyfill } from 'intl-segmenter-polyfill'
;(async function () {
  const Segmenter = await createIntlSegmenterPolyfill(
    fetch('/path/to/break_iterator.wasm'),
  )

  const segmenter = new Segmenter('en', { granularity: 'word' })
  const segments = segmenter.segment('foo bar baz')
})()

Web – bundle with base64 encoded module

This is the simplest way to use the polyfill, at the cost of base64 encoded module – it's ~33% bigger and cannot be loaded on demand.

index.js

import { createIntlSegmenterPolyfill } from 'intl-segmenter-polyfill/bundled'
;(async function () {
  const Segmenter = await createIntlSegmenterPolyfill()
  const segmenter = new Segmenter('en', { granularity: 'word' })
  const segments = segmenter.segment('foo bar baz')
  console.log(segments)
})()

OR using plain old

版本列表
0.4.4 2021-08-10
0.4.3 2020-09-07
0.4.2 2020-08-03
0.4.1 2020-06-30
0.4.0 2020-06-14
0.3.4 2020-06-14
0.3.3 2020-06-14
0.2.8 2020-06-14
0.2.7 2020-06-14
0.2.6 2020-06-14
0.2.5 2020-06-13
0.2.4 2020-06-12
0.2.3 2020-06-12
0.2.2 2020-06-12
0.2.1 2020-06-12
0.2.0 2020-06-12
0.1.1 2020-06-12
0.1.0 2020-06-12