aboutsummaryrefslogtreecommitdiff
path: root/node_modules/abab/lib/btoa.js
diff options
context:
space:
mode:
authorJoel Kronqvist <joel.h.kronqvist@gmail.com>2022-03-05 19:02:27 +0200
committerJoel Kronqvist <joel.h.kronqvist@gmail.com>2022-03-05 19:02:27 +0200
commit5d309ff52cd399a6b71968a6b9a70c8ac0b98981 (patch)
tree360f7eb50f956e2367ef38fa1fc6ac7ac5258042 /node_modules/abab/lib/btoa.js
parentb500a50f1b97d93c98b36ed9a980f8188d648147 (diff)
downloadLYLLRuoka-5d309ff52cd399a6b71968a6b9a70c8ac0b98981.tar.gz
LYLLRuoka-5d309ff52cd399a6b71968a6b9a70c8ac0b98981.zip
Added node_modules for the updating to work properly.
Diffstat (limited to 'node_modules/abab/lib/btoa.js')
-rw-r--r--node_modules/abab/lib/btoa.js58
1 files changed, 58 insertions, 0 deletions
diff --git a/node_modules/abab/lib/btoa.js b/node_modules/abab/lib/btoa.js
new file mode 100644
index 0000000..131a679
--- /dev/null
+++ b/node_modules/abab/lib/btoa.js
@@ -0,0 +1,58 @@
+"use strict";
+
+/**
+ * btoa() as defined by the HTML and Infra specs, which mostly just references
+ * RFC 4648.
+ */
+function btoa(s) {
+ let i;
+ // String conversion as required by Web IDL.
+ s = `${s}`;
+ // "The btoa() method must throw an "InvalidCharacterError" DOMException if
+ // data contains any character whose code point is greater than U+00FF."
+ for (i = 0; i < s.length; i++) {
+ if (s.charCodeAt(i) > 255) {
+ return null;
+ }
+ }
+ let out = "";
+ for (i = 0; i < s.length; i += 3) {
+ const groupsOfSix = [undefined, undefined, undefined, undefined];
+ groupsOfSix[0] = s.charCodeAt(i) >> 2;
+ groupsOfSix[1] = (s.charCodeAt(i) & 0x03) << 4;
+ if (s.length > i + 1) {
+ groupsOfSix[1] |= s.charCodeAt(i + 1) >> 4;
+ groupsOfSix[2] = (s.charCodeAt(i + 1) & 0x0f) << 2;
+ }
+ if (s.length > i + 2) {
+ groupsOfSix[2] |= s.charCodeAt(i + 2) >> 6;
+ groupsOfSix[3] = s.charCodeAt(i + 2) & 0x3f;
+ }
+ for (let j = 0; j < groupsOfSix.length; j++) {
+ if (typeof groupsOfSix[j] === "undefined") {
+ out += "=";
+ } else {
+ out += btoaLookup(groupsOfSix[j]);
+ }
+ }
+ }
+ return out;
+}
+
+/**
+ * Lookup table for btoa(), which converts a six-bit number into the
+ * corresponding ASCII character.
+ */
+const keystr =
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+
+function btoaLookup(index) {
+ if (index >= 0 && index < 64) {
+ return keystr[index];
+ }
+
+ // Throw INVALID_CHARACTER_ERR exception here -- won't be hit in the tests.
+ return undefined;
+}
+
+module.exports = btoa;