{"name":"@sindresorhus/base62","version":"0.1.0","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"],"author":{"url":"https://sindresorhus.com","name":"Sindre Sorhus","email":"sindresorhus@gmail.com"},"license":"MIT","_id":"@sindresorhus/base62@0.1.0","maintainers":[{"name":"sindresorhus","email":"sindresorhus@gmail.com"}],"homepage":"https://github.com/sindresorhus/base62#readme","bugs":{"url":"https://github.com/sindresorhus/base62/issues"},"dist":{"shasum":"2ef36425f0210998adf504e495f6c1e85c7d2718","tarball":"http://registry-npm.ywwl.com/@sindresorhus/base62/download/@sindresorhus/base62-0.1.0.tgz","fileCount":7,"integrity":"sha512-BNjiImatCV+CUdvzSbFWzZIZqOddg6qn0Ag6/8Ty5G09oOtvxidZ5tkPQW2XHpzGVkB3eHfdYGwrWNy2nUFOwQ==","signatures":[{"sig":"MEYCIQC9BfcRDYCj1UXAHW8SgWRQEGbG3hNgzIZcPFSkBlyCwQIhALTvpQkDpexLku9c2u8MyqpvEyz5dk9U78xWGFoVp0+E","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":10037,"size":3386,"noattachment":false,"key":"/@sindresorhus/base62/-/@sindresorhus/base62-0.1.0.tgz"},"type":"module","types":"./index.d.ts","engines":{"node":">=18"},"exports":{"types":"./index.d.ts","default":"./index.js"},"funding":"https://github.com/sponsors/sindresorhus","gitHead":"a5826efc96f7c79eb63a5d97893d6af03967496d","scripts":{"test":"xo && ava"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"repository":{"url":"git+https://github.com/sindresorhus/base62.git","type":"git"},"_npmVersion":"10.6.0","description":"Encode & decode strings, bytes, and integers to Base62","directories":{},"sideEffects":false,"_nodeVersion":"20.12.2","_hasShrinkwrap":false,"devDependencies":{"xo":"^0.58.0","ava":"^6.1.2"},"_npmOperationalInternal":{"tmp":"tmp/base62_0.1.0_1714912663364_0.17261420348543544","host":"s3://npm-registry-packages"},"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","publish_time":1714912663527,"_cnpm_publish_time":1714912663527,"dist-tags":{"latest":"1.0.0"}}