@freeword/meta
Version:
Meta package for Freeword: exports all core types, constants, and utilities from the src/ directory.
17 lines • 925 B
JavaScript
const Rot13Map = {
a: 'n', b: 'o', c: 'p', d: 'q', e: 'r', f: 's', g: 't', h: 'u', i: 'v', j: 'w', k: 'x', l: 'y', m: 'z',
n: 'a', o: 'b', p: 'c', q: 'd', r: 'e', s: 'f', t: 'g', u: 'h', v: 'i', w: 'j', x: 'k', y: 'l', z: 'm',
};
/** ROT-13: trivially obscure/decode a string by mapping a->n, b->o, ..., m->z, n->a, ..., z->m. Installation is the reverse of removal. */
export function rot13Word(str) {
return str.toLowerCase().replace(/[a-z]/g, ((char) => Rot13Map[char]));
}
const Z = 'z'.charCodeAt(0);
/** ROT-13: trivially obscure/decode a string by mapping a->n, b->o, ..., m->z, n->a, ..., z->m. Installation is the reverse of removal. */
export function rotNWord(str, by) {
return str.toLowerCase().replace(/[a-z]/g, ((char) => {
const shifted = char.charCodeAt(0) + by;
return String.fromCharCode((shifted > Z) ? (shifted - 26) : shifted);
}));
}
//# sourceMappingURL=Rot13.js.map