Skip to content

Commit

Permalink
fix: URL Base64 默认使用 noPadding 模式
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouwenfeng committed Feb 8, 2023
1 parent 8fbf278 commit 084ddbc
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
10 changes: 9 additions & 1 deletion base64.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ class Base64 {
this.strict = false;
}

withNoPadding() {
this.padChar = this.noPadding;
}

withStdPadding() {
this.padChar = this.stdPadding;
}

// encodeToString(src Uint8Array) String
encodeToString(src) {
const type = typeof src
Expand Down Expand Up @@ -652,4 +660,4 @@ class Base64 {
}
}

export default Base64;
export default Base64;
1 change: 1 addition & 0 deletions base64_std.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Base64 from './base64.mjs';

const STDBase64 = new Base64("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");
STDBase64.withStdPadding();

export default STDBase64;

1 change: 1 addition & 0 deletions base64_url.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Base64 from './base64.mjs';

const URLBase64 = new Base64("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_");
URLBase64.withNoPadding();

export default URLBase64;

2 changes: 1 addition & 1 deletion tests/base64_test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,4 @@ if (includePlus == true) {
throw new Error("The output string must not contain a plus sign");
}

console.log("basic mixed test STD and URL base64 success.")
console.log("basic mixed test STD and URL base64 success.")

0 comments on commit 084ddbc

Please sign in to comment.