-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: improve base64url encoding when native is available
- Loading branch information
Showing
3 changed files
with
48 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"commit-all": true, | ||
"scripts": { | ||
"postchangelog": "sed -i '' -e 's/### \\[/## [/g' CHANGELOG.md" | ||
}, | ||
"types": [ | ||
{ | ||
"type": "feat", | ||
"section": "Features" | ||
}, | ||
{ | ||
"type": "fix", | ||
"section": "Bug Fixes" | ||
}, | ||
{ | ||
"type": "chore", | ||
"hidden": true | ||
}, | ||
{ | ||
"type": "docs", | ||
"hidden": true | ||
}, | ||
{ | ||
"type": "style", | ||
"hidden": true | ||
}, | ||
{ | ||
"type": "refactor", | ||
"section": "Refactor", | ||
"hidden": true | ||
}, | ||
{ | ||
"type": "perf", | ||
"section": "Performance", | ||
"hidden": false | ||
}, | ||
{ | ||
"type": "test", | ||
"hidden": true | ||
} | ||
] | ||
} |
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,18 +1,8 @@ | ||
const fromBase64 = (base64) => { | ||
return base64.replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_') | ||
if (Buffer.isEncoding('base64url')) { | ||
module.exports.encode = (input) => Buffer.from(input).toString('base64url') | ||
} else { | ||
module.exports.encode = (input) => | ||
input.toString('base64').replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_') | ||
} | ||
|
||
const toBase64 = (base64url) => { | ||
return base64url.replace(/-/g, '+').replace(/_/g, '/') | ||
} | ||
|
||
const encode = (buf) => { | ||
return fromBase64(buf.toString('base64')) | ||
} | ||
|
||
const decode = (input) => { | ||
return Buffer.from(toBase64(input), 'base64') | ||
} | ||
|
||
module.exports.decode = decode | ||
module.exports.encode = encode | ||
module.exports.decode = (input) => Buffer.from(input, 'base64') |
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