@vm75/inditrans 0.3.5

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/CHANGELOG.md ADDED
@@ -0,0 +1,87 @@
1
+ ## 0.3.5
2
+
3
+ - Fixed wasm, tests and nodejs support
4
+
5
+ ## 0.3.4
6
+
7
+ - Fixed some corner case
8
+
9
+ ## 0.3.3
10
+
11
+ - Added support for Tamil prefix
12
+
13
+ ## 0.3.2
14
+
15
+ - Renamed indicroman to readablelatin
16
+
17
+ ## 0.3.1
18
+
19
+ - Improved Tamil transliteration based on rules
20
+
21
+ ## 0.2.0
22
+
23
+ - Fixed Sinhara symbols
24
+
25
+ ## 0.1.9
26
+
27
+ - modified easyroman and renamed to readablelatin
28
+
29
+ ## 0.1.8
30
+
31
+ - Made InferAnuswara automatic. Fixed Diactric for Vowels.
32
+
33
+ ## 0.1.7
34
+
35
+ - fixed bug for indic
36
+
37
+ ## 0.1.6
38
+
39
+ - exported indic, added 2 scripts, fixed roman
40
+
41
+ ## 0.1.5
42
+
43
+ - Added fromString to Script enum
44
+
45
+ ## 0.1.4
46
+
47
+ - re-publish from correct branch.
48
+
49
+ ## 0.1.3
50
+
51
+ - Fixed build error
52
+
53
+ ## 0.1.2
54
+
55
+ - Added option to use ASCII numerals
56
+
57
+ ## 0.1.1
58
+
59
+ - fixed inferAnuswara for consonants after ma
60
+
61
+ ## 0.1.0
62
+
63
+ - Removed unnecessary Inditrans class. Added helpful scripts.
64
+
65
+ ## 0.0.6
66
+
67
+ - fixed example.
68
+
69
+ ## 0.0.5
70
+
71
+ - fixed android build issue.
72
+
73
+ ## 0.0.4
74
+
75
+ - removed unnecessary code and files.
76
+
77
+ ## 0.0.3
78
+
79
+ - Added comments and fixed formatting and example.
80
+
81
+ ## 0.0.2
82
+
83
+ - Fixed ffi_lib for non-web
84
+
85
+ ## 0.0.1
86
+
87
+ - Initial release
package/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # inditrans
2
+
3
+ An experimental transliterator library for some [Indic/Brahmi](https://en.wikipedia.org/wiki/Brahmic_scripts) scripts.
4
+
5
+ * Available on all platforms. Uses ffi for non-Web platforms and wasm for Web.
6
+ * Self-contained and performant.
7
+ * Supports [vedic accents](https://en.wikipedia.org/wiki/Vedic_accent). Useful for vedic scriptures.
8
+
9
+ References:
10
+ - [inditrans on Github](https://github.com/vm75/inditrans)
11
+ - [inditrans on pub.dev](https://pub.dev/packages/inditrans)
12
+
13
+ ## Supported scripts
14
+ * Brahmi scripts:
15
+ * bengali
16
+ * devanagari
17
+ * gujarati
18
+ * gurmukhi
19
+ * kannada
20
+ * malayalam
21
+ * oriya
22
+ * tamil
23
+ * telugu
24
+ * Roman scripts
25
+ * iast (https://en.wikipedia.org/wiki/International_Alphabet_of_Sanskrit_Transliteration)
26
+ * ipa (https://en.wikipedia.org/wiki/International_Phonetic_Alphabet)
27
+ * iso 15919 (https://en.wikipedia.org/wiki/ISO_15919)
28
+ * itrans (https://en.wikipedia.org/wiki/ITRANS)
29
+ * readablelatin (custom)
30
+
31
+ ## Usage example
32
+ ```dart
33
+ import 'package:inditrans/inditrans.dart' as inditrans;
34
+
35
+ Future<void> main() async {
36
+ // Init needs to complete before Inditrans could be used
37
+ await inditrans.init();
38
+
39
+ final result = inditrans.transliterate(
40
+ "श्री॒ गु॒रु॒भ्यो नमः॒ । ह॒रिः॒ ओ३म् ॥",
41
+ inditrans.Script.devanagari,
42
+ inditrans.Script.tamil,
43
+ inditrans.Options.IgnoreVedicAccents + inditrans.Options.TamilSuperscripted);
44
+ ...
45
+ }
46
+ ```
@@ -0,0 +1,11 @@
1
+ import { TranslitOptions } from './TranslitOptions';
2
+ export declare class IndiTrans {
3
+ static instance: Promise<IndiTrans>;
4
+ private static _init;
5
+ private module;
6
+ private memory;
7
+ private constructor();
8
+ private utf82ToString;
9
+ private stringToUtf8;
10
+ transliterate(text: string, from: string, to: string, options: TranslitOptions): string;
11
+ }
@@ -0,0 +1,59 @@
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));
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
+ }
58
+ exports.IndiTrans = IndiTrans;
59
+ //# sourceMappingURL=IndiTrans.js.map
@@ -0,0 +1,8 @@
1
+ export interface IndiTransModule {
2
+ transliterate(text: number, from: number, to: number, options: number): number;
3
+ releaseBuffer(ptr: number): void;
4
+ stackAlloc(size: number): number;
5
+ stackRestore(ptr: number): void;
6
+ memory: WebAssembly.Memory;
7
+ __indirect_function_table: WebAssembly.Table;
8
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=IndiTransModule.js.map
@@ -0,0 +1,9 @@
1
+ export declare enum TranslitOptions {
2
+ None = 0,
3
+ IgnoreVedicAccents = 1,
4
+ IgnoreQuotedMarkers = 2,
5
+ TamilTraditional = 4,
6
+ TamilSuperscripted = 8,
7
+ RetainZeroWidthChars = 16,
8
+ ASCIINumerals = 32
9
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TranslitOptions = void 0;
4
+ var TranslitOptions;
5
+ (function (TranslitOptions) {
6
+ TranslitOptions[TranslitOptions["None"] = 0] = "None";
7
+ TranslitOptions[TranslitOptions["IgnoreVedicAccents"] = 1] = "IgnoreVedicAccents";
8
+ TranslitOptions[TranslitOptions["IgnoreQuotedMarkers"] = 2] = "IgnoreQuotedMarkers";
9
+ TranslitOptions[TranslitOptions["TamilTraditional"] = 4] = "TamilTraditional";
10
+ TranslitOptions[TranslitOptions["TamilSuperscripted"] = 8] = "TamilSuperscripted";
11
+ TranslitOptions[TranslitOptions["RetainZeroWidthChars"] = 16] = "RetainZeroWidthChars";
12
+ TranslitOptions[TranslitOptions["ASCIINumerals"] = 32] = "ASCIINumerals";
13
+ })(TranslitOptions = exports.TranslitOptions || (exports.TranslitOptions = {}));
14
+ //# sourceMappingURL=TranslitOptions.js.map
@@ -0,0 +1,3 @@
1
+ import { IndiTrans } from './IndiTrans';
2
+ import { TranslitOptions } from './TranslitOptions';
3
+ export { IndiTrans, TranslitOptions };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TranslitOptions = exports.IndiTrans = void 0;
4
+ const IndiTrans_1 = require("./IndiTrans");
5
+ Object.defineProperty(exports, "IndiTrans", { enumerable: true, get: function () { return IndiTrans_1.IndiTrans; } });
6
+ const TranslitOptions_1 = require("./TranslitOptions");
7
+ Object.defineProperty(exports, "TranslitOptions", { enumerable: true, get: function () { return TranslitOptions_1.TranslitOptions; } });
8
+ //# sourceMappingURL=index.js.map
Binary file
@@ -0,0 +1,9 @@
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
+ }
@@ -0,0 +1,101 @@
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
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@vm75/inditrans",
3
+ "version": "0.3.5",
4
+ "description": "An experimental transliterator library for some Indic scripts.",
5
+ "main": "./dist/src/index.js",
6
+ "author": "VM75",
7
+ "license": "MIT",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/vm75/inditrans"
11
+ },
12
+ "files": [
13
+ "dist/src/*.ts",
14
+ "dist/src/*.js",
15
+ "dist/src/*.wasm"
16
+ ],
17
+ "types": "./dist/src/index.d.ts",
18
+ "scripts": {
19
+ "clean": "shx rm -rf dist/*",
20
+ "build": "yarn build-wasm && yarn copy-files && tsc",
21
+ "build-wasm": "make -C .. wasm",
22
+ "watch": "tsc --watch",
23
+ "test": "yarn build && yarn jest --config jestconfig.json",
24
+ "copy-files": "shx mkdir -p dist/src && shx cp -f src/inditrans.wasm dist/src/",
25
+ "prepack": "yarn clean && yarn build",
26
+ "publish": "yarn test && npm publish --access=public"
27
+ },
28
+ "devDependencies": {
29
+ "@types/jest": "^27.0.2",
30
+ "@types/node": "^18.0.3",
31
+ "@typescript-eslint/eslint-plugin": "^5.4.0",
32
+ "@typescript-eslint/parser": "^5.4.0",
33
+ "eslint": "^8.2.0",
34
+ "eslint-config-prettier": "^8.3.0",
35
+ "eslint-plugin-prettier": "^4.0.0",
36
+ "jest": "^27.2.5",
37
+ "prettier": "^2.4.1",
38
+ "shx": "^0.3.3",
39
+ "ts-jest": "^27.0.5",
40
+ "ts-node": "^10.9.1",
41
+ "typescript": "^4.5.4"
42
+ }
43
+ }