sedra-cal
Version:
Convert from Sedra 3 to CAL ASCII transliteration
106 lines (96 loc) • 3.04 kB
JavaScript
import { Mapper, Writing } from 'aramaic-mapper';
import { consonants, consonantsByName, diacritics, isConsonant, vowels } from 'sedra-code-util';
import { commonVowels, consonants as consonants$1, diacritics as diacritics$1 } from 'cal-code-util';
/** @module sedraCal */
/**
* Aramaic mapper
* @const
* @type { Mapper }
*/
var mapper = new Mapper(
new Writing(consonants, vowels, diacritics),
new Writing(consonants$1, commonVowels, diacritics$1),
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) === consonantsByName.yod &&
(!word.charAt(i + 2) || isConsonant(word.charAt(i + 2)))
? 'yi' // Sedra stores as (iy)
: to();
break;
case 'e':
m =
word.charAt(i + 1) === consonantsByName.yod &&
(!word.charAt(i + 2) || isConsonant(word.charAt(i + 2)))
? 'ye' // Sedra stores as (ey)
: to();
break;
case 'u':
m =
word.charAt(i + 1) === consonantsByName.waw &&
(!word.charAt(i + 2) || isConsonant(word.charAt(i + 2)))
? 'wu' // Sedra stores as (uw)
: to();
break;
case 'o':
m =
word.charAt(i + 1) === consonantsByName.waw &&
(!word.charAt(i + 2) || 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 }
})
);
export { mapper, toCal, toCalMap };