Skip to content

Commit

Permalink
Prepare 1.1.28
Browse files Browse the repository at this point in the history
  • Loading branch information
Hexagon committed Sep 18, 2023
1 parent 4885655 commit f555e05
Show file tree
Hide file tree
Showing 13 changed files with 147 additions and 166 deletions.
61 changes: 0 additions & 61 deletions CONTRIBUTING.md

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Full documentation available at [base64.56k.guru](https://base64.56k.guru)

Node.js: `npm install @hexagon/base64 --save`

Deno: `import base64 from "https://deno.land/x/b64@1.1.27/src/base64.js";`
Deno: `import base64 from "https://deno.land/x/b64@1.1.28/src/base64.js";`

For browser/cdn usage, refer to the documentation.

Expand Down
23 changes: 14 additions & 9 deletions dist/base64.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@

genLookup = (target) => {
const lookupTemp = typeof Uint8Array === "undefined" ? [] : new Uint8Array(256);
for (let i = 0; i < chars.length; i++) {
const len = chars.length;
for (let i = 0; i < len; i++) {
lookupTemp[target.charCodeAt(i)] = i;
}
return lookupTemp;
Expand All @@ -51,6 +52,12 @@
lookup = genLookup(chars),
lookupUrl = genLookup(charsUrl);

/**
* Pre-calculated regexes for validating base64 and base64url
*/
const base64UrlPattern = /^[-A-Za-z0-9\-_]*$/;
const base64Pattern = /^[-A-Za-z0-9+/]*={0,3}$/;

/**
* @namespace base64
*/
Expand Down Expand Up @@ -103,7 +110,7 @@
};

/**
* Convenience function for converting base64 encoded string to an ArrayBuffer instance
* Convenience function for creating a base64 encoded string from an ArrayBuffer instance
* @public
*
* @param {ArrayBuffer} arrBuf - ArrayBuffer to be encoded
Expand All @@ -127,13 +134,15 @@
result += target[bytes[i + 2] & 63];
}

if (len % 3 === 2) {
const remainder = len % 3;
if (remainder === 2) {
result = result.substring(0, result.length - 1) + (urlMode ? "" : "=");
} else if (len % 3 === 1) {
} else if (remainder === 1) {
result = result.substring(0, result.length - 2) + (urlMode ? "" : "==");
}

return result;

};

/**
Expand Down Expand Up @@ -176,11 +185,7 @@

// Go on validate
try {
if (urlMode) {
return /^[-A-Za-z0-9\-_]*$/.test(encoded);
} else {
return /^[-A-Za-z0-9+/]*={0,3}$/.test(encoded);
}
return urlMode ? base64UrlPattern.test(encoded) : base64Pattern.test(encoded);
} catch (_e) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion dist/base64.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/base64.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f555e05

Please sign in to comment.