sedra-cal
Version:
Convert from Sedra 3 to CAL ASCII transliteration
114 lines (102 loc) • 3.64 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('aramaic-mapper'), require('sedra-code-util'), require('cal-code-util')) :
typeof define === 'function' && define.amd ? define(['exports', 'aramaic-mapper', 'sedra-code-util', 'cal-code-util'], factory) :
(factory((global.sedraCal = {}),global.aramaicMapper,global.sedraCodeUtil,global.calCodeUtil));
}(this, (function (exports,aramaicMapper,sedraCodeUtil,calCodeUtil) { 'use strict';
/** @module sedraCal */
/**
* Aramaic mapper
* @const
* @type { Mapper }
*/
var mapper = new aramaicMapper.Mapper(
new aramaicMapper.Writing(sedraCodeUtil.consonants, sedraCodeUtil.vowels, sedraCodeUtil.diacritics),
new aramaicMapper.Writing(calCodeUtil.consonants, calCodeUtil.commonVowels, calCodeUtil.diacritics),
function (word, i, toFrom) {
var c = word.charAt(i);
var to = function () { return toFrom[c] || c; };
var m;
switch (c) {
case 'i':
m =
word.charAt(i + 1) === sedraCodeUtil.consonantsByName.yod &&
(!word.charAt(i + 2) || sedraCodeUtil.isConsonant(word.charAt(i + 2)))
? 'yi' // Sedra stores as (iy)
: to();
break;
case 'e':
m =
word.charAt(i + 1) === sedraCodeUtil.consonantsByName.yod &&
(!word.charAt(i + 2) || sedraCodeUtil.isConsonant(word.charAt(i + 2)))
? 'ye' // Sedra stores as (ey)
: to();
break;
case 'u':
m =
word.charAt(i + 1) === sedraCodeUtil.consonantsByName.waw &&
(!word.charAt(i + 2) || sedraCodeUtil.isConsonant(word.charAt(i + 2)))
? 'wu' // Sedra stores as (uw)
: to();
break;
case 'o':
m =
word.charAt(i + 1) === sedraCodeUtil.consonantsByName.waw &&
(!word.charAt(i + 2) || sedraCodeUtil.isConsonant(word.charAt(i + 2)))
? 'wO' // Eastern O stored as (ow) in Sedra
: to();
break;
default:
m = to();
break;
}
return m;
}
);
/**
* Convert from Sedra 3 to CAL Code transliteration
* @param {string} word input word in Sedra 3 transliteration
* @returns {string} the input word converted to CAL code representation
*/
var toCal = function (word) { return mapper.map(word); };
/**
* Sedra to CAL consonant map
* @constant
* @type { Object.<string, string> }
*/
var toCalMap = Object.freeze(
Object.create(null, {
// Abgad
A: { value: ')', enumerable: true },
B: { value: 'b', enumerable: true },
G: { value: 'g', enumerable: true },
D: { value: 'd', enumerable: true },
// Hawaz
H: { value: 'h', enumerable: true },
O: { value: 'w', enumerable: true },
Z: { value: 'z', enumerable: true },
// Ḥaṭy
K: { value: 'x', enumerable: true },
Y: { value: 'T', enumerable: true },
';': { value: 'y', enumerable: true },
// Kalman
C: { value: 'k', enumerable: true },
L: { value: 'l', enumerable: true },
M: { value: 'm', enumerable: true },
N: { value: 'n', enumerable: true },
// Saʿpac
S: { value: 's', enumerable: true },
E: { value: '(', enumerable: true },
I: { value: 'p', enumerable: true },
'/': { value: 'c', enumerable: true },
// Qarshat
X: { value: 'q', enumerable: true },
R: { value: 'r', enumerable: true },
W: { value: '$', enumerable: true },
T: { value: 't', enumerable: true }
})
);
exports.mapper = mapper;
exports.toCal = toCal;
exports.toCalMap = toCalMap;
Object.defineProperty(exports, '__esModule', { value: true });
})));