Skip to content

{js} Very simple function to generate a unique id.

License

Notifications You must be signed in to change notification settings

aetonsi/js_uniqueId

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

js_uniqueId

Very simple function to generate a unique id.

Usage

// import the function
import uniqueId from './uniqueId.js';

// use it
const myId = uniqueId();
// pass a transformer function if you wish
const myCustomId = uniqueId(id => 'myprefix_' + id + '_mysuffix');

Technical info

  • Uniqueness is enforced simply by skipping 1 millisecond (empty loop), so that the generated id (timestamp) will be always unique.
  • Please pay attention: calling this function 1000 times in a row means blocking the thread for at least 1 second (1000 milliseconds)

About

{js} Very simple function to generate a unique id.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published