{"id":13465008,"url":"https://github.com/novemberborn/ksuid","last_synced_at":"2025-04-12T16:37:33.722Z","repository":{"id":46331487,"uuid":"93953668","full_name":"novemberborn/ksuid","owner":"novemberborn","description":"Node.js implementation of K-Sortable Globally Unique IDs","archived":false,"fork":false,"pushed_at":"2021-10-30T15:31:30.000Z","size":405,"stargazers_count":259,"open_issues_count":0,"forks_count":28,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-06T08:36:00.289Z","etag":null,"topics":["hacktoberfest"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/novemberborn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-10T17:02:53.000Z","updated_at":"2025-03-01T04:34:14.000Z","dependencies_parsed_at":"2022-08-12T12:50:44.156Z","dependency_job_id":null,"html_url":"https://github.com/novemberborn/ksuid","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/novemberborn%2Fksuid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/novemberborn%2Fksuid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/novemberborn%2Fksuid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/novemberborn%2Fksuid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/novemberborn","download_url":"https://codeload.github.com/novemberborn/ksuid/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247457736,"owners_count":20941905,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest"],"created_at":"2024-07-31T14:00:54.914Z","updated_at":"2025-04-12T16:37:33.695Z","avatar_url":"https://github.com/novemberborn.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","Generation"],"sub_categories":["JavaScript"],"readme":"# ksuid\n\nA Node.js implementation of [Segment's KSUID library](https://github.com/segmentio/ksuid).\n\nYou may also be interested in [`ksuid-cli`](https://www.npmjs.com/package/ksuid-cli).\n\n## Installation\n\n```console\n$ npm install ksuid\n```\n\n## Usage\n\nRequire the module:\n\n```js\nconst KSUID = require('ksuid')\n```\n\n### Creation\n\nYou can create a new instance synchronously:\n\n```js\nconst ksuidFromSync = KSUID.randomSync()\n```\n\nOr asynchronously:\n\n```js\nconst ksuidFromAsync = await KSUID.random()\n```\n\nYou can also specify a specific time, either in milliseconds or as a `Date` object:\n\n```js\nconst ksuidFromDate = KSUID.randomSync(new Date(\"2014-05-25T16:53:20Z\"))\nconst ksuidFromMillisecondsAsync = await KSUID.random(1401036800000)\n```\n\nOr you can compose it using a timestamp and a 16-byte payload:\n\n```js\nconst crypto = require('crypto')\nconst yesterdayInMs = Date.now() - 86400 * 1000\nconst payload = crypto.randomBytes(16)\nconst yesterdayKSUID = KSUID.fromParts(yesterdayInMs, payload)\n```\n\nYou can parse a valid string-encoded KSUID:\n\n```js\nconst maxKsuid = KSUID.parse('aWgEPTl1tmebfsQzFP4bxwgy80V')\n```\n\nFinally, you can create a KSUID from a 20-byte buffer:\n\n```js\nconst fromBuffer = new KSUID(buffer)\n```\n\n### Properties\n\nOnce the KSUID has been created, use it:\n\n```js\nksuidFromSync.string // The KSUID encoded as a fixed-length string\nksuidFromSync.raw // The KSUID as a 20-byte buffer\nksuidFromSync.date // The timestamp portion of the KSUID, as a `Date` object\nksuidFromSync.timestamp // The raw timestamp portion of the KSUID, as a number\nksuidFromSync.payload // A Buffer containing the 16-byte payload of the KSUID (typically a random value)\n```\n\n### Comparisons\n\nYou can compare KSUIDs:\n\n```js\ntodayKSUID.compare(yesterdayKSUID) // 1\ntodayKSUID.compare(todayKSUID) // 0\nyesterdayKSUID.compare(todayKSUID) // -1\n```\n\nAnd check for equality:\n\n```js\ntodayKSUID.equals(todayKSUID) // true\ntodayKSUID.equals(yesterdayKSUID) // false\n```\n\n### Validation\n\nYou can check whether a particular buffer is a valid KSUID:\n\n```js\nKSUID.isValid(buffer) // Boolean\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnovemberborn%2Fksuid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnovemberborn%2Fksuid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnovemberborn%2Fksuid/lists"}