@santi100/base64-lib
v0.0.5
Published
Santi's Base64 Library: A lightweight, portable, ES3-compliant Base64 library!
Downloads
9
Maintainers
Readme
Santi's Base64 Library
What's this?
This is a lightweight, fast library for encoding and decoding strings in base64 format.
It's portable between the browser and Node.js. In order to keep backwards compatibility with old browsers, this library can only encode and decode strings. This serves as a lighweight, portable replacement for the btoa
and atob
functions, and provides clearer names.
Contribute
Wanna contribute? File an issue or pull request! Make sure you follow the contribution Code of Conduct.
Installation
- Via NPM:
npm install @santi100/base64-lib
- Via Yarn:
yarn add @santi100/base64-lib
- Via PNPM:
pnpm install @santi100/base64-lib
API
function encode(input: string): string;
Encodesinput
to base64 format. It takes a string as an argument, and returns a base64 representation ofinput
.function decode(input: string): string;
Decodesinput
back to its original form. Must be a valid base64 string. It takes a valid base64 string, and returns the decoded value ofinput
.
My Goals
The above functions must:
- Be able to handle strings that contain non-printable ASCII (the result of stringifying a buffer, for example).
- Be fully ES3 compliant (no ArrayBuffer, Uint8Array or anything like that).
- Use padding
=
signs. - Be fully portable between the browser and Node.js (no reliance in any browser- or Node-exclusive API).
- Not modify the argument vector.
If any of the above is not being satisfied, open a pull request or issue. I have no idea how to satisfy idea #1 reliably (see Contribute (for instructions) and disclaimers😀).
Disclaimers
- Keep in mind this library can only reliably handle plaintext for now.
- *Hasn't been tested in an actual ES3 environment. Feel free to open an issue or pull request if you find any non-ES3 thing.
- ^The source code is about 3 kilobytes.