UNPKG

unicode-bunny

Version:

Convert Unicode Marathi (Devanagari) text to Shree 0708 legacy font encoding

31 lines (24 loc) 676 B
const mapping = require("./mapping.json"); function convert(inputText) { let output = ""; let i = 0; while (i < inputText.length) { let matched = false; // Try to match longest possible characters first (3, 2, then 1) for (let len = 3; len > 0; len--) { const substr = inputText.substr(i, len); if (mapping[substr]) { output += mapping[substr]; i += len; matched = true; break; } } if (!matched) { output += inputText[i]; i++; } } return output; } module.exports = { convert };