tibetan-mantra-to-iast-and-phonetics 0.1.0

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.
@@ -0,0 +1,3 @@
1
+ github: jerefrer
2
+ buy_me_a_coffee: frerejeremy
3
+ custom: "https://frerejeremy.me"
package/README.md ADDED
@@ -0,0 +1,112 @@
1
+ # tibetan-mantra-to-iast-and-phonetics
2
+
3
+ A naive attempt at converting the mantras from Unicode Tibetan into
4
+ IAST (International Alphabet of Sanskrit Transliteration) and phonetics.
5
+
6
+ ![1766753098762](image/README/1766753098762.png)
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ npm install tibetan-mantra-to-iast-and-phonetics
12
+ ```
13
+
14
+ Or if using as a local package:
15
+
16
+ ```bash
17
+ npm install /path/to/tibetan-mantra-to-iast-and-phonetics
18
+ ```
19
+
20
+ ## Usage as a Library
21
+
22
+ ### Basic Usage
23
+
24
+ ```javascript
25
+ import { TibetanMantraToIastAndPhonetics } from "tibetan-mantra-to-iast-and-phonetics";
26
+
27
+ // Transliterate to IAST
28
+ const tibetan = "ཨོཾ་མ་ཎི་པདྨེ་ཧཱུྃ།";
29
+ const transliterator = new TibetanMantraToIastAndPhonetics(tibetan);
30
+ const iast = transliterator.transliterate({ mode: "iast" });
31
+ console.log(iast); // "oṁ maṇi padmé hūṁ"
32
+
33
+ // Transliterate to phonetics
34
+ const phonetics = transliterator.transliterate({ mode: "phonetics" });
35
+ console.log(phonetics); // "om mani padme hung"
36
+ ```
37
+
38
+ ### Options
39
+
40
+ The `transliterate()` method accepts an options object:
41
+
42
+ - `mode`: `'iast'` (default) or `'phonetics'`
43
+ - `capitalize`: `true` or `false` (default) - Capitalizes the first letter
44
+
45
+ ```javascript
46
+ const result = transliterator.transliterate({
47
+ mode: "iast",
48
+ capitalize: true,
49
+ });
50
+ ```
51
+
52
+ ### Running Tests
53
+
54
+ The package includes a test suite that can be imported and used:
55
+
56
+ ```javascript
57
+ import {
58
+ testGroups,
59
+ runTests,
60
+ } from "tibetan-mantra-to-iast-and-phonetics/tests";
61
+
62
+ // Get test data
63
+ console.log(testGroups);
64
+
65
+ // Run all tests
66
+ const results = runTests();
67
+ console.log(results);
68
+ ```
69
+
70
+ Or run tests from the command line:
71
+
72
+ ```bash
73
+ npm test
74
+ ```
75
+
76
+ ## TODO
77
+
78
+ - Find the right transliteration for all the rules marked "to check"
79
+
80
+ ## Credits
81
+
82
+ A zillion thanks to everybody involved in building an maintaining Vue.js,
83
+ jQuery, SemanticUI, Sugar.js, Underscore.js, DevDocs, Zeal and Google Chrome
84
+ for making web development so easy and enjoyable.
85
+
86
+ Through the virtue coming from this work, may all beings human and
87
+ otherwise reach absolute freedom.
88
+
89
+ ## License
90
+
91
+ This software is licensed under the MIT License.
92
+
93
+ Copyright Padmakara, 2021-present.
94
+
95
+ Permission is hereby granted, free of charge, to any person obtaining a
96
+ copy of this software and associated documentation files (the
97
+ "Software"), to deal in the Software without restriction, including
98
+ without limitation the rights to use, copy, modify, merge, publish,
99
+ distribute, sublicense, and/or sell copies of the Software, and to permit
100
+ persons to whom the Software is furnished to do so, subject to the
101
+ following conditions:
102
+
103
+ The above copyright notice and this permission notice shall be included
104
+ in all copies or substantial portions of the Software.
105
+
106
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
107
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
108
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
109
+ NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
110
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
111
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
112
+ USE OR OTHER DEALINGS IN THE SOFTWARE.
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "tibetan-mantra-to-iast-and-phonetics",
3
+ "version": "0.1.0",
4
+ "description": "A library to transliterate Tibetan mantras to IAST and phonetics",
5
+ "type": "module",
6
+ "main": "./src/index.js",
7
+ "exports": {
8
+ ".": "./src/index.js",
9
+ "./tests": "./src/tests.js"
10
+ },
11
+ "scripts": {
12
+ "test": "node src/tests.js"
13
+ },
14
+ "keywords": [
15
+ "tibetan",
16
+ "mantra",
17
+ "transliteration",
18
+ "iast",
19
+ "phonetics"
20
+ ],
21
+ "author": "",
22
+ "license": "MIT",
23
+ "dependencies": {
24
+ "tibetan-normalizer": "^0.2.0"
25
+ }
26
+ }
package/src/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { normalizeString } from "./lib/normalize.js";
2
+ export { default as TibetanMantraToIastAndPhonetics } from "./lib/tibetan-mantra-to-iast-and-phonetics.js";
@@ -0,0 +1,139 @@
1
+ // Import and initialize the normalize.js script
2
+ // This extends String.prototype with a normalize() method for accent removal
3
+
4
+ let initialized = false;
5
+
6
+ function initializeNormalize() {
7
+ if (initialized) return;
8
+
9
+ const NormalizeMap = {};
10
+ let NormalizeReg, NormalizeSource;
11
+
12
+ function buildNormalizeMap() {
13
+ let normalized,
14
+ str,
15
+ all = "";
16
+ for (normalized in NormalizeSource) {
17
+ if (!NormalizeSource.hasOwnProperty(normalized)) continue;
18
+ str = NormalizeSource[normalized];
19
+ str.split("").forEach(function (character) {
20
+ NormalizeMap[character] = normalized;
21
+ });
22
+ all += str;
23
+ }
24
+ NormalizeReg = RegExp("[" + all + "]", "g");
25
+ }
26
+
27
+ NormalizeSource = {
28
+ A: "AⒶAÀÁÂẦẤẪẨÃĀĂẰẮẴẲȦǠÄǞẢÅǺǍȀȂẠẬẶḀĄȺⱯ",
29
+ B: "BⒷBḂḄḆɃƂƁ",
30
+ C: "CⒸCĆĈĊČÇḈƇȻꜾ",
31
+ D: "DⒹDḊĎḌḐḒḎĐƋƊƉꝹ",
32
+ E: "EⒺEÊỀẾỄỂẼĒḔḖĔĖËẺĚȄȆẸỆȨḜĘḘḚƐƎ",
33
+ F: "FⒻFḞƑꝻ",
34
+ G: "GⒼGǴĜḠĞĠǦĢǤƓꞠꝽꝾ",
35
+ H: "HⒽHĤḢḦȞḤḨḪĦⱧⱵꞍ",
36
+ I: "IⒾIÌÍÎĨĪĬİÏḮỈǏȈȊỊĮḬƗ",
37
+ J: "JⒿJĴɈ",
38
+ K: "KⓀKḰǨḲĶḴƘⱩꝀꝂꝄꞢ",
39
+ L: "LⓁLĿĹĽḶḸĻḼḺŁȽⱢⱠꝈꝆꞀ",
40
+ M: "MⓂMḾṀṂⱮƜ",
41
+ N: "NⓃNǸŃṄŇṆŅṊṈȠƝꞐꞤ",
42
+ O: "OⓄOÒÓÔỒỐỖỔÕṌȬṎŌṐṒŎȮȰÖȪỎŐǑȌȎƠỜỚỠỞỢỌỘǪǬØǾƆƟꝊꝌ",
43
+ P: "PⓅPṔṖƤⱣꝐꝒꝔ",
44
+ Q: "QⓆQꝖꝘɊ",
45
+ R: "RⓇRŔṘŘȐȒṚṜŖṞɌⱤꝚꞦꞂ",
46
+ S: "SⓈSẞŚṤŜṠŠṦṢṨȘŞⱾꞨꞄ",
47
+ T: "TⓉTṪŤṬȚŢṰṮŦƬƮȾꞆ",
48
+ U: "UⓊUÙÚÛŨṸŪṺŬÜǛǗǕǙỦŮŰǓȔȖƯỪỨỮỬỰỤṲŲṶṴɄ",
49
+ V: "VⓋVṼṾƲꝞɅ",
50
+ W: "WⓌWẀẂŴẆẄẈⱲ",
51
+ X: "XⓍXẊẌ",
52
+ Y: "YⓎYỲÝŶỸȲẎŸỶỴƳɎỾ",
53
+ Z: "ZⓏZŹẐŻŽẒẔƵȤⱿⱫꝢ",
54
+ a: "aⓐaẚàáâầấẫẩãāăằắẵẳȧǡäǟảåǻǎȁȃạậặḁąⱥɐ",
55
+ b: "bⓑbḃḅḇƀƃɓ",
56
+ c: "cⓒcćĉċčçḉƈȼꜿↄ",
57
+ d: "dⓓdḋďḍḑḓḏđƌɖɗꝺ",
58
+ e: "eⓔeêềếễểẽēḕḗĕėëẻěȅȇẹệȩḝęḙḛɇɛǝ",
59
+ f: "fⓕfḟƒꝼ",
60
+ g: "gⓖgǵĝḡğġǧģǥɠꞡᵹꝿ",
61
+ h: "hⓗhĥḣḧȟḥḩḫẖħⱨⱶɥ",
62
+ i: "iⓘiìíîĩīĭïḯỉǐȉȋịįḭɨı",
63
+ j: "jⓙjĵǰɉ",
64
+ k: "kⓚkḱǩḳķḵƙⱪꝁꝃꝅꞣ",
65
+ l: "lⓛlŀĺľḷḹļḽḻſłƚɫⱡꝉꞁꝇ",
66
+ m: "mⓜmḿṁṃɱɯ",
67
+ n: "nⓝnǹńṅňṇņṋṉƞɲʼnꞑꞥ",
68
+ o: "oⓞoòóôồốỗổõṍȭṏōṑṓŏȯȱöȫỏőǒȍȏơờớỡởợọộǫǭøǿɔꝋꝍɵ",
69
+ p: "pⓟpṕṗƥᵽꝑꝓꝕ",
70
+ q: "qⓠqɋꝗꝙ",
71
+ r: "rⓡrŕṙřȑȓṛṝŗṟɍɽꝛꞧꞃ",
72
+ s: "sⓢsśṥŝṡšṧṣṩșşȿꞩꞅẛ",
73
+ t: "tⓣtṫẗťṭțţṱṯŧƭʈⱦꞇ",
74
+ u: "uⓤuùúûũṹūṻŭüǜǘǖǚủůűǔȕȗưừứữửựụṳųṷṵʉ",
75
+ v: "vⓥvṽṿʋꝟʌ",
76
+ w: "wⓦwẁẃŵẇẅẘẉⱳ",
77
+ x: "xⓧxẋẍ",
78
+ y: "yⓨyỳýŷỹȳẏÿỷẙỵƴɏỿ",
79
+ z: "zⓩzźẑżžẓẕƶȥɀⱬꝣ",
80
+ AA: "Ꜳ",
81
+ AE: "ÆǼǢ",
82
+ AO: "Ꜵ",
83
+ AU: "Ꜷ",
84
+ AV: "ꜸꜺ",
85
+ AY: "Ꜽ",
86
+ DZ: "DZDŽ",
87
+ Dz: "DzDž",
88
+ LJ: "LJ",
89
+ Lj: "Lj",
90
+ NJ: "NJ",
91
+ Nj: "Nj",
92
+ OI: "Ƣ",
93
+ OO: "Ꝏ",
94
+ OU: "Ȣ",
95
+ TZ: "Ꜩ",
96
+ VY: "Ꝡ",
97
+ aa: "ꜳ",
98
+ ae: "æǽǣ",
99
+ ao: "ꜵ",
100
+ au: "ꜷ",
101
+ av: "ꜹꜻ",
102
+ ay: "ꜽ",
103
+ dz: "dzdž",
104
+ hv: "ƕ",
105
+ lj: "lj",
106
+ nj: "nj",
107
+ oi: "ƣ",
108
+ ou: "ȣ",
109
+ oo: "ꝏ",
110
+ ss: "ß",
111
+ tz: "ꜩ",
112
+ vy: "ꝡ",
113
+ };
114
+
115
+ // Extend String prototype with normalize method
116
+ if (!String.prototype.normalizeAccents) {
117
+ String.prototype.normalizeAccents = function () {
118
+ return this.replace(NormalizeReg, function (character) {
119
+ return NormalizeMap[character];
120
+ });
121
+ };
122
+ }
123
+
124
+ buildNormalizeMap();
125
+ initialized = true;
126
+ }
127
+
128
+ // Initialize on module load
129
+ initializeNormalize();
130
+
131
+ // Export a function that normalizes strings
132
+ export function normalizeString(str) {
133
+ if (!initialized) {
134
+ initializeNormalize();
135
+ }
136
+ return str.normalizeAccents();
137
+ }
138
+
139
+ export default normalizeString;