Currently the code has 2 functions fromBase64 and toBase64 with custom string replacement.
Starting from (at least) Node.js 14.x base64url is a valid parameter to the Buffer.toString API. (I traced this by looking at the Node.js API docs per version and noting when the base64url was included as valid parameter).
Describe the ideal solution
The code of these functions can be rewritten to:
function toBase64(base64url) {
return Buffer.from(base64url.toString(), 'base64url').toString('base64')
}
function fromBase64(base64) {
return Buffer.from(base64.toString(), 'base64').toString('base64url')
}
...taking advantage of the built-in Buffer API
Additionally, might want to specify { "engines": { "node": ">=14.x" }} in package.json
Describe the problem you'd like to have solved
Currently the code has 2 functions
fromBase64
andtoBase64
with custom string replacement. Starting from (at least) Node.js 14.xbase64url
is a valid parameter to theBuffer.toString
API. (I traced this by looking at the Node.js API docs per version and noting when the base64url was included as valid parameter).Describe the ideal solution
The code of these functions can be rewritten to:
...taking advantage of the built-in Buffer API
Additionally, might want to specify
{ "engines": { "node": ">=14.x" }}
inpackage.json