{"name":"ulid","version":"2.4.0","author":{"name":"Alizain Feerasta"},"license":"MIT","_id":"ulid@2.4.0","maintainers":[{"name":"perrymitchell","email":"perry@perrymitchell.net"},{"name":"alizain","email":"alizain.feerasta@gmail.com"}],"homepage":"https://github.com/ulid/javascript#readme","bugs":{"url":"https://github.com/ulid/javascript/issues"},"bin":{"ulid":"bin/cli.js"},"dist":{"shasum":"9d9ee22e63f4390ee1bcd9ad09fca39d8ae0afed","tarball":"http://registry-npm.ywwl.com/ulid/download/ulid-2.4.0.tgz","fileCount":9,"integrity":"sha512-fIRiVTJNcSRmXKPZtGzFQv9WRrZ3M9eoptl/teFJvjOzmpU+/K/JH6HZ8deBfb5vMEpicJcLn7JmvdknlMq7Zg==","signatures":[{"sig":"MEQCIGZIMP6VaosQQgjbtjyQyRjuSOPnrFlhyJFiA/Y5swW9AiBmpSVWJVf0+wDfiB5CENCFYZqy+E8Gn8MgOIOpSkgjCg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":23540,"size":5901,"noattachment":false,"key":"/ulid/-/ulid-2.4.0.tgz"},"main":"./dist/index.umd.js","types":"./dist/index.d.ts","esnext":"./dist/index.js","module":"./dist/index.esm.js","browser":{"crypto":"./stubs/crypto.js"},"gitHead":"0e660a6822e9fadfd37e90647c82faa2f6d336af","scripts":{"ts":"tsc -p .","perf":"matcha perf.js","test":"npm run test:coverage","build":"npm run clean && npm run ts && npm run rollup","clean":"rm -rf ./dist","rollup":"rollup -c","test:specs":"mocha -- -R spec","test:coverage":"c8 --check-coverage --lines 87 --functions 100 --src ./lib npm run test:specs"},"_npmUser":{"name":"perrymitchell","email":"perry@perrymitchell.net"},"repository":{"url":"git+https://github.com/ulid/javascript.git","type":"git"},"_npmVersion":"10.8.2","description":"A universally-unique, lexicographically-sortable, identifier generator","directories":{},"_nodeVersion":"20.19.0","_hasShrinkwrap":false,"devDependencies":{"c8":"^10.1.3","lolex":"^2.7.5","mocha":"^11.1.0","tslib":"^2.8.1","matcha":"^0.7.0","rollup":"^4.35.0","typedoc":"^0.9.0","typescript":"^5.8.2","@types/node":"^22.13.10","@rollup/plugin-babel":"^6.0.4","@rollup/plugin-typescript":"^11.1.6"},"_npmOperationalInternal":{"tmp":"tmp/ulid_2.4.0_1742149695504_0.8885948403731614","host":"s3://npm-registry-packages-npm-production"},"readme":"<h1 align=\"center\">\n\t<br>\n\t<br>\n\t<img width=\"360\" src=\"logo.png\" alt=\"ulid\">\n\t<br>\n\t<br>\n\t<br>\n</h1>\n\n# Universally Unique Lexicographically Sortable Identifier\n\n[![Tests](https://github.com/ulid/javascript/actions/workflows/test.yml/badge.svg)](https://github.com/ulid/javascript/actions/workflows/test.yml)\n[![codecov](https://codecov.io/gh/ulid/javascript/branch/master/graph/badge.svg)](https://codecov.io/gh/ulid/javascript)\n[![npm](https://img.shields.io/npm/dm/ulid.svg)](https://www.npmjs.com/package/ulid) [![npm](https://img.shields.io/npm/dy/ulid)](https://www.npmjs.com/package/ulid)\n\nULIDs are unique, sortable identifiers that work much in the same way as UUIDs, though with some improvements:\n\n * Lexicographically sortable\n * Canonically encoded as a 26 character string, as opposed to the 36 character UUID\n * Uses Crockford's base32 for better efficiency and readability (5 bits per character)\n * Monotonic sort order (correctly detects and handles the same millisecond)\n\nULIDs also provide:\n\n * 128-bit compatibility with UUID\n * 1.21e+24 unique IDs per millisecond\n * Case insensitivity\n * No special characters (URL safe)\n\nUUID can be suboptimal for many uses-cases because:\n\n- It isn't the most character efficient way of encoding 128 bits of randomness\n- UUID v1/v2 is impractical in many environments, as it requires access to a unique, stable MAC address\n- UUID v3/v5 requires a unique seed and produces randomly distributed IDs, which can cause fragmentation in many data structures\n- UUID v4 provides no other information than randomness which can cause fragmentation in many data structures\n\n## Installation\n\nInstall using NPM:\n\n```shell\nnpm install ulid --save\n```\n\n### Compatibility\n\nULID supports the following environments:\n\n| Version   | NodeJS    | Browsers      | React-Native  | Web Workers   | Edge Functions    |\n|-----------|-----------|---------------|---------------|---------------|-------------------|\n| v3        | v18+      | Yes           | Yes           | Yes           | ?                 |\n| v2        | v16+      | Yes           | No            | No            | No                |\n\nAdditionally, both ESM and CommonJS entrypoints are provided.\n\n## Usage\n\nTo quickly generate a ULID, you can simply import the `ulid` function:\n\n```typescript\nimport { ulid } from \"ulid\";\n\nulid(); // \"01ARZ3NDEKTSV4RRFFQ69G5FAV\"\n```\n\n### Seed Time\n\nYou can also input a seed time which will consistently give you the same string for the time component. This is useful for migrating to ulid.\n\n```typescript\nulid(1469918176385) // \"01ARYZ6S41TSV4RRFFQ69G5FAV\"\n```\n\n### Monotonic ULIDs\n\nTo generate monotonically increasing ULIDs, create a monotonic counter with `monotonicFactory`.\n\n> Note that the same seed time is being passed in for this example to demonstrate its behaviour when generating multiple ULIDs within the same millisecond\n\n```typescript\nimport { monotonicFactory } from \"ulid\";\n\nconst ulid = monotonicFactory();\n\n// Strict ordering for the same timestamp, by incrementing the least-significant random bit by 1\nulid(150000); // \"000XAL6S41ACTAV9WEVGEMMVR8\"\nulid(150000); // \"000XAL6S41ACTAV9WEVGEMMVR9\"\nulid(150000); // \"000XAL6S41ACTAV9WEVGEMMVRA\"\nulid(150000); // \"000XAL6S41ACTAV9WEVGEMMVRB\"\nulid(150000); // \"000XAL6S41ACTAV9WEVGEMMVRC\"\n\n// Even if a lower timestamp is passed (or generated), it will preserve sort order\nulid(100000); // \"000XAL6S41ACTAV9WEVGEMMVRD\"\n```\n\n### Pseudo-Random Number Generators\n\n`ulid` automatically detects a suitable (cryptographically-secure) PRNG. In the browser it will use `crypto.getRandomValues` and on NodeJS it will use `crypto.randomBytes`.\n\n#### Using `Math.random` (insecure)\n\nBy default, `ulid` will not use `Math.random` to generate random values. You can bypass this limitation by overriding the PRNG:\n\n```typescript\nconst ulid = monotonicFactory(() => Math.random());\n\nulid(); // \"01BXAVRG61YJ5YSBRM51702F6M\"\n```\n\n### Validity\n\nYou can verify if a value is a valid ULID by using `isValid`:\n\n```typescript\nimport { isValid } from \"ulid\";\n\nisValid(\"01ARYZ6S41TSV4RRFFQ69G5FAV\"); // true\nisValid(\"01ARYZ6S41TSV4RRFFQ69G5FA\"); // false\n```\n\n### ULID Time\n\nYou can encode and decode ULID timestamps by using `encodeTime` and `decodeTime` respectively:\n\n```typescript\nimport { decodeTime } from \"ulid\";\n\ndecodeTime(\"01ARYZ6S41TSV4RRFFQ69G5FAV\"); // 1469918176385\n```\n\nNote that while `decodeTime` works on full ULIDs, `encodeTime` encodes only the _time portion_ of ULIDs:\n\n```typescript\nimport { encodeTime } from \"ulid\";\n\nencodeTime(1469918176385); // \"01ARYZ6S41\"\n```\n\n### Tests\n\nInstall dependencies using `npm install` first, and then simply run `npm test` to run the test suite.\n\n### CLI\n\n`ulid` can be used on the command line, either via global install:\n\n```shell\nnpm install -g ulid\nulid\n```\n\nOr via `npx`:\n\n```shell\nnpx ulid\n```\n\nYou can also generate multiple IDs at the same time:\n\n```shell\nulid --count 15\n```\n\n## Specification\n\nYou can find the full specification, as well as information regarding implementations in other languages, over at [ulid/spec](https://github.com/ulid/spec).\n\n## Performance\n\nYou can test `ulid`'s performance by running `npm run bench`:\n\n```\nSimple ulid x 56,782 ops/sec ±2.50% (86 runs sampled)\nulid with timestamp x 58,574 ops/sec ±1.80% (87 runs sampled)\nDone!\n```\n","publish_time":1742149695739,"_cnpm_publish_time":1742149695739,"dist-tags":{"latest":"3.0.2"}}