{"id":20002638,"url":"https://github.com/leodutra/simpleflakes","last_synced_at":"2025-04-13T04:16:07.105Z","repository":{"id":47054518,"uuid":"49390401","full_name":"leodutra/simpleflakes","owner":"leodutra","description":"Fast and test-driven distributed 64-bit ID generation, using pure JavaScript, for Node.js.","archived":false,"fork":false,"pushed_at":"2024-10-08T06:07:25.000Z","size":269,"stargazers_count":33,"open_issues_count":3,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-13T04:15:47.933Z","etag":null,"topics":["generator","guid","microservices","sharding","uid"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/simpleflakes","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/leodutra.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2016-01-10T23:26:13.000Z","updated_at":"2023-11-03T16:06:09.000Z","dependencies_parsed_at":"2024-06-18T22:48:45.722Z","dependency_job_id":"d4d6846c-feda-41e4-845e-c7ee86886a9d","html_url":"https://github.com/leodutra/simpleflakes","commit_stats":{"total_commits":85,"total_committers":3,"mean_commits":"28.333333333333332","dds":0.02352941176470591,"last_synced_commit":"7144690fd02af62ed79a0737e7d35ecd0a90551f"},"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leodutra%2Fsimpleflakes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leodutra%2Fsimpleflakes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leodutra%2Fsimpleflakes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leodutra%2Fsimpleflakes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leodutra","download_url":"https://codeload.github.com/leodutra/simpleflakes/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248661719,"owners_count":21141451,"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":["generator","guid","microservices","sharding","uid"],"created_at":"2024-11-13T05:22:31.653Z","updated_at":"2025-04-13T04:16:07.068Z","avatar_url":"https://github.com/leodutra.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# simpleflakes\n\n[![travis status][travis-badge]][travis-link]\n[![npm][npm-badge]][npm-link]\n\u003c!-- [![codacy quality][codacy-quality-badge]][codacy-quality-link]\n[![codacy coverage][codacy-coverage-badge]][codacy-coverage-link] --\u003e\n[![coveralls status][coveralls-badge]][coveralls-link] [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fleodutra%2Fsimpleflakes.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fleodutra%2Fsimpleflakes?ref=badge_shield)\n \n[![tonicdev demo][demo-tonicdev-badge]][demo-tonicdev-link]\n[![david dep status][dependencies-badge]][dependencies-url]\n[![david dev dep status][dependencies-dev-badge]][dependencies-dev-url]  \n\nSimpleflake is the smartest way to generate a 64-bit + time-ordered + snowflake based ID. [See the presentation!](http://akmanalp.com/simpleflake_presentation/)\n\n### Test-driven, pure JavaScript\nThis port is test-driven and no release goes out without tests.  \n**Also, this library does not rely on low-level bindings, with OpenSSL, libgmp or anything beyond pure JavaScript.**\n\nAssumes [original Python implementation](https://simpleflake.readthedocs.org/en/latest/) as reference and fixes epoch (starts on `2000-01-01T00:00:00.000Z` (UTC) while Python API v0.1.5 epoch starts on `2000-01-01T05:00:00.000Z`).  \n\n**simpleflakes** uses the TC39 BigInt implementation when running on newer versions of Node.js. When BigInt is not available, [Fedor Indutny's big number library (bn.js)](https://github.com/indutny/bn.js) is used as the fastest fallback for big number calculations.\n\n### How to Install:\n\n```sh\nnpm install simpleflakes --save\n```\n\n### Usage:\n```js\nconst { simpleflake } = require('simpleflakes');\n\nconst flakeBigInt = simpleflake()\n\n// simpleflake(\n//    timestamp = Date.now(), \n//    random_bits = 23-bit random, \n//     epoch = Date.UTC(2000, 0, 1)\n// )\n// returns BigInt on newer Node.js or bn.js BigNum on older engines.\n\nflakeBigInt.toString();       // 4234673179811182512\nflakeBigInt.toString(16);     // 3ac494d21e84f7b0\nflakeBigInt.toString(2);      // 11101011000100...\nflakeBigInt.toString(36);     // 20rfh5\n```\nYou can check the [original Python API 0.1.5](https://simpleflake.readthedocs.org/en/latest/) documentation for more info.  \n\n\n### Reference\n```js\n// Main flake function and its defaults\nsimpleflake(\n    timestamp = Date.now(), \n    random_bits = 23-bit random, \n    epoch = Date.UTC(2000, 0, 1)\n)\n\n// Static constant epoch for simpleflake timestamps, starts at the year 2000  \nsimpleflake.SIMPLEFLAKE_EPOCH // const = 946702800\n\n// Show binary digits of a number, pads to 64 bits unless specified.\nsimpleflake.binary(number, padding=true)\n\n// Extract a portion of a bit string. Similar to substr().\nsimpleflake.extractBits(data, shift, length)\n\n// Parses a simpleflake and returns a named tuple with the parts.\nsimpleflake.parseSimpleflake(flake)\n\n// original API alias for SimpleFlake class, from the Python API\nsimpleflake.simpleflakeStruct\n\n// same as simpleflake.simpleflakeStruct\nSimpleFlake.SimpleFlakeStruct\n```\n\n\n### License:  \n[MIT](https://raw.githubusercontent.com/leodutra/simpleflakes/master/LICENSE)\n\n[npm-badge]: https://img.shields.io/npm/v/simpleflakes.svg?style=flat\n[travis-badge]: http://img.shields.io/travis/leodutra/simpleflakes.svg?style=flat\n[codacy-coverage-badge]: https://api.codacy.com/project/badge/Coverage/f71ef817e5f14a9ab3b8b2cb6fabf51a\n[codacy-quality-badge]: https://api.codacy.com/project/badge/Grade/f71ef817e5f14a9ab3b8b2cb6fabf51a\n[coveralls-badge]: https://img.shields.io/coveralls/leodutra/simpleflakes.svg?style=flat\n\n[npm-link]: https://www.npmjs.com/package/simpleflakes\n[travis-link]: https://travis-ci.org/leodutra/simpleflakes\n[codacy-quality-link]: https://www.codacy.com/app/leodutra/simpleflakes\n\n[codacy-coverage-link]: https://www.codacy.com/app/leodutra/simpleflakes?utm_source=github.com\u0026utm_medium=referral\u0026utm_content=leodutra/simpleflakes\u0026utm_campaign=Badge_Coverage\n[codacy-quality-link]: https://www.codacy.com/app/leodutra/simpleflakes?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=leodutra/simpleflakes\u0026amp;utm_campaign=Badge_Grade\n[coveralls-link]: https://coveralls.io/github/leodutra/simpleflakes\n[demo-tonicdev-link]: https://tonicdev.com/leodutra/simpleflakes-demo/1.0.13\n\n[dependencies-url]: https://david-dm.org/leodutra/simpleflakes\n[dependencies-badge]: \thttps://img.shields.io/david/leodutra/simpleflakes.svg?style=flat\n[dependencies-dev-url]: https://david-dm.org/leodutra/simpleflakes#info=devDependencies\u0026view=table\n[dependencies-dev-badge]: \thttps://img.shields.io/david/dev/leodutra/simpleflakes.svg?style=flat\n[demo-tonicdev-badge]: https://img.shields.io/badge/demo-%40tonicdev-008bb8.svg?style=flat\n\n\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fleodutra%2Fsimpleflakes.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fleodutra%2Fsimpleflakes?ref=badge_large)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleodutra%2Fsimpleflakes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleodutra%2Fsimpleflakes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleodutra%2Fsimpleflakes/lists"}