cal-phonetic
Version:
CAL code to Latin phonetic transliteration
124 lines (111 loc) • 3.83 kB
JavaScript
/**
* @file CAL code to Latin phonetic transliteration
* @version 1.0.3
* @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'), require('cal-code-util'), require('phonetic-code-util')) :
typeof define === 'function' && define.amd ? define(['exports', 'aramaic-mapper', 'cal-code-util', 'phonetic-code-util'], factory) :
(factory((global.calPhonetic = {}),global.aramaicMapper,global.calCodeUtil,global.phoneticCodeUtil));
}(this, (function (exports,aramaicMapper,calCodeUtil,phoneticCodeUtil) { 'use strict';
/** @module calPhonetic */
/**
* @private
* CAL source writing
* @const
* @type { Writing }
*/
var calWriting = new aramaicMapper.Writing(calCodeUtil.allConsonants, calCodeUtil.vowels);
/**
* @private
* Latin phonetic destination writing
* @const
* @type { Writing }
*/
var phoneticWriting = new aramaicMapper.Writing(
Object.freeze(phoneticCodeUtil.consonants.concat('p', 'ś')), // + Palestinian P and Hebrew Shin
Object.freeze(phoneticCodeUtil.commonVowels.concat(phoneticCodeUtil.easternVowels))
);
/**
* @private
* Customized mapping callback
* @param { string } word input word
* @param { number } i current index in the word
* @param { Object.<string, string> } fromTo mapping dictionary
* @returns { string } Latin mapped char
*/
var callback = function (word, i, fromTo) {
var c = word.charAt(i);
// Alap is silent always in present day pronunciation.
// Diacritics were processed already in prior iteration.
if (c === ')' || calCodeUtil.isDiacritic(c)) {
return '';
}
var n = word.charAt(i + 1);
var m;
switch (n) {
case ',':
m = phoneticCodeUtil.begadkepatMap[c];
if (m) {
return m;
}
break;
case '_':
return '';
case 'i':
case 'e':
if (c === 'y') {
return '';
}
break;
case 'u':
case 'O':
if (c === 'w') {
return '';
}
break;
default:
break;
}
return fromTo[c] || c;
};
/**
* Phonetic Mapper
* @const
* @type { Mapper }
*/
var mapper = new aramaicMapper.Mapper(calWriting, phoneticWriting, callback);
/**
* Convert from CAL to Phonetic Latin
* @static
* @param {string} word input word in CAL code transliteration
* @returns {string} the input word converted to phonetic Latin
*/
var toPhonetic = function (word) { return mapper.map(word); };
exports.mapper = mapper;
exports.toPhonetic = toPhonetic;
Object.defineProperty(exports, '__esModule', { value: true });
})));