base64-js
base64-js copied to clipboard
Add support for encoding URL-safe base64
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.
Hi, i have created new one, based on this project.
Fixing and merging
- Ignore padding on decode
- ReferenceError thrown
- Performance improvements and fixed a bug in fromByteArray() when extra bytes are negative
- Add support for encoding URL-safe base64
Improving
- (re)Written by TypeScript
- Supports both modern browsers and Node.js
- Supports URL-safe base64 encoding/decoding
- More test cases
Any additional thoughts on merging this? Before I reinvent the wheel, I'd rather switch to your existing implementation.
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.
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.