@santi100/base64-lib
TypeScript icon, indicating that this package has built-in type declarations

0.0.5 • Public • Published

Santi's Base64 Library

Build Status GitHub stars License npm bundle size

  • 🚀 Lightweight and fast^
  • 👴 ES3-compliant*
  • 💻 Portable between the browser and Node.js

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; Encodes input to base64 format. It takes a string as an argument, and returns a base64 representation of input.
  • function decode(input: string): string; Decodes input back to its original form. Must be a valid base64 string. It takes a valid base64 string, and returns the decoded value of input.

My Goals

The above functions must:

  1. Be able to handle strings that contain non-printable ASCII (the result of stringifying a buffer, for example).
  2. Be fully ES3 compliant (no ArrayBuffer, Uint8Array or anything like that).
  3. Use padding = signs.
  4. Be fully portable between the browser and Node.js (no reliance in any browser- or Node-exclusive API).
  5. 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.

/@santi100/base64-lib/

    Package Sidebar

    Install

    npm i @santi100/base64-lib

    Weekly Downloads

    0

    Version

    0.0.5

    License

    MIT

    Unpacked Size

    24.4 kB

    Total Files

    19

    Last publish

    Collaborators

    • santi100a