hebrew-transliteration 2.1.1 → 2.2.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.
- package/README.md +17 -0
- package/dist/hebCharsTrans.d.ts +6 -0
- package/dist/hebCharsTrans.js +56 -0
- package/dist/index.d.ts +6 -659
- package/dist/index.js +12 -434
- package/dist/mapChars.d.ts +10 -0
- package/dist/mapChars.js +14 -0
- package/dist/remove.d.ts +65 -0
- package/dist/remove.js +45 -0
- package/dist/rules.d.ts +5 -0
- package/dist/rules.js +242 -0
- package/dist/schema.d.ts +476 -0
- package/dist/schema.js +161 -0
- package/dist/schemas/brillAcademic.d.ts +2 -0
- package/dist/schemas/brillAcademic.js +74 -0
- package/dist/schemas/brillSimple.d.ts +2 -0
- package/dist/schemas/brillSimple.js +73 -0
- package/dist/schemas/index.d.ts +5 -0
- package/dist/schemas/index.js +11 -0
- package/dist/schemas/michiganClaremont.d.ts +2 -0
- package/dist/schemas/michiganClaremont.js +67 -0
- package/dist/schemas/sblAcademicSpirantization.d.ts +2 -0
- package/dist/schemas/sblAcademicSpirantization.js +73 -0
- package/dist/schemas/sblSimple.d.ts +2 -0
- package/dist/schemas/sblSimple.js +70 -0
- package/dist/sequence.d.ts +18 -0
- package/dist/sequence.js +25 -0
- package/dist/transliterate.d.ts +45 -0
- package/dist/transliterate.js +88 -0
- package/package.json +27 -12
- package/dist/index.esm.js +0 -406
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transliterate = void 0;
|
|
4
|
+
const rules_1 = require("./rules");
|
|
5
|
+
const schema_1 = require("./schema");
|
|
6
|
+
const havarotjs_1 = require("havarotjs");
|
|
7
|
+
const word_1 = require("havarotjs/dist/word");
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* @param schema
|
|
11
|
+
* @returns syllable options passed into havarotjs
|
|
12
|
+
* @description sanitizes the SylOpts of the schema so as to not pass in undefined
|
|
13
|
+
*/
|
|
14
|
+
const getSylOpts = (schema) => {
|
|
15
|
+
const options = {};
|
|
16
|
+
if ("longVowels" in schema)
|
|
17
|
+
options.longVowels = schema.longVowels;
|
|
18
|
+
if ("qametsQatan" in schema)
|
|
19
|
+
options.qametsQatan = schema.qametsQatan;
|
|
20
|
+
if ("sqnmlvy" in schema)
|
|
21
|
+
options.sqnmlvy = schema.sqnmlvy;
|
|
22
|
+
if ("wawShureq" in schema)
|
|
23
|
+
options.wawShureq = schema.wawShureq;
|
|
24
|
+
if ("article" in schema)
|
|
25
|
+
options.article = schema.article;
|
|
26
|
+
if ("allowNoNiqqud" in schema)
|
|
27
|
+
options.allowNoNiqqud = schema.allowNoNiqqud;
|
|
28
|
+
return options;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* transliterates Hebrew text
|
|
32
|
+
*
|
|
33
|
+
* @param text - a string or {@link https://charlesloder.github.io/havarot/classes/text.Text.html | Text} of Hebrew characters
|
|
34
|
+
* @param schema - a {@link Schema} for transliterating the text
|
|
35
|
+
* @returns a transliterated text
|
|
36
|
+
*
|
|
37
|
+
* @example Default
|
|
38
|
+
* ```ts
|
|
39
|
+
* import { transliterate } from "hebrew-transliteration";
|
|
40
|
+
*
|
|
41
|
+
* transliterate("אֱלֹהִים");
|
|
42
|
+
* // "ʾĕlōhîm";
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* ---
|
|
46
|
+
*
|
|
47
|
+
* @remarks
|
|
48
|
+
*
|
|
49
|
+
* If no {@link Schema} is passed, then the package defaults to SBL's academic style
|
|
50
|
+
*
|
|
51
|
+
* You can pass in a partial schema that will modify SBL's academic style:
|
|
52
|
+
*
|
|
53
|
+
* ```ts
|
|
54
|
+
* transliterate("שָׁלוֹם", { SHIN: "sh" })
|
|
55
|
+
* // shālôm
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* ---
|
|
59
|
+
*
|
|
60
|
+
* If you need a fully custom schema, it is best to use the {@link Schema} constructor:
|
|
61
|
+
*
|
|
62
|
+
* ```ts
|
|
63
|
+
* import { transliterate, Schema } from "hebrew-transliteration";
|
|
64
|
+
*
|
|
65
|
+
* const schema = new Schema({ ALEF: "'", BET: "B", ... QAMETS: "A", ... }) // truncated for brevity
|
|
66
|
+
*
|
|
67
|
+
* transliterate("אָ֣ב", schema)
|
|
68
|
+
* // 'AB
|
|
69
|
+
* ```
|
|
70
|
+
*
|
|
71
|
+
*/
|
|
72
|
+
const transliterate = (text, schema) => {
|
|
73
|
+
const transSchema = schema instanceof schema_1.Schema ? schema : new schema_1.SBL(schema !== null && schema !== void 0 ? schema : {});
|
|
74
|
+
const newText = text instanceof havarotjs_1.Text ? text : new havarotjs_1.Text(text, getSylOpts(transSchema !== null && transSchema !== void 0 ? transSchema : {}));
|
|
75
|
+
return newText.words
|
|
76
|
+
.map((word) => {
|
|
77
|
+
var _a, _b;
|
|
78
|
+
let transliteration = (0, rules_1.wordRules)(word, transSchema);
|
|
79
|
+
if (transliteration instanceof word_1.Word) {
|
|
80
|
+
transliteration = word.syllables
|
|
81
|
+
.map((s) => (0, rules_1.sylRules)(s, transSchema))
|
|
82
|
+
.join((_a = transSchema.SYLLABLE_SEPARATOR) !== null && _a !== void 0 ? _a : "");
|
|
83
|
+
}
|
|
84
|
+
return `${transliteration}${(_b = word.whiteSpaceAfter) !== null && _b !== void 0 ? _b : ""}`;
|
|
85
|
+
})
|
|
86
|
+
.join("");
|
|
87
|
+
};
|
|
88
|
+
exports.transliterate = transliterate;
|
package/package.json
CHANGED
|
@@ -1,12 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hebrew-transliteration",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "a package for transliterating Hebrew",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
-
"
|
|
7
|
-
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"require": "./dist/index.js"
|
|
10
|
+
},
|
|
11
|
+
"./schemas": {
|
|
12
|
+
"types": "./dist/schemas/index.d.ts",
|
|
13
|
+
"require": "./dist/schemas/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"typesVersions": {
|
|
17
|
+
"*": {
|
|
18
|
+
"schemas": [
|
|
19
|
+
"./dist/schemas/index.d.ts"
|
|
20
|
+
]
|
|
21
|
+
}
|
|
22
|
+
},
|
|
8
23
|
"scripts": {
|
|
9
|
-
"build": "
|
|
24
|
+
"build": "tsc",
|
|
10
25
|
"test": "clear && jest",
|
|
11
26
|
"format": "prettier --write 'src/**/*.ts' 'test/**/*.ts'",
|
|
12
27
|
"lint": "eslint . --ext .ts",
|
|
@@ -37,22 +52,22 @@
|
|
|
37
52
|
"author": "Charles Loder",
|
|
38
53
|
"license": "MIT",
|
|
39
54
|
"devDependencies": {
|
|
40
|
-
"@types/jest": "^29.
|
|
41
|
-
"@typescript-eslint/eslint-plugin": "^5.38.
|
|
42
|
-
"esbuild": "^0.15.
|
|
55
|
+
"@types/jest": "^29.1.1",
|
|
56
|
+
"@typescript-eslint/eslint-plugin": "^5.38.1",
|
|
57
|
+
"esbuild": "^0.15.10",
|
|
43
58
|
"eslint": "^8.24.0",
|
|
44
59
|
"eslint-config-prettier": "^8.5.0",
|
|
45
60
|
"eslint-plugin-jest": "^27.0.4",
|
|
46
61
|
"eslint-plugin-jsdoc": "^39.3.6",
|
|
47
62
|
"eslint-plugin-prefer-arrow": "^1.2.3",
|
|
48
|
-
"jest": "^29.
|
|
49
|
-
"npm-check-updates": "^16.3.
|
|
63
|
+
"jest": "^29.1.2",
|
|
64
|
+
"npm-check-updates": "^16.3.7",
|
|
50
65
|
"npm-dts": "^1.3.12",
|
|
51
66
|
"prettier": "^2.7.1",
|
|
52
|
-
"ts-jest": "^29.0.
|
|
53
|
-
"typescript": "^4.8.
|
|
67
|
+
"ts-jest": "^29.0.3",
|
|
68
|
+
"typescript": "^4.8.4"
|
|
54
69
|
},
|
|
55
70
|
"dependencies": {
|
|
56
|
-
"havarotjs": "^0.9.
|
|
71
|
+
"havarotjs": "^0.9.2"
|
|
57
72
|
}
|
|
58
73
|
}
|
package/dist/index.esm.js
DELETED
|
@@ -1,406 +0,0 @@
|
|
|
1
|
-
// src/index.ts
|
|
2
|
-
import { Text as Text3 } from "havarotjs";
|
|
3
|
-
|
|
4
|
-
// src/rules.ts
|
|
5
|
-
import { Cluster } from "havarotjs/dist/cluster";
|
|
6
|
-
|
|
7
|
-
// src/hebCharsTrans.ts
|
|
8
|
-
var transliterateMap = {
|
|
9
|
-
"\u05B0": "VOCAL_SHEVA",
|
|
10
|
-
"\u05B1": "HATAF_SEGOL",
|
|
11
|
-
"\u05B2": "HATAF_PATAH",
|
|
12
|
-
"\u05B3": "HATAF_QAMATS",
|
|
13
|
-
"\u05B4": "HIRIQ",
|
|
14
|
-
"\u05B5": "TSERE",
|
|
15
|
-
"\u05B6": "SEGOL",
|
|
16
|
-
"\u05B7": "PATAH",
|
|
17
|
-
"\u05B8": "QAMATS",
|
|
18
|
-
"\u05B9": "HOLAM",
|
|
19
|
-
"\u05BA": "HOLAM",
|
|
20
|
-
"\u05BB": "QUBUTS",
|
|
21
|
-
"\u05BC": "DAGESH",
|
|
22
|
-
"\u05BE": "MAQAF",
|
|
23
|
-
"\u05C0": "PASEQ",
|
|
24
|
-
"\u05C3": "SOF_PASUQ",
|
|
25
|
-
"\u05C7": "QAMATS_QATAN",
|
|
26
|
-
\u05D0: "ALEF",
|
|
27
|
-
\u05D1: "BET",
|
|
28
|
-
\u05D2: "GIMEL",
|
|
29
|
-
\u05D3: "DALET",
|
|
30
|
-
\u05D4: "HE",
|
|
31
|
-
\u05D5: "VAV",
|
|
32
|
-
\u05D6: "ZAYIN",
|
|
33
|
-
\u05D7: "HET",
|
|
34
|
-
\u05D8: "TET",
|
|
35
|
-
\u05D9: "YOD",
|
|
36
|
-
\u05DA: "FINAL_KAF",
|
|
37
|
-
\u05DB: "KAF",
|
|
38
|
-
\u05DC: "LAMED",
|
|
39
|
-
\u05DD: "FINAL_MEM",
|
|
40
|
-
\u05DE: "MEM",
|
|
41
|
-
\u05DF: "FINAL_NUN",
|
|
42
|
-
\u05E0: "NUN",
|
|
43
|
-
\u05E1: "SAMEKH",
|
|
44
|
-
\u05E2: "AYIN",
|
|
45
|
-
\u05E3: "FINAL_PE",
|
|
46
|
-
\u05E4: "PE",
|
|
47
|
-
\u05E5: "FINAL_TSADI",
|
|
48
|
-
\u05E6: "TSADI",
|
|
49
|
-
\u05E7: "QOF",
|
|
50
|
-
\u05E8: "RESH",
|
|
51
|
-
\u05E9: "SHIN",
|
|
52
|
-
\u05EA: "TAV"
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
// src/mapChars.ts
|
|
56
|
-
var mapChars = (text, schema) => [...text].map((char) => char in transliterateMap ? schema[transliterateMap[char]] : char).join("");
|
|
57
|
-
|
|
58
|
-
// src/rules.ts
|
|
59
|
-
var taamim = /[\u{0590}-\u{05AF}\u{05BD}\u{05BF}]/u;
|
|
60
|
-
var changeElementSplit = (input, split, join) => input.split(split).join(join);
|
|
61
|
-
var consonantFeatures = (clusterText, syl, cluster, schema) => {
|
|
62
|
-
var _a;
|
|
63
|
-
if ((_a = schema.ADDITIONAL_FEATURES) == null ? void 0 : _a.length) {
|
|
64
|
-
const clusterSeqs = schema.ADDITIONAL_FEATURES.filter((s) => s.FEATURE === "cluster");
|
|
65
|
-
for (const seq of clusterSeqs) {
|
|
66
|
-
const heb = new RegExp(seq.HEBREW, "u");
|
|
67
|
-
if (heb.test(clusterText)) {
|
|
68
|
-
const sylSeq = changeElementSplit(clusterText, heb, seq.TRANSLITERATION);
|
|
69
|
-
return [...sylSeq].map((char) => mapChars(char, schema)).join("");
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
clusterText = cluster.hasShewa && syl.isClosed ? clusterText.replace(/\u{05B0}/u, "") : clusterText;
|
|
74
|
-
if (/ה\u{05BC}$/mu.test(clusterText)) {
|
|
75
|
-
return changeElementSplit(clusterText, /ה\u{05BC}/u, schema.HE);
|
|
76
|
-
}
|
|
77
|
-
if (syl.isFinal && !syl.isClosed) {
|
|
78
|
-
const furtiveChet = /\u{05D7}\u{05B7}$/mu;
|
|
79
|
-
if (furtiveChet.test(clusterText)) {
|
|
80
|
-
return changeElementSplit(clusterText, furtiveChet, "\u05B7\u05D7");
|
|
81
|
-
}
|
|
82
|
-
const furtiveAyin = /\u{05E2}\u{05B7}$/mu;
|
|
83
|
-
if (furtiveAyin.test(clusterText)) {
|
|
84
|
-
return changeElementSplit(clusterText, furtiveAyin, "\u05B7\u05E2");
|
|
85
|
-
}
|
|
86
|
-
const furtiveHe = /\u{05D4}\u{05BC}\u{05B7}$/mu;
|
|
87
|
-
if (furtiveHe.test(clusterText)) {
|
|
88
|
-
return changeElementSplit(clusterText, furtiveHe, "\u05B7\u05D4\u05BC");
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
const prevHasVowel = cluster.prev instanceof Cluster ? cluster.prev.hasVowel : false;
|
|
92
|
-
const isDoubled = schema.DAGESH_CHAZAQ && prevHasVowel && /\u{05BC}/u.test(clusterText);
|
|
93
|
-
if (schema.BET_DAGESH && /ב\u{05BC}/u.test(clusterText)) {
|
|
94
|
-
return changeElementSplit(clusterText, /ב\u{05BC}/u, schema.BET_DAGESH.repeat(isDoubled ? 2 : 1));
|
|
95
|
-
}
|
|
96
|
-
if (schema.GIMEL_DAGESH && /ג\u{05BC}/u.test(clusterText)) {
|
|
97
|
-
return changeElementSplit(clusterText, /ג\u{05BC}/u, schema.GIMEL_DAGESH.repeat(isDoubled ? 2 : 1));
|
|
98
|
-
}
|
|
99
|
-
if (schema.DALET_DAGESH && /ד\u{05BC}/u.test(clusterText)) {
|
|
100
|
-
return changeElementSplit(clusterText, /ד\u{05BC}/u, schema.DALET_DAGESH.repeat(isDoubled ? 2 : 1));
|
|
101
|
-
}
|
|
102
|
-
if (schema.KAF_DAGESH && /כ\u{05BC}/u.test(clusterText)) {
|
|
103
|
-
return changeElementSplit(clusterText, /כ\u{05BC}/u, schema.KAF_DAGESH.repeat(isDoubled ? 2 : 1));
|
|
104
|
-
}
|
|
105
|
-
if (schema.KAF_DAGESH && /ך\u{05BC}/u.test(clusterText)) {
|
|
106
|
-
return changeElementSplit(clusterText, /ך\u{05BC}/u, schema.KAF_DAGESH.repeat(isDoubled ? 2 : 1));
|
|
107
|
-
}
|
|
108
|
-
if (schema.PE_DAGESH && /פ\u{05BC}/u.test(clusterText)) {
|
|
109
|
-
return changeElementSplit(clusterText, /פ\u{05BC}/u, schema.PE_DAGESH.repeat(isDoubled ? 2 : 1));
|
|
110
|
-
}
|
|
111
|
-
if (schema.TAV_DAGESH && /ת\u{05BC}/u.test(clusterText)) {
|
|
112
|
-
return changeElementSplit(clusterText, /ת\u{05BC}/u, schema.TAV_DAGESH.repeat(isDoubled ? 2 : 1));
|
|
113
|
-
}
|
|
114
|
-
if (/ש\u{05C1}/u.test(clusterText)) {
|
|
115
|
-
return changeElementSplit(clusterText, /ש\u{05C1}/u, schema.SHIN.repeat(isDoubled ? 2 : 1));
|
|
116
|
-
}
|
|
117
|
-
if (/ש\u{05C2}/u.test(clusterText)) {
|
|
118
|
-
return changeElementSplit(clusterText, /ש\u{05C2}/u, schema.SIN.repeat(isDoubled ? 2 : 1));
|
|
119
|
-
}
|
|
120
|
-
if (isDoubled) {
|
|
121
|
-
const consonant = cluster.chars[0].text;
|
|
122
|
-
const consonantDagesh = new RegExp(consonant + "\u05BC", "u");
|
|
123
|
-
return changeElementSplit(clusterText, consonantDagesh, `${consonant + consonant}`);
|
|
124
|
-
}
|
|
125
|
-
if (cluster.isShureq) {
|
|
126
|
-
return schema.SHUREQ;
|
|
127
|
-
}
|
|
128
|
-
return clusterText;
|
|
129
|
-
};
|
|
130
|
-
var materFeatures = (syl, schema) => {
|
|
131
|
-
const mater = syl.clusters.filter((c) => c.isMater)[0];
|
|
132
|
-
const prev = mater.prev instanceof Cluster ? mater.prev : null;
|
|
133
|
-
const materText = mater.text;
|
|
134
|
-
const prevText = ((prev == null ? void 0 : prev.text) || "").replace(taamim, "");
|
|
135
|
-
let noMaterText = syl.clusters.filter((c) => !c.isMater).map((c) => consonantFeatures(c.text.replace(taamim, ""), syl, c, schema)).join("");
|
|
136
|
-
const hasMaqaf = mater.text.includes("\u05BE");
|
|
137
|
-
noMaterText = hasMaqaf ? noMaterText.concat("\u05BE") : noMaterText;
|
|
138
|
-
if (/י/.test(materText)) {
|
|
139
|
-
if (/\u{05B4}/u.test(prevText)) {
|
|
140
|
-
return changeElementSplit(noMaterText, /\u{05B4}/u, schema.HIRIQ_YOD);
|
|
141
|
-
}
|
|
142
|
-
if (/\u{05B5}/u.test(prevText)) {
|
|
143
|
-
return changeElementSplit(noMaterText, /\u{05B5}/u, schema.TSERE_YOD);
|
|
144
|
-
}
|
|
145
|
-
if (/\u{05B6}/u.test(prevText)) {
|
|
146
|
-
return changeElementSplit(noMaterText, /\u{05B6}/u, schema.SEGOL_YOD);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
if (/ו/u.test(materText)) {
|
|
150
|
-
if (/\u{05B9}/u.test(prevText)) {
|
|
151
|
-
return changeElementSplit(noMaterText, /\u{05B9}/u, schema.HOLAM_VAV);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
if (/ה/.test(materText)) {
|
|
155
|
-
if (/\u{05B8}/u.test(prevText)) {
|
|
156
|
-
return changeElementSplit(noMaterText, /\u{05B8}/u, schema.QAMATS_HE);
|
|
157
|
-
}
|
|
158
|
-
if (/\u{05B6}/u.test(prevText)) {
|
|
159
|
-
return changeElementSplit(noMaterText, /\u{05B6}/u, schema.SEGOL_HE);
|
|
160
|
-
}
|
|
161
|
-
if (/\u{05B5}/u.test(prevText)) {
|
|
162
|
-
return changeElementSplit(noMaterText, /\u{05B5}/u, schema.SEGOL_HE);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
return materText;
|
|
166
|
-
};
|
|
167
|
-
var joinChars = (isAccented, sylChars, schema) => {
|
|
168
|
-
if (!isAccented) {
|
|
169
|
-
return sylChars.map((char) => mapChars(char, schema)).join("");
|
|
170
|
-
}
|
|
171
|
-
if (schema.STRESS_MARKER) {
|
|
172
|
-
const location = schema.STRESS_MARKER.location;
|
|
173
|
-
const mark = schema.STRESS_MARKER.mark;
|
|
174
|
-
if (location === "before-syllable") {
|
|
175
|
-
return `${mark}${sylChars.map((char) => mapChars(char, schema)).join("")}`;
|
|
176
|
-
}
|
|
177
|
-
if (location === "after-syllable") {
|
|
178
|
-
return `${sylChars.map((char) => mapChars(char, schema)).join("")}${mark}`;
|
|
179
|
-
}
|
|
180
|
-
const vowels3 = [
|
|
181
|
-
schema.PATAH,
|
|
182
|
-
schema.HATAF_PATAH,
|
|
183
|
-
schema.QAMATS,
|
|
184
|
-
schema.HATAF_QAMATS,
|
|
185
|
-
schema.SEGOL,
|
|
186
|
-
schema.HATAF_SEGOL,
|
|
187
|
-
schema.TSERE,
|
|
188
|
-
schema.HIRIQ,
|
|
189
|
-
schema.HOLAM,
|
|
190
|
-
schema.QAMATS_QATAN,
|
|
191
|
-
schema.QUBUTS,
|
|
192
|
-
schema.QAMATS_HE,
|
|
193
|
-
schema.SEGOL_HE,
|
|
194
|
-
schema.TSERE_HE,
|
|
195
|
-
schema.HIRIQ_YOD,
|
|
196
|
-
schema.TSERE_YOD,
|
|
197
|
-
schema.SEGOL_YOD,
|
|
198
|
-
schema.HOLAM_VAV,
|
|
199
|
-
schema.SHUREQ
|
|
200
|
-
].sort((a, b) => b.length - a.length);
|
|
201
|
-
const vowelRgx = new RegExp(`${vowels3.join("|")}`);
|
|
202
|
-
const str = sylChars.map((char) => mapChars(char, schema)).join("");
|
|
203
|
-
const match = str.match(vowelRgx);
|
|
204
|
-
if (location === "before-vowel") {
|
|
205
|
-
return (match == null ? void 0 : match.length) ? str.replace(match[0], `${mark}${match[0]}`) : str;
|
|
206
|
-
}
|
|
207
|
-
return (match == null ? void 0 : match.length) ? str.replace(match[0], `${match[0]}${mark}`) : str;
|
|
208
|
-
}
|
|
209
|
-
return sylChars.map((char) => mapChars(char, schema)).join("");
|
|
210
|
-
};
|
|
211
|
-
var sylRules = (syl, schema) => {
|
|
212
|
-
var _a;
|
|
213
|
-
const sylTxt = syl.text.replace(taamim, "");
|
|
214
|
-
if ((_a = schema.ADDITIONAL_FEATURES) == null ? void 0 : _a.length) {
|
|
215
|
-
const sylSeqs = schema.ADDITIONAL_FEATURES.filter((s) => s.FEATURE === "syllable");
|
|
216
|
-
for (const seq of sylSeqs) {
|
|
217
|
-
const heb = new RegExp(seq.HEBREW, "u");
|
|
218
|
-
if (heb.test(sylTxt)) {
|
|
219
|
-
const wordSeq = changeElementSplit(sylTxt, heb, seq.TRANSLITERATION);
|
|
220
|
-
return joinChars(syl.isAccented, [...wordSeq], schema);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
const mSSuffix = /\u{05B8}\u{05D9}\u{05D5}/u;
|
|
225
|
-
if (syl.isFinal && mSSuffix.test(sylTxt)) {
|
|
226
|
-
const sufxSyl = changeElementSplit(sylTxt, mSSuffix, schema.MS_SUFX);
|
|
227
|
-
return joinChars(syl.isAccented, [...sufxSyl], schema);
|
|
228
|
-
}
|
|
229
|
-
const hasMater = syl.clusters.map((c) => c.isMater).includes(true);
|
|
230
|
-
if (hasMater) {
|
|
231
|
-
const materSyl = materFeatures(syl, schema);
|
|
232
|
-
return joinChars(syl.isAccented, [...materSyl], schema);
|
|
233
|
-
}
|
|
234
|
-
const returnTxt = syl.clusters.map((cluster) => {
|
|
235
|
-
const clusterText = cluster.text.replace(taamim, "");
|
|
236
|
-
return consonantFeatures(clusterText, syl, cluster, schema);
|
|
237
|
-
});
|
|
238
|
-
return joinChars(syl.isAccented, returnTxt, schema);
|
|
239
|
-
};
|
|
240
|
-
var wordRules = (word, schema) => {
|
|
241
|
-
var _a;
|
|
242
|
-
if (word.isDivineName)
|
|
243
|
-
return schema.DIVINE_NAME;
|
|
244
|
-
if (word.hasDivineName)
|
|
245
|
-
return `${sylRules(word.syllables[0], schema)}-${schema.DIVINE_NAME}`;
|
|
246
|
-
if (word.isNotHebrew)
|
|
247
|
-
return word.text;
|
|
248
|
-
if ((_a = schema.ADDITIONAL_FEATURES) == null ? void 0 : _a.length) {
|
|
249
|
-
const wordSeqs = schema.ADDITIONAL_FEATURES.filter((s) => s.FEATURE === "word");
|
|
250
|
-
for (const seq of wordSeqs) {
|
|
251
|
-
const heb = new RegExp(seq.HEBREW, "u");
|
|
252
|
-
const wordText = word.text.replace(taamim, "");
|
|
253
|
-
if (heb.test(wordText)) {
|
|
254
|
-
const wordSeq = changeElementSplit(wordText, heb, seq.TRANSLITERATION);
|
|
255
|
-
return [...wordSeq].map((char) => mapChars(char, schema)).join("");
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
return word;
|
|
260
|
-
};
|
|
261
|
-
|
|
262
|
-
// src/schema.ts
|
|
263
|
-
var Schema = class {
|
|
264
|
-
constructor(schema) {
|
|
265
|
-
this.VOCAL_SHEVA = schema.VOCAL_SHEVA, this.HATAF_SEGOL = schema.HATAF_SEGOL, this.HATAF_PATAH = schema.HATAF_PATAH, this.HATAF_QAMATS = schema.HATAF_QAMATS, this.HIRIQ = schema.HIRIQ, this.TSERE = schema.TSERE, this.SEGOL = schema.SEGOL, this.PATAH = schema.PATAH, this.QAMATS = schema.QAMATS, this.HOLAM = schema.HOLAM, this.QUBUTS = schema.QUBUTS, this.DAGESH = schema.DAGESH, this.DAGESH_CHAZAQ = schema.DAGESH_CHAZAQ, this.MAQAF = schema.MAQAF, this.PASEQ = schema.PASEQ, this.SOF_PASUQ = schema.SOF_PASUQ, this.QAMATS_QATAN = schema.QAMATS_QATAN, this.FURTIVE_PATAH = schema.FURTIVE_PATAH, this.HIRIQ_YOD = schema.HIRIQ_YOD, this.TSERE_YOD = schema.TSERE_YOD, this.SEGOL_YOD = schema.SEGOL_YOD, this.SHUREQ = schema.SHUREQ, this.HOLAM_VAV = schema.HOLAM_VAV, this.QAMATS_HE = schema.QAMATS_HE, this.SEGOL_HE = schema.SEGOL_HE, this.TSERE_HE = schema.TSERE_HE, this.MS_SUFX = schema.MS_SUFX, this.ALEF = schema.ALEF, this.BET_DAGESH = schema.BET_DAGESH, this.BET = schema.BET, this.GIMEL = schema.GIMEL, this.GIMEL_DAGESH = schema.GIMEL_DAGESH, this.DALET = schema.DALET, this.DALET_DAGESH = schema.DALET_DAGESH, this.HE = schema.HE, this.VAV = schema.VAV, this.ZAYIN = schema.ZAYIN, this.HET = schema.HET, this.TET = schema.TET, this.YOD = schema.YOD, this.FINAL_KAF = schema.FINAL_KAF, this.KAF = schema.KAF, this.KAF_DAGESH = schema.KAF_DAGESH, this.LAMED = schema.LAMED, this.FINAL_MEM = schema.FINAL_MEM, this.MEM = schema.MEM, this.FINAL_NUN = schema.FINAL_NUN, this.NUN = schema.NUN, this.SAMEKH = schema.SAMEKH, this.AYIN = schema.AYIN, this.FINAL_PE = schema.FINAL_PE, this.PE = schema.PE, this.PE_DAGESH = schema.PE_DAGESH, this.FINAL_TSADI = schema.FINAL_TSADI, this.TSADI = schema.TSADI, this.QOF = schema.QOF, this.RESH = schema.RESH, this.SHIN = schema.SHIN, this.SIN = schema.SIN, this.TAV = schema.TAV, this.TAV_DAGESH = schema.TAV_DAGESH, this.DIVINE_NAME = schema.DIVINE_NAME, this.SYLLABLE_SEPARATOR = schema.SYLLABLE_SEPARATOR, this.ADDITIONAL_FEATURES = schema.ADDITIONAL_FEATURES, this.STRESS_MARKER = schema.STRESS_MARKER, this.longVowels = schema.longVowels, this.qametsQatan = schema.qametsQatan, this.sqnmlvy = schema.sqnmlvy, this.wawShureq = schema.wawShureq, this.article = schema.article;
|
|
266
|
-
this.allowNoNiqqud = schema.allowNoNiqqud;
|
|
267
|
-
}
|
|
268
|
-
};
|
|
269
|
-
var SBL = class extends Schema {
|
|
270
|
-
constructor(schema) {
|
|
271
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
272
|
-
super({
|
|
273
|
-
VOCAL_SHEVA: schema.VOCAL_SHEVA || "\u01DD",
|
|
274
|
-
HATAF_SEGOL: schema.HATAF_SEGOL || "\u0115",
|
|
275
|
-
HATAF_PATAH: schema.HATAF_PATAH || "\u0103",
|
|
276
|
-
HATAF_QAMATS: schema.HATAF_QAMATS || "\u014F",
|
|
277
|
-
HIRIQ: schema.HIRIQ || "i",
|
|
278
|
-
TSERE: schema.TSERE || "\u0113",
|
|
279
|
-
SEGOL: schema.SEGOL || "e",
|
|
280
|
-
PATAH: schema.PATAH || "a",
|
|
281
|
-
QAMATS: schema.QAMATS || "\u0101",
|
|
282
|
-
HOLAM: schema.HOLAM || "\u014D",
|
|
283
|
-
QUBUTS: schema.QUBUTS || "\u016B",
|
|
284
|
-
DAGESH: schema.DAGESH || "",
|
|
285
|
-
DAGESH_CHAZAQ: (_a = schema.DAGESH_CHAZAQ) != null ? _a : true,
|
|
286
|
-
MAQAF: schema.MAQAF || "-",
|
|
287
|
-
PASEQ: schema.PASEQ || "",
|
|
288
|
-
SOF_PASUQ: schema.SOF_PASUQ || "",
|
|
289
|
-
QAMATS_QATAN: schema.QAMATS_QATAN || "o",
|
|
290
|
-
FURTIVE_PATAH: schema.FURTIVE_PATAH || "a",
|
|
291
|
-
HIRIQ_YOD: schema.HIRIQ_YOD || "\xEE",
|
|
292
|
-
TSERE_YOD: schema.TSERE_YOD || "\xEA",
|
|
293
|
-
SEGOL_YOD: schema.SEGOL_YOD || "\xEA",
|
|
294
|
-
SHUREQ: schema.SHUREQ || "\xFB",
|
|
295
|
-
HOLAM_VAV: schema.HOLAM_VAV || "\xF4",
|
|
296
|
-
QAMATS_HE: schema.QAMATS_HE || "\xE2",
|
|
297
|
-
SEGOL_HE: schema.SEGOL_HE || "\xEA",
|
|
298
|
-
TSERE_HE: schema.TSERE_HE || "\xEA",
|
|
299
|
-
MS_SUFX: schema.MS_SUFX || "\u0101yw",
|
|
300
|
-
ALEF: schema.ALEF || "\u02BE",
|
|
301
|
-
BET: schema.BET || "b",
|
|
302
|
-
BET_DAGESH: schema.BET_DAGESH || void 0,
|
|
303
|
-
GIMEL: schema.GIMEL || "g",
|
|
304
|
-
GIMEL_DAGESH: schema.GIMEL_DAGESH || void 0,
|
|
305
|
-
DALET: schema.DALET || "d",
|
|
306
|
-
DALET_DAGESH: schema.DALET_DAGESH || void 0,
|
|
307
|
-
HE: schema.HE || "h",
|
|
308
|
-
VAV: schema.VAV || "w",
|
|
309
|
-
ZAYIN: schema.ZAYIN || "z",
|
|
310
|
-
HET: schema.HET || "\u1E25",
|
|
311
|
-
TET: schema.TET || "\u1E6D",
|
|
312
|
-
YOD: schema.YOD || "y",
|
|
313
|
-
FINAL_KAF: schema.FINAL_KAF || "k",
|
|
314
|
-
KAF: schema.KAF || "k",
|
|
315
|
-
KAF_DAGESH: schema.KAF_DAGESH || void 0,
|
|
316
|
-
LAMED: schema.LAMED || "l",
|
|
317
|
-
FINAL_MEM: schema.FINAL_MEM || "m",
|
|
318
|
-
MEM: schema.MEM || "m",
|
|
319
|
-
FINAL_NUN: schema.FINAL_NUN || "n",
|
|
320
|
-
NUN: schema.NUN || "n",
|
|
321
|
-
SAMEKH: schema.SAMEKH || "s",
|
|
322
|
-
AYIN: schema.AYIN || "\u02BF",
|
|
323
|
-
FINAL_PE: schema.FINAL_PE || "p",
|
|
324
|
-
PE: schema.PE || "p",
|
|
325
|
-
PE_DAGESH: schema.PE_DAGESH || void 0,
|
|
326
|
-
FINAL_TSADI: schema.FINAL_TSADI || "\u1E63",
|
|
327
|
-
TSADI: schema.TSADI || "\u1E63",
|
|
328
|
-
QOF: schema.QOF || "q",
|
|
329
|
-
RESH: schema.RESH || "r",
|
|
330
|
-
SHIN: schema.SHIN || "\u0161",
|
|
331
|
-
SIN: schema.SIN || "\u015B",
|
|
332
|
-
TAV: schema.TAV || "t",
|
|
333
|
-
TAV_DAGESH: schema.TAV_DAGESH || void 0,
|
|
334
|
-
DIVINE_NAME: schema.DIVINE_NAME || "yhwh",
|
|
335
|
-
SYLLABLE_SEPARATOR: schema.SYLLABLE_SEPARATOR || void 0,
|
|
336
|
-
ADDITIONAL_FEATURES: schema.ADDITIONAL_FEATURES || void 0,
|
|
337
|
-
STRESS_MARKER: schema.STRESS_MARKER || void 0,
|
|
338
|
-
longVowels: (_b = schema.longVowels) != null ? _b : true,
|
|
339
|
-
qametsQatan: (_c = schema.qametsQatan) != null ? _c : true,
|
|
340
|
-
sqnmlvy: (_d = schema.sqnmlvy) != null ? _d : true,
|
|
341
|
-
wawShureq: (_e = schema.wawShureq) != null ? _e : true,
|
|
342
|
-
article: (_f = schema.article) != null ? _f : true,
|
|
343
|
-
allowNoNiqqud: (_g = schema.allowNoNiqqud) != null ? _g : true
|
|
344
|
-
});
|
|
345
|
-
}
|
|
346
|
-
};
|
|
347
|
-
|
|
348
|
-
// src/transliterate.ts
|
|
349
|
-
import { Text } from "havarotjs";
|
|
350
|
-
import { Word } from "havarotjs/dist/word";
|
|
351
|
-
var getSylOpts = (schema) => {
|
|
352
|
-
const options = {};
|
|
353
|
-
if ("longVowels" in schema)
|
|
354
|
-
options.longVowels = schema.longVowels;
|
|
355
|
-
if ("qametsQatan" in schema)
|
|
356
|
-
options.qametsQatan = schema.qametsQatan;
|
|
357
|
-
if ("sqnmlvy" in schema)
|
|
358
|
-
options.sqnmlvy = schema.sqnmlvy;
|
|
359
|
-
if ("wawShureq" in schema)
|
|
360
|
-
options.wawShureq = schema.wawShureq;
|
|
361
|
-
if ("article" in schema)
|
|
362
|
-
options.article = schema.article;
|
|
363
|
-
if ("allowNoNiqqud" in schema)
|
|
364
|
-
options.allowNoNiqqud = schema.allowNoNiqqud;
|
|
365
|
-
return options;
|
|
366
|
-
};
|
|
367
|
-
var transliterate = (text, schema) => {
|
|
368
|
-
const transSchema = schema instanceof Schema ? schema : new SBL(schema != null ? schema : {});
|
|
369
|
-
const newText = text instanceof Text ? text : new Text(text, getSylOpts(transSchema != null ? transSchema : {}));
|
|
370
|
-
return newText.words.map((word) => {
|
|
371
|
-
var _a, _b;
|
|
372
|
-
let transliteration = wordRules(word, transSchema);
|
|
373
|
-
if (transliteration instanceof Word) {
|
|
374
|
-
transliteration = word.syllables.map((s) => sylRules(s, transSchema)).join((_a = transSchema.SYLLABLE_SEPARATOR) != null ? _a : "");
|
|
375
|
-
}
|
|
376
|
-
return `${transliteration}${(_b = word.whiteSpaceAfter) != null ? _b : ""}`;
|
|
377
|
-
}).join("");
|
|
378
|
-
};
|
|
379
|
-
|
|
380
|
-
// src/sequence.ts
|
|
381
|
-
import { Text as Text2 } from "havarotjs";
|
|
382
|
-
var vowels = /[\u{05B0}-\u{05BC}\u{05C7}]/u;
|
|
383
|
-
var sequence = (text, qametsQatan = false) => {
|
|
384
|
-
return vowels.test(text) ? new Text2(text, { qametsQatan }).text : text;
|
|
385
|
-
};
|
|
386
|
-
|
|
387
|
-
// src/remove.ts
|
|
388
|
-
var cantillation = /[\u{0591}-\u{05AF}\u{05BF}\u{05C0}\u{05C3}-\u{05C6}\u{05F3}\u{05F4}]/gu;
|
|
389
|
-
var vowels2 = /[\u{05B0}-\u{05BD}\u{05BF}\u{05C7}]/gu;
|
|
390
|
-
var shinDot = /\u{05C1}/gu;
|
|
391
|
-
var sinDot = /\u{05C2}/gu;
|
|
392
|
-
var removeItem = (text, item) => text.replace(item, "");
|
|
393
|
-
var remove = (text, { removeVowels = false, removeShinDot = false, removeSinDot = false } = {}) => {
|
|
394
|
-
const sequenced = sequence(text);
|
|
395
|
-
const remCantillation = removeItem(sequenced, cantillation);
|
|
396
|
-
const remVowels = removeVowels ? removeItem(remCantillation, vowels2) : remCantillation;
|
|
397
|
-
const remShin = removeShinDot ? removeItem(remVowels, shinDot) : remVowels;
|
|
398
|
-
return removeSinDot ? removeItem(remShin, sinDot) : remShin;
|
|
399
|
-
};
|
|
400
|
-
export {
|
|
401
|
-
Schema,
|
|
402
|
-
Text3 as Text,
|
|
403
|
-
remove,
|
|
404
|
-
sequence,
|
|
405
|
-
transliterate
|
|
406
|
-
};
|