-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
35 lines (27 loc) · 778 Bytes
/
index.js
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
const wasm = require('./pkg/string_offsets_js.js');
class StringOffsets {
constructor(content) {
this.inner = wasm.WasmStringOffsets.from_bytes(new TextEncoder().encode(content));
}
lines() {
return this.inner.lines();
}
utf8ToUtf16(bytePos) {
return this.inner.utf8_to_utf16(bytePos);
}
utf16ToUtf8(utf16Pos) {
return this.inner.utf16_to_utf8(utf16Pos);
}
utf8ToLine(bytePos) {
return this.inner.utf8_to_line(bytePos);
}
lineToUtf8s(lineNumber) {
const [start, end] = this.inner.line_to_utf8s(lineNumber);
return { start, end };
}
utf8sToLines(start, end) {
const [startLine, endLine] = this.inner.utf8s_to_lines(start, end);
return { start: startLine, end: endLine };
}
}
module.exports = StringOffsets;