-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathicu4x_bidi_example.mjs
36 lines (30 loc) · 965 Bytes
/
icu4x_bidi_example.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { ICU4XDataProvider } from "./lib/ICU4XDataProvider.js";
import { ICU4XBidi } from "./lib/ICU4XBidi.js";
import { default as wasm } from "./lib/diplomat-wasm.mjs";
const SAMPLE_TEXT_ARRAY = [
"a",
"b",
"(",
"c",
")",
];
const SAMPLE_TEXT = SAMPLE_TEXT_ARRAY.join('');
async function main() {
const provider = new ICU4XDataProvider(wasm.skiawasm_get_provider(), true, []);
const bidi = ICU4XBidi.create(provider);
const bidiInfo = bidi.for_text(SAMPLE_TEXT, 1);
const paragraph = bidiInfo.paragraph_at(0);
const reordered = paragraph.reorder_line(paragraph.range_start(), paragraph.range_end());
// Print each character separately on its own line.
console.log("Input:");
printChars(SAMPLE_TEXT);
console.log("");
console.log("Reordered:");
printChars(reordered);
}
function printChars(text) {
for (let i = 0; i < text.length; i++) {
console.log('>>', text[i]);
}
}
main();