sedra-code-util
Version:
Sedra 3 ASCII code transliteration utilities
264 lines (233 loc) • 8.67 kB
JavaScript
/**
* @file Sedra 3 ASCII code transliteration utilities
* @version 1.0.8
* @author Greg Borota
* @copyright (c) 2017 Greg Borota.
* @license MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
// https://peshitta.github.io
// https://sedra.bethmardutho.org/about/fonts
// http://cal1.cn.huc.edu/searching/fullbrowser.html
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('aramaic-mapper')) :
typeof define === 'function' && define.amd ? define(['exports', 'aramaic-mapper'], factory) :
(factory((global.sedraCodeUtil = {}),global.aramaicMapper));
}(this, (function (exports,aramaicMapper) { 'use strict';
var obj;
/** @module sedraCodeUtil */
/**
* Sedra consonant name to value map
* @constant
* @type { Object.<string, string> }
*/
var consonantsByName = Object.freeze(
Object.create(null, {
alaph: { value: 'A', enumerable: true },
beth: { value: 'B', enumerable: true },
gamal: { value: 'G', enumerable: true },
dalath: { value: 'D', enumerable: true },
he: { value: 'H', enumerable: true },
waw: { value: 'O', enumerable: true },
zayn: { value: 'Z', enumerable: true },
heth: { value: 'K', enumerable: true },
teth: { value: 'Y', enumerable: true },
yod: { value: ';', enumerable: true },
kaph: { value: 'C', enumerable: true },
lamadh: { value: 'L', enumerable: true },
mim: { value: 'M', enumerable: true },
nun: { value: 'N', enumerable: true },
semkath: { value: 'S', enumerable: true },
e: { value: 'E', enumerable: true },
pe: { value: 'I', enumerable: true },
sadhe: { value: '/', enumerable: true },
qoph: { value: 'X', enumerable: true },
resh: { value: 'R', enumerable: true },
shin: { value: 'W', enumerable: true },
taw: { value: 'T', enumerable: true }
})
);
var l = consonantsByName;
/**
* Sedra consonants
* @constant
* @type { string[] }
*/
var consonants = Object.freeze([
l.alaph,
l.beth,
l.gamal,
l.dalath,
l.he,
l.waw,
l.zayn,
l.heth,
l.teth,
l.yod,
l.kaph,
l.lamadh,
l.mim,
l.nun,
l.semkath,
l.e,
l.pe,
l.sadhe,
l.qoph,
l.resh,
l.shin,
l.taw
]);
/**
* Sedra vowel name to value map
* @constant
* @type { Object.<string, string> }
*/
var vowelsByName = Object.freeze(
Object.create(null, {
pthaha: { value: 'a', enumerable: true },
zqapha: { value: 'o', enumerable: true },
rbasa: { value: 'e', enumerable: true },
hbasa: { value: 'i', enumerable: true },
esasa: { value: 'u', enumerable: true }
})
);
var v = vowelsByName;
/**
* Sedra vowels
* @constant
* @type { string[] }
*/
var vowels = Object.freeze([
v.pthaha,
v.zqapha,
v.rbasa,
v.hbasa,
v.esasa
]);
/**
* Sedra/CAL diacritic name map
* 1. qushaya: __'__ - dot above
* 2. rukkakha: __,__ - dot below
* 3. lineaOccultans: **_** - linea occultans
* 4. seyame: __*__ - seyame, rebwe
* @constant
* @type { Object.<string, string> }
*/
var diacriticsByName = Object.freeze(
Object.create(null, {
qushaya: { value: "'", enumerable: true },
rukkakha: { value: ',', enumerable: true },
lineaOccultans: { value: '_', enumerable: true },
seyame: { value: '*', enumerable: true }
})
);
var d = diacriticsByName;
/**
* Sedra/CAL diacritic characters:
* * __'__ dot above, Qushaya
* * __,__ dot below, Rukkakha
* * **_** line under
* * __*__ Seyame
* @constant
* @type { string[] }
*/
var diacritics = Object.freeze([
d.qushaya,
d.rukkakha,
d.lineaOccultans,
d.seyame
]);
/**
* CAL to ordinal ASCII value. Used for sorting:
* a b c d e f g h i j k l m n o p q r s t u v
* w x y z {
* @constant
* @type { Object.<string, string> }
*/
var letterAsciiMap = Object.freeze(
Object.create(null, ( obj = {}, obj[l.alaph] = { value: 'a', enumerable: true }, obj[l.beth] = { value: 'b', enumerable: true }, obj[l.gamal] = { value: 'c', enumerable: true }, obj[l.dalath] = { value: 'd', enumerable: true }, obj[l.he] = { value: 'e', enumerable: true }, obj[l.waw] = { value: 'f', enumerable: true }, obj[l.zayn] = { value: 'g', enumerable: true }, obj[l.heth] = { value: 'h', enumerable: true }, obj[l.teth] = { value: 'i', enumerable: true }, obj[l.yod] = { value: 'j', enumerable: true }, obj[l.kaph] = { value: 'k', enumerable: true }, obj[l.lamadh] = { value: 'l', enumerable: true }, obj[l.mim] = { value: 'm', enumerable: true }, obj[l.nun] = { value: 'n', enumerable: true }, obj[l.semkath] = { value: 'o', enumerable: true }, obj[l.e] = { value: 'p', enumerable: true }, obj[l.pe] = { value: 'q', enumerable: true }, obj[l.sadhe] = { value: 'r', enumerable: true }, obj[l.qoph] = { value: 's', enumerable: true }, obj[l.resh] = { value: 't', enumerable: true }, obj[l.shin] = { value: 'u', enumerable: true }, obj[l.taw] = { value: 'v', enumerable: true }, obj[v.pthaha] = { value: 'w', enumerable: true }, obj[v.zqapha] = { value: 'x', enumerable: true }, obj[v.rbasa] = { value: 'y', enumerable: true }, obj[v.hbasa] = { value: 'z', enumerable: true }, obj[v.esasa] = { value: '{', enumerable: true }, obj[d.qushaya] = { value: '', enumerable: true }, obj[d.rukkakha] = { value: ',', enumerable: true }, obj[d.lineaOccultans] = { value: '', enumerable: true }, obj[d.seyame] = { value: '', enumerable: true }, obj))
);
/**
* Vowels and diacritics: used for consonantal only mapping
* @constant
* @type { Array.<string> }
*/
var dotting = Object.freeze(vowels.concat(diacritics));
/**
* Is character c a Sedra 3 consonant?
* @param { string } c input character
* @returns { boolean } true if c is Sedra 3 consonant
*/
var isConsonant = function (c) { return consonants.indexOf(c) > -1; };
/**
* Is character c a Sedra 3 vowel?
* @param { string } c input character
* @returns { boolean } true if c is Sedra 3 vowel
*/
var isVowel = function (c) { return vowels.indexOf(c) > -1; };
/**
* Is character c a diacritic? Same characters used for both Sedra 3 and CAL.
* @param { string } c input character
* @returns { boolean } true if c is a diacritic
*/
var isDiacritic = function (c) { return diacritics.indexOf(c) > -1; };
/**
* Returns true if c is dotting character
* @param { string } c input character
* @returns { boolean } true if c is dotting
*/
var isDotting = function (c) { return dotting.indexOf(c) > -1; };
/**
* Return true if input word has vowels or diacritics
* @param { string } word input CAL code word
* @returns { boolean } true if word has vowels or diacritics
*/
var isDotted = aramaicMapper.hasDotting(isDotting);
/**
* Remove dotting (vowels and diacritics), leaving consonantal word only.
* @param { string } word input word to be processed
* @returns { string } consonantal word
*/
var removeDotting = aramaicMapper.clearDotting(isDotting);
/**
* Comparator function to be used for sorting words
* @static
* @param { string } word1 first word to compare
* @param { string } word2 second word to compare
* @returns { number } -1, 0, 1 depending on word sorting
*/
var sort = aramaicMapper.getSort(letterAsciiMap, isConsonant);
exports.consonantsByName = consonantsByName;
exports.consonants = consonants;
exports.vowelsByName = vowelsByName;
exports.vowels = vowels;
exports.diacriticsByName = diacriticsByName;
exports.diacritics = diacritics;
exports.letterAsciiMap = letterAsciiMap;
exports.dotting = dotting;
exports.isConsonant = isConsonant;
exports.isVowel = isVowel;
exports.isDiacritic = isDiacritic;
exports.isDotting = isDotting;
exports.isDotted = isDotted;
exports.removeDotting = removeDotting;
exports.sort = sort;
Object.defineProperty(exports, '__esModule', { value: true });
})));