{"id":18581947,"url":"https://github.com/chilts/yid","last_synced_at":"2025-04-10T11:35:45.935Z","repository":{"id":57403702,"uuid":"119156300","full_name":"chilts/yid","owner":"chilts","description":"Simple ID generator. A timestamp plus random digits.","archived":false,"fork":false,"pushed_at":"2025-02-15T03:50:10.000Z","size":12,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-02T06:41:18.946Z","etag":null,"topics":["id","identifier","nodejs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chilts.png","metadata":{"files":{"readme":"ReadMe.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-01-27T10:59:14.000Z","updated_at":"2025-02-15T03:50:10.000Z","dependencies_parsed_at":"2025-03-03T17:36:06.855Z","dependency_job_id":null,"html_url":"https://github.com/chilts/yid","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chilts%2Fyid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chilts%2Fyid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chilts%2Fyid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chilts%2Fyid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chilts","download_url":"https://codeload.github.com/chilts/yid/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248208688,"owners_count":21065205,"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":["id","identifier","nodejs"],"created_at":"2024-11-07T00:08:31.887Z","updated_at":"2025-04-10T11:35:40.921Z","avatar_url":"https://github.com/chilts.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# yid #\n\n## Synopsis ##\n\n```js\nconst yid = require('yid')\n\nconsole.log(yid())\n// -\u003e 1517049989798-7496988299172\n```\n\nA `yid` is:\n\n* always 27 chars long\n* has two parts:\n  * a timestamp\n  * a random string\n* is of the form `\\d{13}-\\d{13}`\n* starts off with `Date.now()`\n* uses a substring of https://www.npmjs.com/package/math-random for the second part\n\n## `yid.fromDate(d)` ##\n\nPass in a `Date` object, and get a yid back. This is great if you want to\ntimestamp something in the past or the future, rather than right now.\n\n\n```js\nconst yid = require('yid')\n\n// get the date at the start of the day\nconst date = new Date()\ndate.setUTCHours(0)\ndate.setUTCMinutes(0)\ndate.setUTCSeconds(0)\ndate.setUTCMilliseconds(0)\nconsole.log(yid.fromDate(date))\n// -\u003e 1635984000000-4266433825250\n```\n\n## `yid.asDate(id)` ##\n\nReturns the numbers from the first part of the `id` as a `Date()`.\n\n```js\nyid.asDate(id)\n// -\u003e Date: \"2018-01-27T10:46:29.798Z\"\n```\n\n## `yid.asEpoch(id)` ##\n\nReturns the numbers from the first part of the `id` as a `Number()`.\n\n```js\nyid.asEpoch(id)\n// -\u003e Number: 1517049989798\n```\n\n## `yid.asRandom(id)` ##\n\nReturns the random collection of digits from the second part of the `id`.\n\n```js\nyid.asRandom(id)\n// -\u003e \"7496988299172\"\n```\n\n## Why? ##\n\nWhy another ID generating library?\n\nI already wrote [zid](https://www.npmjs.com/package/zid) and [flake](https://www.npmjs.com/package/flake) (a long time\nago) and they all have uses. The use for this one is to generate FAST but UNIQUE distributed IDs with no central server\nto talk to and no co-ordination required.\n\nA secondary property is that they are approximately sortable across servers.\n\nI got the idea from Google Keep, since the notes have IDs as follows, whereby the first secion is just `Date.now()`:\n\n* '1517050593526.6629835825', e.g. https://keep.google.com/u/1/#NOTE/1517050593526.6629835825\n\n## Author ##\n\nAndrew Chilton.\n\n## License ##\n\nISC.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchilts%2Fyid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchilts%2Fyid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchilts%2Fyid/lists"}