{"id":22160369,"url":"https://github.com/rozek/locally-unique-id-generator","last_synced_at":"2025-07-26T09:31:33.523Z","repository":{"id":114382900,"uuid":"380408444","full_name":"rozek/locally-unique-id-generator","owner":"rozek","description":"trivial generator for ids which are unique within an application","archived":false,"fork":false,"pushed_at":"2024-09-10T04:57:15.000Z","size":71,"stargazers_count":5,"open_issues_count":1,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-23T05:02:45.058Z","etag":null,"topics":["unique-id"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rozek.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-06-26T03:55:25.000Z","updated_at":"2024-10-21T13:42:25.000Z","dependencies_parsed_at":null,"dependency_job_id":"f9e62af8-b345-49f0-8c46-1dbb696bcd75","html_url":"https://github.com/rozek/locally-unique-id-generator","commit_stats":{"total_commits":47,"total_committers":2,"mean_commits":23.5,"dds":"0.021276595744680882","last_synced_commit":"86cf75588ffa3de5a01782c4ffeeebb1b789b1c2"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rozek%2Flocally-unique-id-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rozek%2Flocally-unique-id-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rozek%2Flocally-unique-id-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rozek%2Flocally-unique-id-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rozek","download_url":"https://codeload.github.com/rozek/locally-unique-id-generator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227668795,"owners_count":17801513,"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":["unique-id"],"created_at":"2024-12-02T04:07:36.128Z","updated_at":"2024-12-02T04:07:36.803Z","avatar_url":"https://github.com/rozek.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# locally-unique-id-generator #\n\ntrivial generator for ids which are unique within an application\n\n**NPM users**: please consider the [Github README](https://github.com/rozek/locally-unique-id-generator/blob/main/README.md) for the latest description of this package (as updating the docs would otherwise always require a new NPM package version)\n\n\u003e Just a small note: if you like this module and plan to use it, consider \"starring\" this repository (you will find the \"Star\" button on the top right of this page), so that I know which of my repositories to take most care of.\n\n## Installation ##\n\n`locally-unique-id-generator` may be used as an ECMAScript module (ESM), a CommonJS or AMD module or from a global variable.\n\nYou may either install the package into your build environment using [NPM](https://docs.npmjs.com/) with the command\n\n```\nnpm install locally-unique-id-generator\n```\n\nor load the plain script file directly\n\n```html\n\u003cscript src=\"https://unpkg.com/locally-unique-id-generator\"\u003e\u003c/script\u003e\n```\n\n## Access ##\n\nHow to access the package depends on the type of module you prefer\n\n* ESM (or Svelte): `import newUniqueId from 'locally-unique-id-generator'`\n* CommonJS: `const newUniqueId = require('locally-unique-id-generator')`\n* AMD: `require(['locally-unique-id-generator'], (newUniqueId) =\u003e {...})`\n\nAlternatively, you may access the global variable `newUniqueId` directly.\n\n## Usage within Svelte ##\n\nFor Svelte it is recommended to import the package within a module context:\n\n```html\n\u003cscript context=\"module\"\u003e\n  import newUniqueId from 'locally-unique-id-generator'\n\u003c/script\u003e\n\n\u003cscript\u003e\n  console.log('next unique id:',newUniqueId())\n\u003c/script\u003e\n```\n\n## Usage as ECMAscript, CommonJS or AMD Module (or as a global Variable) ##\n\nLet's assume that you already \"required\" or \"imported\" (or simply loaded) the module according to your local environment. In that case, you may use it as follows:\n\n```javascript\nconsole.log('next unique id:',newUniqueId())\n```\n\n## Background Information ##\n\nFrom time to time, it may be necessary to generate unique ids (e.g., for the ids of data lists in a web page). This module provides a trivial solution for this problem by using a counter to generate ids of the form `uid-\u003ccounter\u003e`. Within the same application, such keys are guaranteed to be unique (unless more than 2^53 of them are created while that application is running) - but only while the application is running: as soon as the application is restarted, the counter starts from 0 again.\n\nIf you need universally unique ids, you should better generate UUIDs/GUIDs of type 4 (see below)\n\n## JavaScript API ##\n\nThis package offers a JavaScript `default` export, which may be imported (or `required`) as shown in the \"Access\" section above.\n\nWith such an import, the JavaScript API can be used as follows:\n\n* **`newUniqueId()`** - returns a new, unique literal id of the form `uid-\u003ccounter\u003e` with \"counter\" starting at 1\n\n## Example ##\n\nAn example is available on the Svelte REPL - feel free to play with it!\n\n* [basic example](https://svelte.dev/repl/34407dd75db14206becd97b1441720c6)\n\n## Alternative for Universally Unique Ids ##\n\nUUIDs/GUIDs of type 4 may be easily created using the following code:\n\n```\n   function newUUID ():string {\n    let Id = '', IdPart\n    IdPart = Math.round(Math.random()*0xffffffff).toString(16)\n      Id += IdPart + '00000000'.slice(IdPart.length) + '-'\n      IdPart = Math.round(Math.random()*0xffff).toString(16)\n      Id += IdPart + '0000'.slice(IdPart.length) + '-4'\n      IdPart = Math.round(Math.random()*0xfff).toString(16)\n      Id += IdPart + '000'.slice(IdPart.length) + '-'\n      IdPart = Math.round(Math.random()*0x3fff+0x8000).toString(16)\n      Id += IdPart + '-'\n      IdPart = Math.round(Math.random()*0xffffffffffff).toString(16)\n      Id += IdPart + '000000000000'.slice(IdPart.length)\n    return Id.toLowerCase()\n  }\n```\n\nprovided that cryptographic uniqueness is not required.\n\n## Build Instructions ##\n\nYou may easily build this package yourself.\n\nJust install [NPM](https://docs.npmjs.com/) according to the instructions for your platform and follow these steps:\n\n1. either clone this repository using [git](https://git-scm.com/) or [download a ZIP archive](https://github.com/rozek/locally-unique-id-generator/archive/refs/heads/main.zip) with its contents to your disk and unpack it there \n2. open a shell and navigate to the root directory of this repository\n3. run `npm install` in order to install the complete build environment\n4. execute `npm run build` to create a new build\n\nYou may also look into the author's [build-configuration-study](https://github.com/rozek/build-configuration-study) for a general description of his build environment.\n\n## License ##\n\n[MIT License](LICENSE.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frozek%2Flocally-unique-id-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frozek%2Flocally-unique-id-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frozek%2Flocally-unique-id-generator/lists"}