{"_id":"js-base64@3.9.6","bugs":{"url":"https://github.com/dankogai/js-base64/issues"},"dist":{"shasum":"f4a84265b5d56fd2870f368a4ea6ba7bbdff7157","tarball":"http://registry-npm.ywwl.com/js-base64/download/js-base64-3.9.6.tgz","fileCount":7,"integrity":"sha512-LjkzbLtU6Lx6fjXMYGEACEB7rdtqZtxkBe9aS1ZpDNUyWgUivw3yBEIhQ37OVygJYRt+C+9e9fVT8PpFzH2Hww==","signatures":[{"sig":"MEQCIFFPnwYdQEnRFlFcOgiIBBZpAnus3BwaT9bJd1hjcEEjAiAyNX0giYgyOyKHy59bNpc1cgJaguUeOQGhHT4L4XVZdw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQD0728r7NvDEy0wbLCueUFX6o5+EEgabibujr8uxrIhUwIgJ2Z750Br/HdjOxHEGRxWV0MVOq0BqNUhhyU7fcJjlHo="}],"unpackedSize":39974,"size":9048,"noattachment":false,"key":"/js-base64/-/js-base64-3.9.6.tgz"},"main":"base64.js","name":"js-base64","types":"base64.d.ts","author":{"name":"Dan Kogai"},"module":"base64.mjs","exports":{".":{"import":{"types":"./base64.d.mts","default":"./base64.mjs"},"require":{"types":"./base64.d.ts","default":"./base64.js"}},"./package.json":"./package.json"},"gitHead":"106d9fdfebb365e7b0e9be3c28c70c859a6efa6d","license":"BSD-3-Clause","scripts":{"test":"npm run build && mocha && npm run test:types","build":"rollup -c && tsc -p . --declaration --emitDeclarationOnly && node -e \"require('fs').copyFileSync('base64.d.ts','base64.d.mts')\"","clean":"node -e \"['base64.js','base64.mjs','base64.d.ts','base64.d.mts'].forEach(f=>require('fs').rmSync(f,{force:true}))\"","version":"npm run build && node util/sync-version.js && git add base64.js base64.mjs base64.d.ts base64.d.mts README.md","test:types":"tsc --noEmit --strict --module nodenext --lib es2020,dom test/types.cts test/types.mts"},"version":"3.9.6","_npmUser":{"name":"dankogai","email":"dankogai+github@gmail.com"},"homepage":"https://github.com/dankogai/js-base64#readme","keywords":["base64","binary"],"repository":{"url":"git+https://github.com/dankogai/js-base64.git","type":"git"},"_npmVersion":"11.21.0","description":"Yet another Base64 transcoder in pure-JS","directories":{},"maintainers":[{"name":"dankogai","email":"dankogai+github@gmail.com"}],"sideEffects":false,"_nodeVersion":"24.21.0","_hasShrinkwrap":false,"devDependencies":{"mocha":"^10.2.0","tslib":"^2.8.1","rollup":"^4.62.3","typescript":"^5.3.3","@types/node":"^20.11.5","@rollup/plugin-replace":"^6.0.3","@rollup/plugin-typescript":"^12.3.0"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/js-base64_3.9.6_1793535047209_0.3127368981781232"},"readme":"[![CI via GitHub Actions](https://github.com/dankogai/js-base64/actions/workflows/node.js.yml/badge.svg)](https://github.com/dankogai/js-base64/actions/workflows/node.js.yml)\n[![CI on bun](https://github.com/dankogai/js-base64/actions/workflows/bun.yml/badge.svg)](https://github.com/dankogai/js-base64/actions/workflows/bun.yml)\n\n# base64.js\n\nYet another [Base64] transcoder.\n\n[Base64]: http://en.wikipedia.org/wiki/Base64\n\n## Install\n\n```shell\n$ npm install --save js-base64\n```\n\n## Usage\n\n### In Browser\n\nLocally…\n\n```html\n<script src=\"base64.js\"></script>\n```\n\n… or Directly from CDN.  In which case you don't even need to install.\n\n```html\n<script src=\"https://cdn.jsdelivr.net/npm/js-base64@3.9.6/base64.min.js\"></script>\n```\n\nThis good old way loads `Base64` in the global context (`window`).  Though `Base64.noConflict()` is made available, you should consider using ES6 Module to avoid tainting `window`.\n\n### As an ES6 Module\n\nlocally…\n\n```javascript\nimport { Base64 } from 'js-base64';\n```\n\n```javascript\n// or if you prefer no Base64 namespace\nimport { encode, decode } from 'js-base64';\n```\n\nor even remotely.\n\n```html\n<script type=\"module\">\n// note jsdelivr.net does not automatically minify .mjs\nimport { Base64 } from 'https://cdn.jsdelivr.net/npm/js-base64@3.9.6/base64.mjs';\n</script>\n```\n\n```html\n<script type=\"module\">\n// or if you prefer no Base64 namespace\nimport { encode, decode } from 'https://cdn.jsdelivr.net/npm/js-base64@3.9.6/base64.mjs';\n</script>\n```\n\n### node.js (commonjs)\n\n```javascript\nconst {Base64} = require('js-base64');\n```\n\nUnlike the case above, the global context is no longer modified.\n\nYou can also use [esm] to `import` instead of `require`.\n\n[esm]: https://github.com/standard-things/esm\n\n```javascript\nrequire=require('esm')(module);\nimport {Base64} from 'js-base64';\n```\n\n## SYNOPSIS\n\n```javascript\nlet latin = 'dankogai';\nlet utf8  = '小飼弾'\nlet u8s   =  new Uint8Array([100,97,110,107,111,103,97,105]);\nBase64.encode(latin);             // ZGFua29nYWk=\nBase64.encode(latin, true);       // ZGFua29nYWk skips padding\nBase64.encodeURI(latin);          // ZGFua29nYWk\nBase64.btoa(latin);               // ZGFua29nYWk=\nBase64.btoa(utf8);                // raises exception\nBase64.fromUint8Array(u8s);       // ZGFua29nYWk=\nBase64.fromUint8Array(u8s, true); // ZGFua29nYWk which is URI safe\nBase64.encode(utf8);              // 5bCP6aO85by+\nBase64.encode(utf8, true)         // 5bCP6aO85by-\nBase64.encodeURI(utf8);           // 5bCP6aO85by-\n```\n\n```javascript\nBase64.decode(      'ZGFua29nYWk=');// dankogai\nBase64.decode(      'ZGFua29nYWk'); // dankogai\nBase64.atob(        'ZGFua29nYWk=');// dankogai\nBase64.atob(        '5bCP6aO85by+');// 'å°é£¼å¼¾' which is nonsense\nBase64.toUint8Array('ZGFua29nYWk=');// u8s above\nBase64.decode(      '5bCP6aO85by+');// 小飼弾\n// note .decodeURI() is unnecessary since it accepts both flavors\nBase64.decode(      '5bCP6aO85by-');// 小飼弾\n```\n\n```javascript\nBase64.isValid(0);      // false: 0 is not string\nBase64.isValid('');     // true: a valid Base64-encoded empty byte\nBase64.isValid('ZA=='); // true: a valid Base64-encoded 'd'\nBase64.isValid('Z A='); // true: whitespaces are okay\nBase64.isValid('ZA');   // true: padding ='s can be omitted\nBase64.isValid('Z');    // false: a single character can't encode a byte\nBase64.isValid('++');   // true: can be non URL-safe\nBase64.isValid('--');   // true: or URL-safe\nBase64.isValid('+-');   // false: can't mix both\n```\n\n### Base64 variants\n\nThe default encoding uses the standard Base64 alphabet from\n[RFC 4648, section 4](https://www.rfc-editor.org/rfc/rfc4648.html#section-4).\nThe URL-safe form in js-base64 uses the base64url alphabet from\n[section 5](https://www.rfc-editor.org/rfc/rfc4648.html#section-5) and omits padding.\n\n| Form | Characters for values 62 and 63 | Padding | Encoding methods |\n| --- | --- | --- | --- |\n| Standard Base64 | `+` and `/` | Trailing `=` as needed | `Base64.encode(text)`, `Base64.fromUint8Array(bytes)` |\n| URL-safe Base64 | `-` and `_` | Omitted | `Base64.encodeURI(text)`, `Base64.encode(text, true)`, `Base64.fromUint8Array(bytes, true)` |\n\nFor example, these bytes show both the alphabet and padding differences:\n\n```javascript\nconst bytes = new Uint8Array([251, 255]);\nBase64.fromUint8Array(bytes);       // '+/8='\nBase64.fromUint8Array(bytes, true); // '-_8'\nBase64.toUint8Array('+/8=');        // Uint8Array [251, 255]\nBase64.toUint8Array('-_8');         // Uint8Array [251, 255]\n```\n\n`Base64.decode()` and `Base64.toUint8Array()` accept both alphabets, with or\nwithout padding. Use `decode()` for UTF-8 text and `toUint8Array()` for bytes.\nEncoded output has no line wrapping; MIME or PEM line wrapping is not added.\n\n### Built-in Extensions\n\nBy default `Base64` leaves built-in prototypes untouched.  But you can extend them as below.\n\n```javascript\n// you have to explicitly extend String.prototype\nBase64.extendString();\n// once extended, you can do the following\n'dankogai'.toBase64();        // ZGFua29nYWk=\n'小飼弾'.toBase64();           // 5bCP6aO85by+\n'小飼弾'.toBase64(true);       // 5bCP6aO85by-\n'小飼弾'.toBase64URI();        // 5bCP6aO85by- an alias of .toBase64(true)\n'小飼弾'.toBase64URL();        // 5bCP6aO85by- an alias of .toBase64URI()\n'ZGFua29nYWk='.fromBase64();  // dankogai\n'5bCP6aO85by+'.fromBase64();  // 小飼弾\n'5bCP6aO85by-'.fromBase64();  // 小飼弾\n'5bCP6aO85by-'.toUint8Array();// UTF-8 bytes of '小飼弾'\n```\n\n```javascript\n// you have to explicitly extend Uint8Array.prototype\nBase64.extendUint8Array();\n// once extended, you can do the following\nu8s.toBase64();     // 'ZGFua29nYWk='\nu8s.toBase64URI();  // 'ZGFua29nYWk'\nu8s.toBase64URL();  // 'ZGFua29nYWk' an alias of .toBase64URI()\n```\n\n```javascript\n// extend all at once\nBase64.extendBuiltins()\n```\n\n## `.decode()` vs `.atob` (and `.encode()` vs `btoa()`)\n\nSuppose you have:\n\n```\nvar pngBase64 = \n  \"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=\";\n```\n\nWhich is a Base64-encoded 1x1 transparent PNG, **DO NOT USE** `Base64.decode(pngBase64)`.  Use `Base64.atob(pngBase64)` instead.  `Base64.decode()` decodes to UTF-8 string while `Base64.atob()` decodes to bytes, which is compatible to browser built-in `atob()`.  The same rule applies to the opposite direction.\n\nOr even better, `Base64.toUint8Array(pngBase64)`.\n\n## Brief History\n\n* Since version 3.3 it is written in TypeScript.  Both `base64.mjs` and `base64.js` are compiled from `base64.ts` via [Rollup](https://rollupjs.org).\n* Since version 3.7 `base64.js` is ES5-compatible again (hence IE11-compatible).\n* Since 3.0 `js-base64` switch to ES2015 module so it is no longer compatible with legacy browsers like IE (see above)\n","publish_time":1793535047299,"_cnpm_publish_time":1793535047299,"dist-tags":{"latest":"3.9.6"}}