{"id":19315896,"url":"https://github.com/liweitianux/nanoid","last_synced_at":"2025-02-24T04:27:40.486Z","repository":{"id":184994562,"uuid":"615965574","full_name":"liweitianux/nanoid","owner":"liweitianux","description":"A tiny, secure, URL-friendly, unique string ID generator for C and Lua/LuaJIT.","archived":false,"fork":false,"pushed_at":"2023-09-04T06:42:41.000Z","size":45,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-06T03:43:02.281Z","etag":null,"topics":["c","ffi","lua","luajit","nanoid"],"latest_commit_sha":null,"homepage":"","language":"C","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/liweitianux.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":"2023-03-19T07:58:32.000Z","updated_at":"2024-12-13T11:55:56.000Z","dependencies_parsed_at":null,"dependency_job_id":"ce2ce197-1edd-485e-985b-927040cab6a7","html_url":"https://github.com/liweitianux/nanoid","commit_stats":null,"previous_names":["liweitianux/nanoid"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liweitianux%2Fnanoid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liweitianux%2Fnanoid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liweitianux%2Fnanoid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liweitianux%2Fnanoid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/liweitianux","download_url":"https://codeload.github.com/liweitianux/nanoid/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240417681,"owners_count":19798028,"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":["c","ffi","lua","luajit","nanoid"],"created_at":"2024-11-10T01:08:52.027Z","updated_at":"2025-02-24T04:27:40.441Z","avatar_url":"https://github.com/liweitianux.png","language":"C","readme":"Nano ID\n=======\n\nA tiny, secure, URL-friendly, unique string ID generator for C and Lua/LuaJIT\n(both C API and LuaJIT FFI API).\n\nThis Lua module is also available on\n[LuaRocks as `lua-nanoid`](https://luarocks.org/modules/liweitianux/lua-nanoid)\nand can be installed with `luarocks install lua-nanoid`.\n\nFor the Nano ID description and algorithm, please refer to\n[ai/nanoid](https://github.com/ai/nanoid).\n\nSupported operating systems:\n- DragonFly BSD\n- FreeBSD\n- NetBSD\n- OpenBSD\n- Linux\n- macOS\n\nSupported random sources:\n- `getentropy()`\n- `getrandom()`\n- `arc4random_buf()`\n- `/dev/urandom`\n\nC Interface\n-----------\n### Usage\n- Bundle the `nanoid.c` and `nanoid.h` source files with your project;\n- Or, link your program to the `libnanoid.so` library.\n\n### API\n```c\nvoid *\nnanoid_generate_r(void *buf, size_t buflen, const unsigned char *alphabet,\n                  size_t alphacnt);\n```\n\nGenerates an ID of length `buflen` and stores into `buf`, using the given\nalphabet `alphabet` of size `alphacnt`.  If `alphabet` is `NULL`, then the\ndefault alphabet is used; `alphacnt` is also ignored in this case.\n\nReturns a pointer to `buf` on success, or `NULL` on error with `errno`\nindicating the error reason.\n\nThis function is reentrantable (i.e., thread-safe), as indicated by the `_r`\nsuffix.\n\n```c\nconst char *\nnanoid_generate(const unsigned char *alphabet, size_t alphacnt);\n```\n\nGenerates an ID of the default length (i.e., 21 as defined by `NANOID_SIZE`),\nusing the alphabet `alphabet` of size `alphacnt` if it isn't `NULL`.\n\nThis function uses an *internal static buffer* to store the ID and returns a\npointer to the internal buffer on success, or `NULL` on error with `errno`\nindicating the error reason\n\nLua C Interface\n---------------\n### Usage\n```lua\nlocal nanoid = require(\"nanoid\")\n```\n\n### API\n```lua\nid = nanoid.generate(length?, alphabet?)\n```\n\nGenerates an ID.  Both `length` and `alphabet` are optional; specify them to\nuse custom length and/or alphabet.\n\nReturns the generated ID, or nil if error occurred.\n\nLuaJIT FFI Interface\n--------------------\n### Usage\n```lua\nlocal nanoid = require(\"nanoid.ffi\")\n```\n\n### API\nSame as the above Lua C interface.\n\nCLI Utility\n-----------\nThe `nanoid` CLI utility can be used to generate IDs, perform speed tests,\nand test for uniformity.\n\n```\n% ./nanoid -h\nNano ID command utility.\n\nGenerate ID:\n\u003e\u003e\u003e ./nanoid [-a alphabet] [-l length]\n    -a: specify the custom alphabet\n    -l: specify the custom ID length\n\nSpeed test:\n\u003e\u003e\u003e ./nanoid speed [-b burnin] [-c count] [-l length]\n    -b: specify the burn-in iterations (default: count/10)\n    -c: specify the test iterations (default: 1000000)\n    -l: specify the custom ID length\n\nDistribution uniformity test:\n\u003e\u003e\u003e ./nanoid test\n```\n\nBenchmark\n---------\n* Machine: ThinkPad T490, Intel i5-8265U 1.6GHz, 24GB RAM\n* Operating System: Debian GNU/Linux trixie (testing), amd64, Linux 6.3.0\n* Random source: `getentropy(3)` (glibc \u003e= 2.25)\n\n### C\n(Compiler: GCC 12.3.0)\n```\n% ./nanoid speed -c 2000000\nBurning in ... (n=200000)\nRunning speed test ... (n=2000000)\nSpeed: 295 ns/id, 3385528 id/s\n```\n\n### Lua 5.1\n(Lua: 5.1.5, installed from Debian repository)\n```\n% lua5.1 t/benchmark.lua\n\u003e\u003e\u003e Lua C Interface\nBurning in ... (n=200000)\nRunning test ... (n=2000000)\nSpeed: 484 ns/id, 2065343 id/s\n```\n\n### Lua 5.4\n(Lua: 5.4.4, installed from Debian repository)\n```\n% lua5.4 t/benchmark.lua\n\u003e\u003e\u003e Lua C Interface\nBurning in ... (n=200000)\nRunning test ... (n=2000000)\nSpeed: 414 ns/id, 2413884 id/s\n```\n\n### LuaJIT 2.1\n(LuaJIT: 2.1.0-beta3, installed from Debian repository)\n```\n% luajit t/benchmark.lua\n\u003e\u003e\u003e Lua C Interface\nBurning in ... (n=200000)\nRunning test ... (n=2000000)\nSpeed: 410 ns/id, 2438729 id/s\n\u003e\u003e\u003e LuaJIT FFI Interface\nBurning in ... (n=200000)\nRunning test ... (n=2000000)\nSpeed: 693 ns/id, 1441711 id/s\n```\n\nCredits\n-------\n* [ai/nanoid](https://github.com/ai/nanoid)\n* [mcmikecreations/nanoid\\_cpp](https://github.com/mcmikecreations/nanoid_cpp)\n* [leosbotelho/nanoid-c](https://github.com/leosbotelho/nanoid-c)\n\nLicense\n-------\nThe MIT License.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliweitianux%2Fnanoid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fliweitianux%2Fnanoid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliweitianux%2Fnanoid/lists"}