@vm75/inditrans 0.7.0 → 0.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,69 +1,119 @@
1
- # inditrans
1
+ # @vm75/inditrans
2
2
 
3
- A functional transliterator library for the most common [Indic/Brahmic](https://en.wikipedia.org/wiki/Brahmic_scripts) scripts.
3
+ [![npm](https://img.shields.io/npm/v/@vm75/inditrans)](https://www.npmjs.com/package/@vm75/inditrans)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/vm75/inditrans/blob/master/LICENSE)
4
5
 
5
- - No dependencies and no server needed. Uses wasm for near native performance.
6
- - Supports ITRANS toggle transliteration with ## and skipping XML tags
7
- - Special handling for scripts like Tamil, Malayalam, Gurmukhi, etc. Tuned for reability.
8
- - Supports [vedic accents](https://en.wikipedia.org/wiki/Vedic_accent) for vedic scriptures.
6
+ A transliteration library for [Indic/Brahmic](https://en.wikipedia.org/wiki/Brahmic_scripts)
7
+ and Latin scripts for Node.js and the browser. Powered by a C++23 engine compiled to WASM
8
+ for near-native performance, with no server dependency.
9
9
 
10
- <!-- - [Demo](http://vm75.github.io/inditrans/example/) -->
11
- - [Changelog](CHANGELOG.md)
10
+ - ITRANS toggle transliteration — wrap any region in `##…##` to pass it through unchanged.
11
+ - XML/HTML tag pass-through — tags are never transliterated.
12
+ - Special handling for Tamil, Malayalam, Gurmukhi, and other scripts tuned for readability.
13
+ - [Vedic accent](https://en.wikipedia.org/wiki/Vedic_accent) support for Vedic scriptures.
14
+ - Full TypeScript typings included.
15
+
16
+ ## Supported scripts
12
17
 
13
- References:
18
+ **Indic/Brahmic:** Assamese, Bengali, Burmese, Devanagari, Gujarati, Gurmukhi, Kannada,
19
+ Khmer, Malayalam, Oriya, Sinhala, Tamil, Tamil-Extended, Telugu, Thai, Tibetan
14
20
 
15
- - [inditrans on Github](https://github.com/vm75/inditrans)
16
- - [inditrans for Flutter](https://pub.dev/packages/inditrans)
17
- - [inditrans for nodejs](https://www.npmjs.com/package/@vm75/inditrans)
21
+ **Latin/Roman:**
22
+ [IAST](https://en.wikipedia.org/wiki/International_Alphabet_of_Sanskrit_Transliteration) ·
23
+ [IPA](https://en.wikipedia.org/wiki/International_Phonetic_Alphabet) ·
24
+ [ISO 15919](https://en.wikipedia.org/wiki/ISO_15919) ·
25
+ [ITRANS](https://www.aczoom.com/itrans/) ·
26
+ [TITUS](https://titus.uni-frankfurt.de/indexe.htm) ·
27
+ ReadableLatin
18
28
 
19
- ## Supported scripts
29
+ ### ITRANS notation notes
20
30
 
21
- - Indic/Brahmic scripts:
22
- - Assamese
23
- - Bengali
24
- - Burmese
25
- - Devanagari
26
- - Gujarati
27
- - Gurmukhi
28
- - Kannada
29
- - Khmer
30
- - Malayalam
31
- - Oriya
32
- - Sinhala
33
- - Tamil
34
- - Tamil-Extended
35
- - Telugu
36
- - Tibetan
37
- - Thai
38
- - Latin/Roman scripts:
39
- - IAST (https://en.wikipedia.org/wiki/International_Alphabet_of_Sanskrit_Transliteration)
40
- - IPA (https://en.wikipedia.org/wiki/International_Phonetic_Alphabet)
41
- - ISO 15919 (https://en.wikipedia.org/wiki/ISO_15919)
42
- - ITRANS (https://en.wikipedia.org/wiki/ITRANS)
43
- - ReadableLatin (easy to read in Latin alphabets with some customizations)
44
- - TITUS (https://titus.uni-frankfurt.de/indexe.htm)
31
+ `inditrans` implements uniform phonemic vowel mapping adhering to the [ITRANS specification](https://www.aczoom.com/itrans/):
32
+ - **Short vowels**: `e` and `o` encode short vowels (e.g. Kannada `ಎ` / `ೆ`, Telugu `ఎ` / `ె`, Tamil `எ` / `ெ`, Malayalam `എ` / `െ`, Devanagari `ऎ` / `ॆ`). `^e` and `^o` remain supported as aliases.
33
+ - **Long vowels**: `E` and `O` encode long vowels (e.g. Kannada `ಏ` / `ೇ`, Telugu `ఏ` / `ే`, Tamil `ஏ` / `ே`, Malayalam `ഏ` / `േ`, Devanagari `ए` / `े`).
34
+ - Examples: `te` $\to$ `तॆ` / `ತೆ`, `tE` $\to$ `ते` / `ತೇ`; `tere bina` $\to$ `ತೆರೆ ಬಿನ` (Kannada), `tErE bina` $\to$ `ತೇರೇ ಬಿನ` (Kannada) / `तेरे बिन` (Devanagari).
35
+
36
+ ## Requirements
37
+
38
+ - Node.js ≥ 18.3 (or modern browser with WebAssembly support)
45
39
 
46
40
  ## Installation
47
41
 
48
- ```
42
+ ```sh
49
43
  npm install @vm75/inditrans
44
+ # or
45
+ yarn add @vm75/inditrans
50
46
  ```
51
47
 
52
- ## Usage example
48
+ ## Quick start
53
49
 
54
- ```javascript
55
- import * as inditrans from 'inditrans';
50
+ ```typescript
51
+ import * as inditrans from '@vm75/inditrans';
56
52
 
57
- async function test() {
58
- // Init needs to complete before Inditrans could be used
59
- await indiTrans.init();
53
+ async function main() {
54
+ // init() must complete before transliterate() is called
55
+ await inditrans.init();
60
56
 
61
- result = inditrans.transliterate(
57
+ const result = inditrans.transliterate(
62
58
  "श्री॒ गु॒रु॒भ्यो नमः॒ । ह॒रिः॒ ओ३म् ॥",
63
59
  inditrans.Script.devanagari,
64
60
  inditrans.Script.tamil,
65
- inditrans.Option.IgnoreVedicAccents + inditrans.Option.TamilSuperscripted
61
+ inditrans.Option.IgnoreVedicAccents | inditrans.Option.TamilSuperscripted,
66
62
  );
67
- ...
63
+ console.log(result);
68
64
  }
65
+
66
+ main();
69
67
  ```
68
+
69
+ ## API
70
+
71
+ ### `init(): Promise<void>`
72
+
73
+ Loads and initialises the WASM module. Must be awaited before any other call.
74
+
75
+ ### `transliterate(text, from, to, options?): string`
76
+
77
+ Transliterates `text` from the `from` script to the `to` script.
78
+
79
+ | Parameter | Type | Description |
80
+ |---|---|---|
81
+ | `text` | `string` | Input text |
82
+ | `from` | `Script` | Source script |
83
+ | `to` | `Script` | Target script |
84
+ | `options` | `Option` | Bitwise combination of option flags (default: `Option.None`) |
85
+
86
+ ### `isScriptSupported(script: string): boolean`
87
+
88
+ Returns `true` when the given script name is recognised.
89
+
90
+ ## Options
91
+
92
+ | Option | Value | Description |
93
+ |---|---|---|
94
+ | `Option.None` | `0` | No options (default) |
95
+ | `Option.TamilTraditional` | `1` | Traditional Tamil consonants only |
96
+ | `Option.TamilSuperscripted` | `2` | Superscripted Tamil consonants |
97
+ | `Option.ASCIINumerals` | `4` | Force ASCII numerals in output |
98
+ | `Option.IgnoreVedicAccents` | `8` | Strip Vedic accent markers |
99
+ | `Option.RetainSpecialMarkers` | `16` | Keep non-standard character markers |
100
+ | `Option.NoXMLTagHandling` | `32` | Treat XML/HTML tags as plain text |
101
+
102
+ Combine flags with the bitwise OR operator: `Option.IgnoreVedicAccents | Option.TamilSuperscripted`.
103
+
104
+ ## Development
105
+
106
+ ```sh
107
+ yarn install # install dependencies
108
+ yarn test # build WASM and run tests
109
+ ```
110
+
111
+ ## Documentation
112
+
113
+ - [Changelog](CHANGELOG.md)
114
+ - [Project on GitHub](https://github.com/vm75/inditrans)
115
+ - [Flutter / Dart package](https://pub.dev/packages/inditrans)
116
+
117
+ ## License
118
+
119
+ [MIT](../LICENSE)
@@ -4,5 +4,6 @@ export declare enum Option {
4
4
  TamilSuperscripted = 2,
5
5
  ASCIINumerals = 4,
6
6
  IgnoreVedicAccents = 8,
7
- RetainSpecialMarkers = 16
7
+ RetainSpecialMarkers = 16,
8
+ NoXMLTagHandling = 32
8
9
  }
@@ -18,5 +18,7 @@ var Option;
18
18
  Option[Option["IgnoreVedicAccents"] = 8] = "IgnoreVedicAccents";
19
19
  /// Retain special markers which are used to identify non-standard chars
20
20
  Option[Option["RetainSpecialMarkers"] = 16] = "RetainSpecialMarkers";
21
- })(Option = exports.Option || (exports.Option = {}));
21
+ /// Do not check for xml/html tags, and treat them as normal text
22
+ Option[Option["NoXMLTagHandling"] = 32] = "NoXMLTagHandling";
23
+ })(Option || (exports.Option = Option = {}));
22
24
  //# sourceMappingURL=Option.js.map
@@ -7,6 +7,7 @@ export declare enum Script {
7
7
  gujarati = "gujarati",
8
8
  gurmukhi = "gurmukhi",
9
9
  hindi = "hindi",
10
+ hk = "hk",
10
11
  iast = "iast",
11
12
  indic = "indic",
12
13
  ipa = "ipa",
@@ -21,11 +22,13 @@ export declare enum Script {
21
22
  readableLatin = "readableLatin",
22
23
  sanskrit = "sanskrit",
23
24
  sinhala = "sinhala",
25
+ slp1 = "slp1",
24
26
  tamil = "tamil",
25
27
  tamilExtended = "tamilExtended",
26
28
  telugu = "telugu",
27
29
  thai = "thai",
28
30
  tibetan = "tibetan",
29
31
  titus = "titus",
32
+ velthuis = "velthuis",
30
33
  wx = "wx"
31
34
  }
@@ -13,6 +13,7 @@ var Script;
13
13
  Script["gujarati"] = "gujarati";
14
14
  Script["gurmukhi"] = "gurmukhi";
15
15
  Script["hindi"] = "hindi";
16
+ Script["hk"] = "hk";
16
17
  Script["iast"] = "iast";
17
18
  Script["indic"] = "indic";
18
19
  Script["ipa"] = "ipa";
@@ -27,12 +28,14 @@ var Script;
27
28
  Script["readableLatin"] = "readableLatin";
28
29
  Script["sanskrit"] = "sanskrit";
29
30
  Script["sinhala"] = "sinhala";
31
+ Script["slp1"] = "slp1";
30
32
  Script["tamil"] = "tamil";
31
33
  Script["tamilExtended"] = "tamilExtended";
32
34
  Script["telugu"] = "telugu";
33
35
  Script["thai"] = "thai";
34
36
  Script["tibetan"] = "tibetan";
35
37
  Script["titus"] = "titus";
38
+ Script["velthuis"] = "velthuis";
36
39
  Script["wx"] = "wx";
37
- })(Script = exports.Script || (exports.Script = {}));
40
+ })(Script || (exports.Script = Script = {}));
38
41
  //# sourceMappingURL=Script.js.map
@@ -4,5 +4,11 @@ export { Option, Script };
4
4
  export declare function init(): Promise<void>;
5
5
  export declare function transliterate(text: string, from: Script, to: Script, options: Option): string;
6
6
  export declare function isScriptSupported(script: string): boolean;
7
- declare const _default: (typeof Option | typeof Script | typeof init | typeof transliterate | typeof isScriptSupported)[];
7
+ declare const _default: {
8
+ Option: typeof Option;
9
+ Script: typeof Script;
10
+ init: typeof init;
11
+ transliterate: typeof transliterate;
12
+ isScriptSupported: typeof isScriptSupported;
13
+ };
8
14
  export default _default;
package/dist/src/index.js CHANGED
@@ -1,29 +1,57 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isScriptSupported = exports.transliterate = exports.init = exports.Script = exports.Option = void 0;
4
- const Inditrans_1 = require("./Inditrans");
6
+ exports.Script = exports.Option = void 0;
7
+ exports.init = init;
8
+ exports.transliterate = transliterate;
9
+ exports.isScriptSupported = isScriptSupported;
5
10
  const Option_1 = require("./Option");
6
11
  Object.defineProperty(exports, "Option", { enumerable: true, get: function () { return Option_1.Option; } });
7
12
  const Script_1 = require("./Script");
8
13
  Object.defineProperty(exports, "Script", { enumerable: true, get: function () { return Script_1.Script; } });
9
- let inditrans = null;
14
+ const path_1 = __importDefault(require("path"));
15
+ let Module = null;
10
16
  async function init() {
11
- inditrans = await Inditrans_1.Inditrans.instance;
17
+ // Try to load from compiled dist location first, fall back to src
18
+ let inditransPath;
19
+ try {
20
+ inditransPath = path_1.default.join(__dirname, 'inditrans.js');
21
+ }
22
+ catch {
23
+ inditransPath = path_1.default.join(__dirname, '../js/public/inditrans.js');
24
+ }
25
+ // The module directly exports Module, not a factory
26
+ Module = require(inditransPath);
27
+ // Wait for runtime initialization if needed
28
+ if (Module.onRuntimeInitialized) {
29
+ await new Promise(resolve => {
30
+ if (Module.inditrans) {
31
+ resolve(undefined);
32
+ }
33
+ else {
34
+ const originalCallback = Module.onRuntimeInitialized;
35
+ Module.onRuntimeInitialized = () => {
36
+ if (originalCallback)
37
+ originalCallback();
38
+ resolve(undefined);
39
+ };
40
+ }
41
+ });
42
+ }
12
43
  }
13
- exports.init = init;
14
44
  function transliterate(text, from, to, options) {
15
- if (!inditrans) {
16
- throw new Error('Inditrans not initialized');
45
+ if (!Module) {
46
+ throw new Error('Inditrans not initialized. Call init() first.');
17
47
  }
18
- return inditrans.transliterate(text, from, to, options);
48
+ return Module.inditrans.transliterate(text, from, to, options);
19
49
  }
20
- exports.transliterate = transliterate;
21
50
  function isScriptSupported(script) {
22
- if (!inditrans) {
23
- throw new Error('Inditrans not initialized');
51
+ if (!Module) {
52
+ throw new Error('Inditrans not initialized. Call init() first.');
24
53
  }
25
- return inditrans.isScriptSupported(script);
54
+ return Module.inditrans.isScriptSupported(script);
26
55
  }
27
- exports.isScriptSupported = isScriptSupported;
28
- exports.default = [Option_1.Option, Script_1.Script, init, transliterate, isScriptSupported];
56
+ exports.default = { Option: Option_1.Option, Script: Script_1.Script, init, transliterate, isScriptSupported };
29
57
  //# sourceMappingURL=index.js.map
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vm75/inditrans",
3
- "version": "0.7.0",
3
+ "version": "0.13.1",
4
4
  "description": "A functional transliterator library for the most common Indic/Brahmic scripts.",
5
5
  "main": "./dist/src/index.js",
6
6
  "author": "VM75",
@@ -20,30 +20,36 @@
20
20
  "test/"
21
21
  ],
22
22
  "types": "./dist/src/index.d.ts",
23
+ "engines": {
24
+ "node": ">=18.3"
25
+ },
23
26
  "scripts": {
24
27
  "clean": "shx rm -rf dist/*",
25
28
  "build": "yarn build-wasm && yarn copy-files && tsc",
26
29
  "build-wasm": "make -C .. wasm",
27
30
  "watch": "tsc --watch",
28
31
  "test": "yarn build && yarn jest --config jestconfig.json",
29
- "copy-files": "shx mkdir -p dist/src && shx cp -f src/inditrans.wasm dist/src/",
32
+ "copy-files": "shx mkdir -p dist/src && shx cp -f ../js/public/inditrans.js dist/src/ && shx cp -f ../js/public/inditrans.js src/",
30
33
  "prepack": "yarn clean && yarn test",
31
34
  "pub": "npm publish --access=public"
32
35
  },
33
36
  "devDependencies": {
34
- "@types/jest": "^27.0.2",
35
- "@types/node": "^18.0.3",
36
- "@typescript-eslint/eslint-plugin": "^5.4.0",
37
- "@typescript-eslint/parser": "^5.4.0",
38
- "eslint": "^8.2.0",
39
- "eslint-config-prettier": "^8.3.0",
40
- "eslint-plugin-prettier": "^4.0.0",
41
- "jest": "^27.2.5",
42
- "prettier": "^2.4.1",
43
- "shx": "^0.3.3",
44
- "ts-jest": "^27.0.5",
45
- "ts-node": "^10.9.1",
46
- "typescript": "^4.5.4"
37
+ "@types/jest": "^30.0.0",
38
+ "@types/node": "^26.6.3",
39
+ "@typescript-eslint/eslint-plugin": "^8.71.0",
40
+ "@typescript-eslint/parser": "^8.71.0",
41
+ "eslint": "^10.11.0",
42
+ "eslint-config-prettier": "^10.1.8",
43
+ "eslint-plugin-prettier": "^5.5.6",
44
+ "jest": "^30.5.2",
45
+ "prettier": "^3.9.9",
46
+ "shx": "^0.4.0",
47
+ "ts-jest": "^29.4.14",
48
+ "ts-node": "^10.9.2",
49
+ "typescript": "^6.0.3"
50
+ },
51
+ "resolutions": {
52
+ "handlebars": "^4.7.10"
47
53
  },
48
54
  "keywords": [
49
55
  "Transliterate",
@@ -1,13 +0,0 @@
1
- import { Option } from './Option';
2
- import { Script } from './Script';
3
- export declare class Inditrans {
4
- static instance: Promise<Inditrans>;
5
- private static _init;
6
- private module;
7
- private memory;
8
- private constructor();
9
- private utf82ToString;
10
- private stringToUtf8;
11
- transliterate(text: string, from: Script, to: Script, options: Option): string;
12
- isScriptSupported(script: string): boolean;
13
- }
@@ -1,65 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Inditrans = void 0;
7
- const fs_1 = __importDefault(require("fs"));
8
- class Inditrans {
9
- static instance = Inditrans._init();
10
- static async _init() {
11
- const { instance } = await WebAssembly.instantiate(fs_1.default.readFileSync(`${__dirname}/inditrans.wasm`));
12
- return new Inditrans(instance.exports);
13
- }
14
- module;
15
- memory;
16
- constructor(wrapper) {
17
- this.module = wrapper;
18
- this.memory = new Uint8Array(wrapper.memory.buffer);
19
- }
20
- utf82ToString(ptr) {
21
- if (ptr === 0) {
22
- return '';
23
- }
24
- const decoder = new TextDecoder();
25
- let endPtr = ptr;
26
- while (this.memory[endPtr]) {
27
- ++endPtr;
28
- }
29
- return decoder.decode(this.memory.subarray(ptr, endPtr));
30
- }
31
- stringToUtf8(str) {
32
- let ret = 0;
33
- if (str === null && str === undefined) {
34
- return ret;
35
- }
36
- const encoder = new TextEncoder();
37
- const encodedText = encoder.encode(str);
38
- const len = encodedText.length + 1;
39
- ret = this.module.stackAlloc(len);
40
- if (encodedText.length > 0) {
41
- this.memory.set(encodedText, ret);
42
- }
43
- this.memory[ret + encodedText.length] = 0;
44
- return ret;
45
- }
46
- transliterate(text, from, to, options) {
47
- const pointers = [text, from, to].map((str) => this.stringToUtf8(str.toString()));
48
- const resultPtr = this.module.transliterate(pointers[0], pointers[1], pointers[2], options);
49
- let result = '';
50
- if (resultPtr !== 0) {
51
- result = this.utf82ToString(resultPtr);
52
- this.module.releaseBuffer(resultPtr);
53
- }
54
- pointers.map((ptr) => this.module.stackRestore(ptr));
55
- return result;
56
- }
57
- isScriptSupported(script) {
58
- const ptr = this.stringToUtf8(script);
59
- const result = this.module.isScriptSupported(ptr);
60
- this.module.stackRestore(ptr);
61
- return result == 1;
62
- }
63
- }
64
- exports.Inditrans = Inditrans;
65
- //# sourceMappingURL=Inditrans.js.map
@@ -1,9 +0,0 @@
1
- export interface InditransModule {
2
- transliterate(text: number, from: number, to: number, options: number): number;
3
- isScriptSupported(script: number): number;
4
- releaseBuffer(ptr: number): void;
5
- stackAlloc(size: number): number;
6
- stackRestore(ptr: number): void;
7
- memory: WebAssembly.Memory;
8
- __indirect_function_table: WebAssembly.Table;
9
- }
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=InditransModule.js.map
Binary file
@@ -1,9 +0,0 @@
1
- import { InditransModule } from './InditransModule';
2
- export declare class Codec {
3
- private module;
4
- private memory;
5
- constructor(module: InditransModule);
6
- private stringToNativeArray;
7
- private nativeArrayToString;
8
- private stringToUtf82;
9
- }
package/dist/src/utf8.js DELETED
@@ -1,101 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Codec = void 0;
4
- class Codec {
5
- module;
6
- memory;
7
- constructor(module) {
8
- this.module = module;
9
- this.memory = new Uint8Array(module.memory.buffer);
10
- }
11
- stringToNativeArray(str, outIdx, maxBytesToWrite) {
12
- if (!(maxBytesToWrite > 0))
13
- return 0;
14
- const startIdx = outIdx;
15
- const endIdx = outIdx + maxBytesToWrite - 1;
16
- for (let i = 0; i < str.length; ++i) {
17
- let charCode = str.charCodeAt(i);
18
- if (charCode >= 55296 && charCode <= 57343) {
19
- const byte1 = str.charCodeAt(++i);
20
- charCode = (65536 + ((charCode & 1023) << 10)) | (byte1 & 1023);
21
- }
22
- if (charCode <= 127) {
23
- if (outIdx >= endIdx)
24
- break;
25
- this.memory[outIdx++] = charCode;
26
- }
27
- else if (charCode <= 2047) {
28
- if (outIdx + 1 >= endIdx)
29
- break;
30
- this.memory[outIdx++] = 192 | (charCode >> 6);
31
- this.memory[outIdx++] = 128 | (charCode & 63);
32
- }
33
- else if (charCode <= 65535) {
34
- if (outIdx + 2 >= endIdx)
35
- break;
36
- this.memory[outIdx++] = 224 | (charCode >> 12);
37
- this.memory[outIdx++] = 128 | ((charCode >> 6) & 63);
38
- this.memory[outIdx++] = 128 | (charCode & 63);
39
- }
40
- else {
41
- if (outIdx + 3 >= endIdx)
42
- break;
43
- this.memory[outIdx++] = 240 | (charCode >> 18);
44
- this.memory[outIdx++] = 128 | ((charCode >> 12) & 63);
45
- this.memory[outIdx++] = 128 | ((charCode >> 6) & 63);
46
- this.memory[outIdx++] = 128 | (charCode & 63);
47
- }
48
- }
49
- this.memory[outIdx] = 0;
50
- return outIdx - startIdx;
51
- }
52
- nativeArrayToString(idx, maxBytesToRead) {
53
- const endIdx = idx + maxBytesToRead;
54
- let endPtr = idx;
55
- while (this.memory[endPtr] && !(endPtr >= endIdx))
56
- ++endPtr;
57
- let str = '';
58
- while (idx < endPtr) {
59
- let byte0 = this.memory[idx++];
60
- if (!(byte0 & 128)) {
61
- str += String.fromCharCode(byte0);
62
- continue;
63
- }
64
- const byte1 = this.memory[idx++] & 63;
65
- if ((byte0 & 224) == 192) {
66
- str += String.fromCharCode(((byte0 & 31) << 6) | byte1);
67
- continue;
68
- }
69
- const byte2 = this.memory[idx++] & 63;
70
- if ((byte0 & 240) == 224) {
71
- byte0 = ((byte0 & 15) << 12) | (byte1 << 6) | byte2;
72
- }
73
- else {
74
- byte0 =
75
- ((byte0 & 7) << 18) |
76
- (byte1 << 12) |
77
- (byte2 << 6) |
78
- (this.memory[idx++] & 63);
79
- }
80
- if (byte0 < 65536) {
81
- str += String.fromCharCode(byte0);
82
- }
83
- else {
84
- const ch = byte0 - 65536;
85
- str += String.fromCharCode(55296 | (ch >> 10), 56320 | (ch & 1023));
86
- }
87
- }
88
- return str;
89
- }
90
- stringToUtf82(str) {
91
- let ret = 0;
92
- if (str !== null && str !== undefined) {
93
- const len = (str.length << 2) + 1;
94
- ret = this.module.stackAlloc(len);
95
- this.stringToNativeArray(str, ret, len);
96
- }
97
- return ret;
98
- }
99
- }
100
- exports.Codec = Codec;
101
- //# sourceMappingURL=utf8.js.map