{"id":12843,"library":"atob-lite","title":"atob-lite","description":"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.","status":"active","version":"2.0.0","language":"javascript","source_language":"en","source_url":"git://github.com/hughsk/atob-lite","tags":["javascript","atob","base64","isomorphic","browser","node","shared"],"install":[{"cmd":"npm install atob-lite","lang":"bash","label":"npm"},{"cmd":"yarn add atob-lite","lang":"bash","label":"yarn"},{"cmd":"pnpm add atob-lite","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"For CommonJS, the package exports a default function. Direct assignment from `require()` is correct, while destructuring will result in 'undefined'.","wrong":"const { atob } = require('atob-lite')","symbol":"atob","correct":"const atob = require('atob-lite')"},{"note":"For ES Modules, the package exports a default function. Named imports are incorrect for this module and will lead to an error.","wrong":"import { atob } from 'atob-lite'","symbol":"atob","correct":"import atob from 'atob-lite'"},{"note":"For TypeScript, use the default import. Importing as a namespace object ('* as atob') would require calling 'atob.default(encoded)'.","wrong":"import * as atob from 'atob-lite'","symbol":"atob (TypeScript)","correct":"import atob from 'atob-lite'"}],"quickstart":{"code":"import atob from 'atob-lite';\n\nconst encodedString = 'SGVsbG8sIFdvcmxkIQ=='; // \"Hello, World!\" in Base64\nconst decodedString = atob(encodedString);\nconsole.log(`Encoded: ${encodedString}`);\nconsole.log(`Decoded: ${decodedString}`);\n\n// Demonstrating the environment abstraction (conceptual)\n// In a browser environment, this would utilize window.atob.\n// In a Node.js environment, it would leverage Node's Buffer API.\nfunction checkEnvironmentUsage() {\n  if (typeof window !== 'undefined' && typeof window.atob === 'function') {\n    console.log(\"Detected browser-like environment; atob-lite uses native window.atob.\");\n  } else if (typeof Buffer !== 'undefined' && typeof Buffer.from === 'function') {\n    console.log(\"Detected Node.js-like environment; atob-lite uses Buffer for decoding.\");\n  } else {\n    console.log(\"Could not conclusively determine environment specific implementation.\");\n  }\n}\ncheckEnvironmentUsage();","lang":"typescript","description":"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."},"warnings":[{"fix":"Use established cryptographic methods (e.g., AES, RSA) for data security and integrity when handling sensitive information.","message":"Base64 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure you are using the correct package for the intended operation: `atob-lite` for decoding, `btoa-lite` for encoding.","message":"Confusing `atob-lite` (decode) with `btoa-lite` (encode). `atob-lite` is strictly for decoding Base64 strings, while `btoa-lite` (a separate package) is for encoding.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"Directly 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"For CommonJS, use `const atob = require('atob-lite')`. For ES Modules, use `import atob from 'atob-lite'`.","message":"Incorrect 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`.","severity":"breaking","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Use `const atob = require('atob-lite')` for CommonJS or `import atob from 'atob-lite'` for ES Modules to correctly import the default function.","cause":"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).","error":"TypeError: atob is not a function"},{"fix":"Change the import statement to `import atob from 'atob-lite'`.","cause":"Trying to import `atob` as a named export from `atob-lite` in an ES Module context, but the package provides a default export.","error":"SyntaxError: Named export 'atob' not found (module 'atob-lite')"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null}