base64-js icon indicating copy to clipboard operation
base64-js copied to clipboard

Add support for encoding URL-safe base64

Open jessetane opened this issue 6 years ago • 4 comments

There are a bunch of modules on npm that do this already, but it seems like most of them depend on another module (sometimes buffer itself) and then add regex replace or similar, or include lots of features I don't want. Since we already do decoding here, I figure adding encoding just makes things symmetrical and so doesn't feel too out of place.

Note that performance remains the same with this approach but there is a tiny memory penalty (the extra alphabet itself should only be another ~128 bytes?). Ideas for other approaches or references to alternate modules welcome.

jessetane avatar Jan 01 '19 04:01 jessetane

Hi, i have created new one, based on this project.

Fixing and merging

Improving

  • (re)Written by TypeScript
  • Supports both modern browsers and Node.js
  • Supports URL-safe base64 encoding/decoding
  • More test cases

Enjoy it with base64 and Docs .

waitingsong avatar Jun 13 '19 12:06 waitingsong

Any additional thoughts on merging this? Before I reinvent the wheel, I'd rather switch to your existing implementation.

bradisbell avatar Feb 18 '20 23:02 bradisbell

oops, had forgotten about this. I personally still like having the (totally optional!) alphabet arg, but Feross is right that it should "do something". I just pushed a few commits to try and clear up the difference between real base64url support and the node compat hack where the default alphabet also decodes base64url, see what you think.

jessetane avatar Feb 19 '20 13:02 jessetane

I implemented an extra optional opts argument to fromArrayBuffer in my fork. I did so before seeing this pull request, so maybe there are some ideas from here I can include there and vice versa. Anyway, that branch also includes modifications inspired by other forks. I can pick up this pull request, if anyone is still maintaining the package.

kwikwag avatar Dec 17 '23 13:12 kwikwag