Skip to content

Commit

Permalink
internal refactor of function name
Browse files Browse the repository at this point in the history
  • Loading branch information
awaragi committed Sep 30, 2024
1 parent ae1accd commit 1be8dde
Showing 1 changed file with 48 additions and 46 deletions.
94 changes: 48 additions & 46 deletions lib/plantumlEncode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 1be8dde

Please sign in to comment.