hebrew-transliteration
Version:
a package for transliterating Hebrew
76 lines (75 loc) • 3.04 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var transliterate_exports = {};
__export(transliterate_exports, {
transliterate: () => transliterate
});
module.exports = __toCommonJS(transliterate_exports);
var import_havarotjs = require("havarotjs");
var import_word = require("havarotjs/word");
var import_rules = require("./rules.js");
var import_schema = require("./schema.js");
const getSylOpts = (schema) => {
const options = {};
if ("longVowels" in schema)
options.longVowels = schema.longVowels;
if ("qametsQatan" in schema)
options.qametsQatan = schema.qametsQatan;
if ("sqnmlvy" in schema)
options.shevaAfterMeteg = schema.shevaAfterMeteg;
if ("sqnmlvy" in schema)
options.sqnmlvy = schema.sqnmlvy;
if ("wawShureq" in schema)
options.wawShureq = schema.wawShureq;
if ("article" in schema)
options.article = schema.article;
if ("allowNoNiqqud" in schema)
options.allowNoNiqqud = schema.allowNoNiqqud;
if ("strict" in schema)
options.strict = schema.strict;
return options;
};
const transliterate = (text, schema) => {
const transSchema = schema instanceof import_schema.Schema ? schema : new import_schema.SBL(schema != null ? schema : {});
const newText = text instanceof import_havarotjs.Text ? text : new import_havarotjs.Text(text, getSylOpts(transSchema != null ? transSchema : {}));
return newText.words.map((word) => {
var _a, _b;
const transliteration = (0, import_rules.wordRules)(word, transSchema);
if (!(transliteration instanceof import_word.Word)) {
return `${transliteration}${(_a = word.whiteSpaceAfter) != null ? _a : ""}`;
}
const syllableTransliteration = transliteration.syllables.map((s) => (0, import_rules.sylRules)(s, transSchema)).reduce((a, c, i) => {
if (!i) {
return a + c;
}
if (!transSchema.SYLLABLE_SEPARATOR) {
return a + c;
}
if (c.includes(transSchema.SYLLABLE_SEPARATOR)) {
return a + c;
}
return a + transSchema.SYLLABLE_SEPARATOR + c;
}, "");
return `${syllableTransliteration}${(_b = word.whiteSpaceAfter) != null ? _b : ""}`;
}).join("");
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
transliterate
});
//# sourceMappingURL=transliterate.js.map