btoa-lite provides a lightweight, isomorphic `btoa` (Base64 encoding) implementation for both Node.js and browser environments. Its primary differentiator is its approach to environment-specific code loading, utilizing `package.json`'s `main` and `browser` fields to avoid bundling Browserify's potentially large `Buffer` shim into browser builds. This ensures minimal bundle sizes for browser targets while providing a functional Base64 encoder in Node.js using its native `Buffer` API. As of version 1.0.0, it is a stable, mature package, likely in a maintenance state given its last publish in 2016, with a focus on simplicity over frequent feature updates. It aims to be the smallest and simplest means for `btoa` functionality across environments.
npm install btoa-liteVerified import paths — ran on the pinned version, not inferred.
Demonstrates Base64 encoding for both Latin-1 compatible and arbitrary Unicode strings using `btoa-lite`, including a common pattern for UTF-8 pre-encoding.
For arbitrary Unicode strings, first encode the string to UTF-8, then encode the resulting byte string with `btoa`. The `quickstart` example provides a utility function `utf8_to_b64` for this purpose.
For applications requiring modern Node.js APIs, consider alternatives that use `Buffer.from(string)` or ensure your environment tolerates the deprecation warning. `btoa-lite` itself is a low-level utility and does not provide an option to switch implementations.
In ESM contexts, always use the default import syntax `import btoa from 'btoa-lite';`. If issues persist, consider using `require()` within an `import` wrapper or a dynamic `import()` for more control.
Evaluate if an actively maintained alternative like `js-base64` or a custom implementation using `Buffer.from().toString('base64')` (for Node.js) and `window.btoa()` (for browsers) might be more suitable for long-term projects.Pre-encode the Unicode string into a UTF-8 byte string before passing it to `btoa-lite`. Refer to the `utf8_to_b64` function in the quickstart example.
When using `require('btoa-lite')`, the module itself returns the `btoa` function directly. Use `const btoa = require('btoa-lite');` instead of `const { btoa } = require('btoa-lite');`.Ensure `btoa-lite` is correctly bundled for your target environment. If trying to use `Buffer` directly in a browser, ensure a `Buffer` shim (like the one provided by Browserify) is present.
No dependency data recorded yet.