{"_id":"base62@3.0.0","bugs":{"url":"https://github.com/base62/base62.js/issues"},"dist":{"shasum":"940c3da63601cdf80d2c8b88d2fdb8a017bf374d","tarball":"http://registry-npm.ywwl.com/base62/download/base62-3.0.0.tgz","fileCount":8,"integrity":"sha512-dE5M7GCUopwruZVnbKnQB4Jhr5gnF9EK2PZtGXkcCEwCMGkZIJfq2bk3H3bGUOcMmaSHglCIBqbzBnye3CG16g==","signatures":[{"sig":"MEQCIDqmY4+LqDdMHQnPcYvX5E8zHCpp3ec64K3atDBicoYZAiA8k3NMgjb4b94SNPM+So9nCacOcRR8t76ZRvZfkcdbhw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCICaSkA+Vf1h4A10xWpI1Nu/Gb4bLHpMSQnlM3iyqqiycAiEAyTqatzDQqqBUjuiJ29FtoakyvT0JVjqSfZ9t9pRe70k="}],"unpackedSize":13404,"size":4743,"noattachment":false,"key":"/base62/-/base62-3.0.0.tgz"},"main":"./lib/legacy.js","name":"base62","types":"./index.d.ts","author":{"url":"http://nesbitt.io","name":"Andrew Nesbitt","email":"andrewnez@gmail.com"},"engines":{"node":">=18.0.0"},"gitHead":"448e00e3e8cc65d585eeaad4f0f36b8110c1ec1b","license":"MIT","scripts":{"test":"node --test test/*.js","benchmark":"node benchmark/benchmarks.js"},"version":"3.0.0","_npmUser":{"name":"andrewnez","email":"andrewnez@gmail.com"},"homepage":"https://github.com/base62/base62.js","keywords":["base-62","encoder","decoder"],"repository":{"url":"git+https://github.com/base62/base62.js.git","type":"git"},"_npmVersion":"11.7.0","description":"JavaScript Base62 encode/decoder","directories":{},"maintainers":[{"name":"andrewnez","email":"andrewnez@gmail.com"},{"name":"fnd","email":"fndnpm@burningchrome.com"}],"_nodeVersion":"25.4.0","_hasShrinkwrap":false,"devDependencies":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/base62_3.0.0_1792403482582_0.8782624209302146"},"readme":"# Base62.js\n[![npm version](https://badge.fury.io/js/base62.svg)](https://badge.fury.io/js/base62)\n[![CI](https://github.com/base62/base62.js/actions/workflows/ci.yml/badge.svg)](https://github.com/base62/base62.js/actions/workflows/ci.yml)\n[![npm downloads](https://img.shields.io/npm/dm/base62.svg)](https://www.npmjs.com/package/base62)\n[![license](https://img.shields.io/npm/l/base62.svg)](https://github.com/base62/base62.js/blob/main/LICENSE)\n\nA JavaScript Base62 encode/decoder.\n\nBase62 encoding converts numbers to ASCII strings (0-9, a-z and A-Z) and vice\nversa, which typically results in comparatively short strings. Such identifiers\nalso tend to be more readily identifiable by humans.\n\n* `999` -> `\"g7\"`\n* `9999` -> `\"2Bh\"`\n* `238327` -> `\"ZZZ\"`\n\n\n## Installation\n\n```shell\nnpm install base62\n```\n\n\n## Usage\n\n```javascript\nvar base62 = require(\"base62\");\n\nbase62.encode(999);  // \"g7\"\nbase62.decode(\"g7\"); // 999\n```\n\nBoth `encode` and `decode` support BigInt for values beyond `Number.MAX_SAFE_INTEGER`:\n\n```javascript\nbase62.encode(9007199254740993n);                // \"FfGNdXsE9\"\nbase62.decode(\"FfGNdXsE9\", { bigint: true });    // 9007199254740993n\n```\n\n`encode` accepts non-negative integers up to `Number.MAX_SAFE_INTEGER`, or any non-negative BigInt. Anything else throws: negatives, fractions, `NaN`, `Infinity`, strings, and numbers above the safe range, which JavaScript can't represent exactly. If a large ID arrives as a string, convert it with `BigInt(str)` rather than `Number(str)`, since `Number` has already rounded it.\n\n`decode` throws on an empty string, on any character outside the character set, and on results above `Number.MAX_SAFE_INTEGER` unless `{ bigint: true }` is passed:\n\n```javascript\nbase62.decode(\"g7!\");        // RangeError: Invalid character \"!\" in \"g7!\"\nbase62.decode(\"FfGNdXsE8\");  // RangeError: \"FfGNdXsE8\" decodes above Number.MAX_SAFE_INTEGER, use { bigint: true }\n```\n\nLeading zeros are ignored, so `\"0g7\"` and `\"g7\"` both decode to 999. Pad with `encoded.padStart(n, \"0\")` if you need fixed-length output. Decoding with `{ bigint: true }` takes time quadratic in the input length, so cap the length of untrusted input before decoding it.\n\n\n## Custom character sets\n\n`create` returns an `encode`/`decode` pair for a character set of any length (at least 2 unique characters):\n\n```javascript\nvar base62 = require(\"base62\");\nvar codec = base62.create(\"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\");\n\ncodec.encode(999);  // \"G7\"\ncodec.decode(\"G7\"); // 999\n```\n\n`setCharacterSet` changes the character set of the shared module instead, for every caller in the process, including other dependencies that use base62. It expects exactly 62 unique characters and replaces `base62.encode` and `base62.decode`, so references taken before the call keep the old character set. Prefer `create` in libraries.\n\n```javascript\nbase62.setCharacterSet(\"~9876543210ABCDEFGHIJKLMNOPQRSTU$#@%!abcdefghijklmnopqrstuvw-=\");\n\nbase62.encode(999);  // \"F3\"\nbase62.decode(\"F3\"); // 999\n```\n\nCharacters outside the Basic Multilingual Plane, such as emoji, count as one character each.\n\n\n## Upgrading to 3.0\n\nVersion 3.0 adds the input checks above. Earlier versions returned wrong values without an error: `decode(\"g7 \")` gave 61922, `decode(\"!g7\")` gave -56661, `encode(1.5)` gave `\"undefined\"`, and numbers past `Number.MAX_SAFE_INTEGER` lost precision. Version 3.0 also adds BigInt support and `create`, and requires Node 18 or later. Output for valid input in the safe range is unchanged from 1.x and 2.x.\n\n\n## Development\n\nSource code is hosted on [GitHub](http://github.com/base62/base62.js).\nPlease report issues or feature requests in\n[GitHub Issues](https://github.com/base62/base62.js/issues).\n\n * Fork the project.\n * Make your feature addition or bug fix.\n * Add tests for it.\n * Send a pull request.\n\n\n## License\n\nMIT. Copyright (c) 2026 Andrew Nesbitt. See [LICENSE](https://github.com/base62/base62.js/blob/main/LICENSE) for details.\n","publish_time":1792403482666,"_cnpm_publish_time":1792403482666,"dist-tags":{"latest":"3.0.0"}}