The `bidi-js` package provides a pure JavaScript implementation of the Unicode Bidirectional Algorithm (UAX #9) version 13.0.0. It aims for correctness, small bundle size, and performance, having passed all Unicode conformance tests. Currently at version 1.0.3, it offers a stable API for calculating embedding levels, reordering segments, and identifying mirrored characters in mixed-direction text. It ships as ES5 compatible and has no external dependencies, making it suitable for both browser and Node.js environments. The library differentiates itself by providing a factory function for module initialization, allowing for flexible deployment, such as within web workers, and ensuring a self-contained module without closure dependencies.
npm install bidi-jsVerified import paths — ran on the pinned version, not inferred.
Demonstrates installation, factory initialization, and usage of core methods like `getEmbeddingLevels`, `getReorderSegments`, and `getMirroredCharactersMap` with a mixed-direction string to illustrate the Unicode Bidirectional Algorithm.
Always initialize the library by calling the default imported function: `const bidi = bidiFactory()`.
Iterate through the `flips` array using `forEach` and apply the reversal for each range from `start` to `end` inclusive, in the given order.
When processing multi-line or segmented text, call `bidi.getReorderSegments(text, embeddingLevels, lineStart, lineEnd)` for each segment.
Periodically check the `bidi-js` repository for updates that might align with newer Unicode Bidi Algorithm versions if strict adherence to the latest spec is critical for your application.
Ensure you call the factory function to get the bidi object: `const bidiFactory = require('bidi-js'); const bidi = bidiFactory();` or `import bidiFactory from 'bidi-js'; const bidi = bidiFactory();`Verify that `bidiFactory()` has been correctly invoked and its return value assigned to the `bidi` variable: `const bidi = bidiFactory()`.
No dependency data recorded yet.