{"_id":"@sindresorhus/base62","_rev":"4250406","name":"@sindresorhus/base62","description":"Encode & decode strings, bytes, and integers to Base62","dist-tags":{"latest":"1.0.0"},"maintainers":[{"name":"sindresorhus","email":""}],"time":{"modified":"2026-03-29T21:57:33.000Z","created":"2024-05-05T12:37:43.527Z","1.0.0":"2025-09-16T19:02:37.860Z","0.1.0":"2024-05-05T12:37:43.527Z"},"users":{},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"repository":{"type":"git","url":"git+https://github.com/sindresorhus/base62.git"},"versions":{"1.0.0":{"name":"@sindresorhus/base62","version":"1.0.0","description":"Encode & decode strings, bytes, and integers to Base62","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/base62.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":{"types":"./index.d.ts","default":"./index.js"},"sideEffects":false,"engines":{"node":">=18"},"scripts":{"test":"xo && ava"},"keywords":["base62","base","base64","base-62","encode","decode","shorten","compress","compact","alphanumeric","serialization","url","safe","text","string","number","integer","bigint","bytes","uint8array","algorithm","transformation","encoder","decoder","encoding","decoding","url-friendly","url-safe"],"devDependencies":{"ava":"^6.1.2","xo":"^0.58.0"},"_id":"@sindresorhus/base62@1.0.0","gitHead":"74e8b2f252737a83a9b88dc77afb6ae77bdaa676","types":"./index.d.ts","bugs":{"url":"https://github.com/sindresorhus/base62/issues"},"homepage":"https://github.com/sindresorhus/base62#readme","_nodeVersion":"20.19.5","_npmVersion":"10.9.2","dist":{"shasum":"c47c42410e5212e4fa4657670e118ddfba39acd6","size":4351,"noattachment":false,"key":"/@sindresorhus/base62/-/@sindresorhus/base62-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/@sindresorhus/base62/download/@sindresorhus/base62-1.0.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/base62_1.0.0_1758049357664_0.6247925194330457"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2025-09-16T19:02:37.860Z","publish_time":1758049357860,"_source_registry_name":"default","_cnpm_publish_time":1758049357860},"0.1.0":{"name":"@sindresorhus/base62","version":"0.1.0","description":"Encode & decode strings, bytes, and integers to Base62","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/base62.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":{"types":"./index.d.ts","default":"./index.js"},"sideEffects":false,"engines":{"node":">=18"},"scripts":{"test":"xo && ava"},"keywords":["base62","base","base64","base-62","encode","decode","shorten","compress","compact","alphanumeric","serialization","url","safe","text","string","number","integer","bigint","bytes","uint8array","algorithm","transformation","encoder","decoder","encoding","decoding","url-friendly","url-safe"],"devDependencies":{"ava":"^6.1.2","xo":"^0.58.0"},"_id":"@sindresorhus/base62@0.1.0","gitHead":"a5826efc96f7c79eb63a5d97893d6af03967496d","types":"./index.d.ts","bugs":{"url":"https://github.com/sindresorhus/base62/issues"},"homepage":"https://github.com/sindresorhus/base62#readme","_nodeVersion":"20.12.2","_npmVersion":"10.6.0","dist":{"shasum":"2ef36425f0210998adf504e495f6c1e85c7d2718","size":3386,"noattachment":false,"key":"/@sindresorhus/base62/-/@sindresorhus/base62-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/@sindresorhus/base62/download/@sindresorhus/base62-0.1.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/base62_0.1.0_1714912663364_0.17261420348543544"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2024-05-05T12:37:43.527Z","publish_time":1714912663527,"_source_registry_name":"default","_cnpm_publish_time":1714912663527}},"readme":"# base62\n\n> Encode & decode strings, bytes, and integers to [Base62](https://en.wikipedia.org/wiki/Base62)\n\nBase62 is ideal for URL shortening, creating readable codes, and compact data representation, because it compresses large values into shorter, alphanumeric strings, maximizing space efficiency and readability.\n\n## Install\n\n```sh\nnpm install @sindresorhus/base62\n```\n\n## Usage\n\n```js\nimport base62 from '@sindresorhus/base62';\n\nconst encodedString = base62.encodeString('Hello world!');\nconsole.log(encodedString);\n//=> '28B5ymDkgSU62aA0v'\n\nconsole.log(base62.decodeString(encodedString));\n//=> 'Hello world!'\n\nconsole.log(base62.encodeString('????'));\n//=> '95s3vg'\n\nconsole.log(base62.encodeInteger(1337));\n//=> 'LZ'\n```\n\n> [!NOTE]\n> The output may differ from other Base62 encoders due to variations in alphabet order and byte encoding.\n\n## API\n\nIt uses the most common alphabet for Base62: `0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`\n\n### `encodeString(string: string): string`\n\nEncodes a string to a Base62 string.\n\n> [!CAUTION]\n> The result format is not yet guaranteed to be stable across package versions. Avoid using it for persistent storage.\n\n### `decodeString(encodedString: string): string`\n\nDecodes a Base62 encoded string created with `encodeString()` back to the original string.\n\n### `encodeBytes(bytes: Uint8Array): string`\n\nEncodes bytes to a Base62 string.\n\n> [!CAUTION]\n> The result format is not yet guaranteed to be stable across package versions. Avoid using it for persistent storage.\n\n### `decodeBytes(encodedString: string): Uint8Array`\n\nDecodes a Base62 string created with `encodeBytes()` back to bytes.\n\n### `encodeInteger(integer: number): string`\n\nEncodes a non-negative integer to a Base62 string.\n\n### `decodeInteger(encodedString: string): number`\n\nDecodes a Base62 string to an integer.\n\n### `encodeBigInt(integer: bigint): string`\n\nEncodes a non-negative bigint to a Base62 string.\n\n### `decodeBigInt(encodedString: string): bigint`\n\nDecodes a Base62 string to a bigint.\n\n### Custom alphabets\n\nYou can use a custom alphabet by using the `Base62` class:\n\n```js\nimport {Base62} from '@sindresorhus/base62';\n\n// Create instance with custom alphabet\nconst customBase62 = new Base62({\n\talphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'\n});\n\nconsole.log(customBase62.encodeInteger(1337));\n//=> 'Vj' (different from default 'LZ')\n\n// Or use special characters\nconst symbolBase62 = new Base62({\n\talphabet: '!@#$%^&*()_+-=[]{}|;:,.<>?/~`0123456789ABCDEFGHIJKLMNOPQRSTUVW'\n});\nconsole.log(symbolBase62.encodeInteger(42));\n//=> 'D'\n```\n\n> [!NOTE]\n> The alphabet must be exactly 62 unique characters.\n\n### `Base62`\n\n#### `constructor(options?)`\n\nCreate a new Base62 encoder/decoder instance.\n\n##### options\n\nType: `object`\n\n###### alphabet\n\nType: `string`\\\nDefault: `'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'`\n\nCustom alphabet containing exactly 62 unique characters.\n\nThe `Base62` class has the same methods as the exported functions: `encodeString()`, `decodeString()`, `encodeBytes()`, `decodeBytes()`, `encodeInteger()`, `decodeInteger()`, `encodeBigInt()`, and `decodeBigInt()`.\n","_attachments":{},"homepage":"https://github.com/sindresorhus/base62#readme","bugs":{"url":"https://github.com/sindresorhus/base62/issues"},"license":"MIT"}