Registry / serialization / atob-lite

atob-lite

JSON →
library2.0.0jsnpmunverified

atob-lite provides a streamlined, isomorphic solution for Base64 decoding in JavaScript, abstracting away the platform-specific `atob` implementations. It intelligently uses the native `atob` function in browser environments and Node.js's `Buffer` API for server-side operations. The package's core strength lies in its build-time optimization: it leverages the `main` and `browser` fields in `package.json` to prevent build tools like Browserify from unnecessarily bundling the heavier `Buffer` shim into browser-destined code. This ensures a minimal footprint for client-side applications. The current stable version is 2.0.0. Given its nature as a foundational utility, its release cadence is generally slow, focusing on stability, cross-environment compatibility, and critical bug fixes rather than frequent feature additions. Its primary differentiator is its "lite" approach to isomorphic Base64 decoding, specifically designed to avoid common bundle size issues associated with `Buffer` shims in browser builds.

npm install atob-lite
INSTALL
IMPORT
SIG · ATOB-LITE
A
atob-lite
serializationjavascriptv2.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

atob
const atob = require('atob-lite')
const { atob } = require('atob-lite')
For CommonJS, the package exports a default function. Direct assignment from `require()` is correct, while destructuring will result in 'undefined'.
atob
import atob from 'atob-lite'
import { atob } from 'atob-lite'
For ES Modules, the package exports a default function. Named imports are incorrect for this module and will lead to an error.
atob (TypeScript)
import atob from 'atob-lite'
import * as atob from 'atob-lite'
For TypeScript, use the default import. Importing as a namespace object ('* as atob') would require calling 'atob.default(encoded)'.

Demonstrates how to decode a Base64 string using `atob-lite` and conceptually illustrates its environment-agnostic behavior, utilizing native browser `atob` or Node.js `Buffer` as appropriate.

import atob from 'atob-lite'; const encodedString = 'SGVsbG8sIFdvcmxkIQ=='; // "Hello, World!" in Base64 const decodedString = atob(encodedString); console.log(`Encoded: ${encodedString}`); console.log(`Decoded: ${decodedString}`); // Demonstrating the environment abstraction (conceptual) // In a browser environment, this would utilize window.atob. // In a Node.js environment, it would leverage Node's Buffer API. function checkEnvironmentUsage() { if (typeof window !== 'undefined' && typeof window.atob === 'function') { console.log("Detected browser-like environment; atob-lite uses native window.atob."); } else if (typeof Buffer !== 'undefined' && typeof Buffer.from === 'function') { console.log("Detected Node.js-like environment; atob-lite uses Buffer for decoding."); } else { console.log("Could not conclusively determine environment specific implementation."); } } checkEnvironmentUsage();
Debug
Known issues
gotchaBase64 encoding/decoding is not a form of encryption and should not be used for securing sensitive data. It merely translates binary data into an ASCII string format.
fix
Use established cryptographic methods (e.g., AES, RSA) for data security and integrity when handling sensitive information.
affects: >=1.0.0
gotchaConfusing `atob-lite` (decode) with `btoa-lite` (encode). `atob-lite` is strictly for decoding Base64 strings, while `btoa-lite` (a separate package) is for encoding.
fix
Ensure you are using the correct package for the intended operation: `atob-lite` for decoding, `btoa-lite` for encoding.
affects: >=1.0.0
gotchaDirectly requiring or importing `Buffer` in browser-targeted code, even implicitly, can pull in Browserify's large `Buffer` shim. `atob-lite` specifically aims to avoid this by using conditional exports.
fix
Rely on `atob-lite` for Base64 decoding in isomorphic code. Avoid direct `Buffer` usage in shared code that targets browsers unless a large bundle size is acceptable or necessary.
affects: >=1.0.0
breakingIncorrect module import syntax for CommonJS (e.g., destructuring `require`) or ES Modules (e.g., named import for a default export) will result in `atob` being `undefined` or a `SyntaxError`.
fix
For CommonJS, use `const atob = require('atob-lite')`. For ES Modules, use `import atob from 'atob-lite'`.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: atob is not a function
Attempting to call `atob` when it was incorrectly imported as `undefined` (e.g., `const { atob } = require('atob-lite')` for CommonJS or `import { atob } from 'atob-lite'` for ES Modules).
fix
Use `const atob = require('atob-lite')` for CommonJS or `import atob from 'atob-lite'` for ES Modules to correctly import the default function.
SyntaxError: Named export 'atob' not found (module 'atob-lite')
Trying to import `atob` as a named export from `atob-lite` in an ES Module context, but the package provides a default export.
fix
Change the import statement to `import atob from 'atob-lite'`.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
15 hits · last 30 days
node
14
OpenAI (training)
1
Resources
atob-lite — npm install atob-lite · libregistry