UNPKG

@easy-cipher/caesar

Version:

[![npm](https://img.shields.io/npm/v/@easy-cipher/caesar.svg)](https://www.npmjs.com/package/@easy-cipher/caesar) [![npm bundle size (minified + gzip)](https://badgen.net/bundlephobia/minzip/@easy-cipher/caesar)](https://bundlephobia.com/result?p=@easy-ci

10 lines (8 loc) 1.76 kB
/** * @easy-cipher/caesar@1.0.1 * Copyright (c) 2021 Bartłomiej Wiśniewski * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self)["@easy-cipher/caesar"]={})}(this,(function(t){"use strict";const e="abcdefghijklmnopqrstuvwxyz".split("");t.caesar=({encryptionOffset:t,alphabet:r=e,ciphertextWordsSeparator:n,ciphertextCharactersSeparator:a,plaintextWordsSeparator:o,plaintextCharactersSeparator:i})=>{const p=t>0?t%r.length:r.length+t%r.length;return(({mappings:t,ciphertextWordsSeparator:e=" ",ciphertextCharactersSeparator:r="",plaintextWordsSeparator:n=" ",plaintextCharactersSeparator:a=""})=>{const o=Object.entries(t).reduce(((t,[e,r])=>({...t,[r]:e})),{});return{encode:(o,{throwOnUnknownCharacters:i}={throwOnUnknownCharacters:!0})=>o.split(n).map((e=>e.split(a).map((e=>{const r=t[e];if(r)return r;if(i)throw new Error(`Unsupported character ${JSON.stringify(e)}, not found in ${JSON.stringify(t)}`);return""})).join(r))).join(e),decode:(t,{throwOnUnknownCharacters:i}={throwOnUnknownCharacters:!0})=>t.split(e).map((t=>t.split(r).map((t=>{const e=o[t];if(e)return e;if(i)throw new Error(`Unsupported ciphertext ${JSON.stringify(t)}, not found in ${JSON.stringify(o)}`);return""})).join(a))).join(n)}})({mappings:r.reduce(((t,e,r,n)=>({...t,[e]:n[(r+p)%n.length]})),{}),ciphertextWordsSeparator:n,ciphertextCharactersSeparator:a,plaintextWordsSeparator:o,plaintextCharactersSeparator:i})},Object.defineProperty(t,"__esModule",{value:!0})})); //# sourceMappingURL=index.umd.js.map