Security News
The Risks of Misguided Research in Supply Chain Security
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
intl-segmenter-polyfill
Advanced tools
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.
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.
npm install --save intl-segmenter-polyfill
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.
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')
})()
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.
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)
})()
<script src="bundled.js"></script>
<script>
IntlSegmenterPolyfillBundled.createIntlSegmenterPolyfill().then(function (
Segmenter,
) {
const segmenter = new Segmenter('en', { granularity: 'word' })
const segments = segmenter.segment('foo bar baz')
console.log(segments)
})
</script>
@rollup/plugin-wasm and webpack wasm-loader can be used with createIntlSegmenterPolyfillFromFactory
import commonjs from '@rollup/plugin-commonjs'
import { wasm } from '@rollup/plugin-wasm'
export default {
input: 'index.js',
output: {
file: 'out.js',
format: 'iife',
},
plugins: [commonjs(), wasm()],
}
import { createIntlSegmenterPolyfillFromFactory } from 'intl-segmenter-polyfill'
import break_iterator from 'intl-segmenter-polyfill/break_iterator.wasm'
;(async function () {
const Segmenter = await createIntlSegmenterPolyfillFromFactory(break_iterator)
const segmenter = new Segmenter('en', { granularity: 'word' })
const segments = segmenter.segment('foo bar baz')
})()
const {createIntlSegmenterPolyfill} = require('intl-segmenter-polyfill')
const fs = require('fs')
const wasmBuffer = fs.readFileSync('node_modules/intl-segmenter-polyfill/break_iterator.wasm')
let wasmBinary = new Uint8Array(wasmBuffer)
;(async () => {
const Segmenter = await createIntlSegmenterPolyfill(wasmBinary);
const segmenter = new Segmenter("en", { granularity: 'word' });
const segments = segmenter.segment("foo bar baz");
)()
Besides Chrome, Firefox and Safari with reasonable versions, it polyfills TextEncoder/TextDecoder to support Edge 18 (non-chromium).
Running ./build.sh
while having docker installed should output break_iterator.wasm
ready to be used in Node, browsers or Wasmer without a lot of special treatment (see examples above or examples/
).
FAQs
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.
The npm package intl-segmenter-polyfill receives a total of 3,686 weekly downloads. As such, intl-segmenter-polyfill popularity was classified as popular.
We found that intl-segmenter-polyfill demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.