Skip to content

Enhancement/ tech debt: use Node's built-in toString(base64url) #48

Description

@webketje

Describe the problem you'd like to have solved

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions