-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Remove Node.js b64 codec code (not needed) - Run tests in JSDOM to get window.atob/btoa - Even with that, can't get under 1KB gziped, oh well..
- Loading branch information
Showing
4 changed files
with
431 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,20 @@ | ||
export function base64UrlEncode(input: Uint8Array): string { | ||
if (typeof window === 'undefined') { | ||
// Node.js | ||
return Buffer.from(input).toString('base64url') | ||
} else { | ||
// Browser | ||
return ( | ||
window | ||
.btoa(String.fromCharCode(...input)) | ||
// Convert to base64url | ||
.replace(/\+/g, '-') | ||
.replace(/\//g, '_') | ||
.replace(/={1,2}$/, '') | ||
) | ||
} | ||
return ( | ||
window | ||
.btoa(String.fromCharCode(...input)) | ||
// Convert to base64url | ||
.replace(/\+/g, '-') | ||
.replace(/\//g, '_') | ||
.replace(/={1,2}$/, '') | ||
) | ||
} | ||
|
||
export function base64UrlDecode(input: string): Uint8Array { | ||
if (typeof window === 'undefined') { | ||
// Node.js | ||
return new Uint8Array(Buffer.from(input, 'base64url')) | ||
} else { | ||
// Browser | ||
return new Uint8Array( | ||
// convert base64url to base64 for atob | ||
window | ||
.atob(input.replace(/-/g, '+').replace(/_/g, '/')) | ||
.split('') | ||
.map(x => x.charCodeAt(0)) | ||
) | ||
} | ||
return new Uint8Array( | ||
// convert base64url to base64 for atob | ||
window | ||
.atob(input.replace(/-/g, '+').replace(/_/g, '/')) | ||
.split('') | ||
.map(x => x.charCodeAt(0)) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.