From 1be8dde36092cb02995e520f63f4be6c21d13e77 Mon Sep 17 00:00:00 2001 From: Pierre Awaragi Date: Mon, 30 Sep 2024 14:40:44 -0400 Subject: [PATCH] internal refactor of function name --- lib/plantumlEncode.js | 94 ++++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 46 deletions(-) diff --git a/lib/plantumlEncode.js b/lib/plantumlEncode.js index 355dad3..06119a0 100644 --- a/lib/plantumlEncode.js +++ b/lib/plantumlEncode.js @@ -2,60 +2,62 @@ * Original: * https://github.com/johan/js-deflate */ -const { deflate } = require("./rawdeflate"); +const {deflate} = require("./rawdeflate"); const encode64 = (data) => { - let r = ""; - for (let i = 0; i < data.length; i += 3) { - if (i + 2 === data.length) { - r += append3bytes(data.charCodeAt(i), data.charCodeAt(i + 1), 0); - } else if (i + 1 === data.length) { - r += append3bytes(data.charCodeAt(i), 0, 0); - } else { - r += append3bytes( - data.charCodeAt(i), - data.charCodeAt(i + 1), - data.charCodeAt(i + 2) - ); + let r = ""; + for (let i = 0; i < data.length; i += 3) { + if (i + 2 === data.length) { + r += append3bytes(data.charCodeAt(i), data.charCodeAt(i + 1), 0); + } else if (i + 1 === data.length) { + r += append3bytes(data.charCodeAt(i), 0, 0); + } else { + r += append3bytes( + data.charCodeAt(i), + data.charCodeAt(i + 1), + data.charCodeAt(i + 2) + ); + } } - } - return r; + return r; }; const append3bytes = (b1, b2, b3) => { - let c1 = b1 >> 2; - let c2 = ((b1 & 0x3) << 4) | (b2 >> 4); - let c3 = ((b2 & 0xf) << 2) | (b3 >> 6); - let c4 = b3 & 0x3f; - let r = ""; - r += encode6bit(c1 & 0x3f); - r += encode6bit(c2 & 0x3f); - r += encode6bit(c3 & 0x3f); - r += encode6bit(c4 & 0x3f); - return r; + let c1 = b1 >> 2; + let c2 = ((b1 & 0x3) << 4) | (b2 >> 4); + let c3 = ((b2 & 0xf) << 2) | (b3 >> 6); + let c4 = b3 & 0x3f; + let r = ""; + r += encode6bit(c1 & 0x3f); + r += encode6bit(c2 & 0x3f); + r += encode6bit(c3 & 0x3f); + r += encode6bit(c4 & 0x3f); + return r; }; const encode6bit = (b) => { - if (b < 10) { - return String.fromCharCode(48 + b); - } - b -= 10; - if (b < 26) { - return String.fromCharCode(65 + b); - } - b -= 26; - if (b < 26) { - return String.fromCharCode(97 + b); - } - b -= 26; - if (b === 0) { - return "-"; - } - if (b === 1) { - return "_"; - } - return "?"; + if (b < 10) { + return String.fromCharCode(48 + b); + } + b -= 10; + if (b < 26) { + return String.fromCharCode(65 + b); + } + b -= 26; + if (b < 26) { + return String.fromCharCode(97 + b); + } + b -= 26; + if (b === 0) { + return "-"; + } + if (b === 1) { + return "_"; + } + return "?"; }; -const geturl = (s) => encode64(deflate(unescape(encodeURIComponent(s)), 9)); -module.exports = geturl; +function plantumlEncode(s) { + return encode64(deflate(unescape(encodeURIComponent(s)), 9)); +} +module.exports = plantumlEncode;