Skip to content

Generate a random id string with a prefix and allows to configurate the chars and length

License

Notifications You must be signed in to change notification settings

jesusgm/random-id-gen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

random-id-gen

Generate a random id with customizable prefix, sufix, length and chars

Instalation

    npm install random-id-gen --save

Use

const id = rig(config);

Config is a object with the next default values:

{
  "prefix": "",
  "sufix": "",
  "length": 25,
  "letters": "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
  "numbers": "0123456789",
  "specialChars": "-_+!&@%=¿?¡!"
}

You can combine as you want

Examples of use

import rig from "random-id-gen";

//default id
const id = rig();
console.log(id); //WrDxw27xyb_w@8UFTy_0TGfrR

//custom length
const id = rig({ length: 10 });
console.log(id); //hh4-rRedj?

//no letters
const id = rig({ letters: "" });
console.log(id); //!&0_5@978_

//no special chars
const id = rig({ specialChars: "" });
console.log(id); //XAe7NSsz8p

About

Generate a random id string with a prefix and allows to configurate the chars and length

Resources

License

Stars

Watchers

Forks

Packages

No packages published