tajweed-ts
Version:
Tajweed and buck parsing library.
289 lines (286 loc) • 8.44 kB
JavaScript
;
// src/index.ts
var Tajweed = class {
constructor() {
this.meta = [
{
identifier: "[h",
type: "hamza-wasl",
description: "Hamzat ul Wasl",
default_css_class: "ham_wasl",
html_color: "#AAAAAA"
},
{
identifier: "[s",
type: "silent",
description: "Silent",
default_css_class: "slnt",
html_color: "#AAAAAA"
},
{
identifier: "[l",
type: "laam-shamsiyah",
description: "Lam Shamsiyyah",
default_css_class: "slnt",
html_color: "#AAAAAA"
},
{
identifier: "[n",
type: "madda-normal",
description: "Normal Prolongation: 2 Vowels",
default_css_class: "madda_normal",
html_color: "#537FFF"
},
{
identifier: "[p",
type: "madda-permissible",
description: "Permissible Prolongation: 2, 4, 6 Vowels",
default_css_class: "madda_permissible",
html_color: "#4050FF"
},
{
identifier: "[m",
type: "madda-necesssary",
description: "Necessary Prolongation: 6 Vowels",
default_css_class: "madda_necessary",
html_color: "#000EBC"
},
{
identifier: "[q",
type: "qalaqah",
description: "Qalaqah",
default_css_class: "qlq",
html_color: "#DD0008"
},
{
identifier: "[o",
type: "madda-obligatory",
description: "Obligatory Prolongation: 4-5 Vowels",
default_css_class: "madda_pbligatory",
html_color: "#2144C1"
},
{
identifier: "[c",
type: "ikhafa-shafawi",
description: "Ikhafa' Shafawi - With Meem",
default_css_class: "ikhf_shfw",
html_color: "#D500B7"
},
{
identifier: "[f",
type: "ikhafa",
description: "Ikhafa'",
default_css_class: "ikhf",
html_color: "#9400A8"
},
{
identifier: "[w",
type: "idgham-shafawi",
description: "Idgham Shafawi - With Meem",
default_css_class: "idghm_shfw",
html_color: "#58B800"
},
{
identifier: "[i",
type: "iqlab",
description: "Iqlab",
default_css_class: "iqlb",
html_color: "#26BFFD"
},
{
identifier: "[a",
type: "idgham-without-ghunnah",
description: "Idgham - With Ghunnah",
default_css_class: "idgh_ghn",
html_color: "#169200"
},
{
identifier: "[u",
type: "idgham-without-ghunnah",
description: "Idgham - Without Ghunnah",
default_css_class: "idgh_w_ghn",
html_color: "#169200"
},
{
identifier: "[d",
type: "idgham-mutajanisayn",
description: "Idgham - Mutajanisayn",
default_css_class: "idgh_mus",
html_color: "#A1A1A1"
},
{
identifier: "[b",
type: "idgham-mutaqaribayn",
description: "Idgham - Mutaqaribayn",
default_css_class: "idgh_mus",
html_color: "#A1A1A1"
},
{
identifier: "[g",
type: "ghunnah",
description: "Ghunnah: 2 Vowels",
default_css_class: "ghn",
html_color: "#FF7E1E"
}
];
}
parse(text, fixWebkit = false) {
if (fixWebkit) {
return this.webkitFix(this.closeParsing(this.parseTajweed(text)));
}
return this.closeParsing(this.parseTajweed(text));
}
parseTajweed(text) {
var _a;
(_a = this.meta) == null ? void 0 : _a.forEach((meta) => {
const _re = new RegExp("(\\" + meta.identifier + ")", "ig");
text = text.replace(
_re,
`<tajweed class="${meta.default_css_class}" data-type="${meta.type}" data-description="${meta.description}" data-tajweed="`
);
});
return text;
}
webkitFix(text) {
text = text.replace("/</tajweed>(S)/", "‍${0}");
text = text.replace(
'/(S)<tajweed class="(.*?)" data-type="(.*?)" data-description="(.*?)" data-tajweed="(.*?)">(S)/',
'${1}<tajweed class="${2}" data-type="${3}" data-description="${4}" data-tajweed="${5}">‍‍${6}'
);
text = text.replaceAll("\u0671‍", "\u0671");
return text;
}
closeParsing(text) {
const re_1 = new RegExp("(\\[)", "ig");
text = text.replace(re_1, '">');
const re_2 = new RegExp("(\\])", "ig");
text = text.replace(re_2, "</tajweed>");
return text;
}
getMeta() {
return this.meta;
}
};
var Buck = class {
constructor() {
this.chars = "\u0622 \u0627 \u0628 \u062A \u062B \u062C \u062D \u062E \u062F \u0630 \u0631 \u0632 \u0633 \u0634 \u0635 \u0636 \u0637 \u0638 \u0639 \u063A \u0641 \u0642 \u0643 \u0644 \u0645 \u0646 \u0647 \u0648 \u064A";
this.buck = "A A b t v j H x d * r z s $ S D T Z E g f q k l m n h w y";
this.trans = "\u0101 \u0101 b t th j h kh d dh r z s sh \u1E63 \u1E0D \u1E6D \u1E93 \u02BF gh f q k l m n h w y";
this.charsArr = this.chars.split(" ");
this.buckArr = this.buck.split(" ");
this.transArr = this.trans.split(" ");
this.charsArr.push("\u0649");
this.buckArr.push("Y");
this.transArr.push("\u0101");
this.charsArr.push("\u0623");
this.buckArr.push(">");
this.transArr.push("");
this.charsArr.push("\u0625");
this.buckArr.push("<");
this.transArr.push("");
this.charsArr.push("\u0626");
this.buckArr.push("}");
this.transArr.push("");
this.charsArr.push("\u0621");
this.buckArr.push("X");
this.transArr.push("'");
this.charsArr.push("\u0624");
this.buckArr.push("&");
this.transArr.push(" ");
this.charsArr.push("\u0652");
this.buckArr.push("o");
this.transArr.push("'");
this.charsArr.push("\u064E");
this.buckArr.push("a");
this.transArr.push("a");
this.charsArr.push("\u0650");
this.buckArr.push("i");
this.transArr.push("i");
this.charsArr.push("\u064F");
this.buckArr.push("u");
this.transArr.push("");
this.charsArr.push("\u064B");
this.buckArr.push("F");
this.transArr.push("an");
this.charsArr.push("\u064D");
this.buckArr.push("K");
this.transArr.push("in");
this.charsArr.push("\u064C");
this.buckArr.push("N");
this.transArr.push("un");
this.charsArr.push("\u0626");
this.buckArr.push("}");
this.transArr.push("");
this.charsArr.push("\u0640");
this.buckArr.push("_");
this.transArr.push("");
this.charsArr.push("\u0651");
this.buckArr.push("~");
this.transArr.push("(double)");
this.charsArr.push("\u0653");
this.buckArr.push("^");
this.transArr.push("");
this.charsArr.push("\u0654");
this.buckArr.push("#");
this.transArr.push("");
this.charsArr.push("\u0671");
this.buckArr.push("{");
this.transArr.push("");
this.charsArr.push("\u0670");
this.buckArr.push("`");
this.transArr.push("");
this.charsArr.push("\u06E5");
this.buckArr.push(",");
this.transArr.push("");
this.charsArr.push("\u06E6");
this.buckArr.push(".");
this.transArr.push("");
this.charsArr.push("\u0629");
this.buckArr.push("p");
this.transArr.push("t");
this.charsArr.push("\u06DF");
this.buckArr.push("@");
this.transArr.push("");
this.charsArr.push("\u06E2");
this.buckArr.push("[");
this.transArr.push("");
this.charsArr.push("\u06ED");
this.buckArr.push("]");
this.transArr.push("");
this.charsArr.push("\u0621");
this.buckArr.push('"');
this.transArr.push("");
this.charsArr.push("\u06DC");
this.buckArr.push(":");
this.transArr.push("");
this.charsArr.push("\u06E0");
this.buckArr.push('"');
this.transArr.push("");
this.charsArr.push(" ");
this.buckArr.push(" ");
this.transArr.push(" ");
this.charsArr.push(";");
this.buckArr.push(";");
this.transArr.push("");
this.charsArr.push("\n");
this.buckArr.push("\n");
this.transArr.push("");
}
toArabic(text) {
let arabic = "";
const letters = text.split();
letters.forEach((letter) => {
const buckArrKey = this.buckArr.indexOf(letter);
if (buckArrKey !== -1) {
arabic += this.charsArr[buckArrKey];
} else {
if (!Number.isNaN(letter)) {
arabic += letter;
}
}
});
return arabic;
}
};
exports.Buck = Buck;
exports.Tajweed = Tajweed;