uniqueids
v1.1.1
Published
Generate unique ID
Downloads
4
Maintainers
Readme
UniqueIds
Installation
Browser
<script src="/path/to/UniqueIds.min.js"></script>
Node
npm install uniqueids
let uid = require('uniqueids')
Usage
//Usage without name
uid()
//out:'$-VM9F6ROYU8J9MZ0S2Y.0'
//Batch usage
console.log(uid())
console.log(uid())
console.log(uid())
console.log(uid())
//out:
//$-27S1JC2Z2BXJ9MXTQFO.0
//$-9GTXYPGVY6J9MXTQFO.1
//$-4EV7QGEQSBYJ9MXTQFO.2
//$-A9F825VM43EJ9MXTQFO.3
//Usage with name
uid('xxx')
//out:'$xxx-MF0ZV3YWRNJ9MZ2CWX.0'
uid('aaa')
//out:'$aaa-WIJS1QWU1SJ9MZ2FMX.0'
//Batch usage with name
console.log(uid('xxx'))
console.log(uid('xxx'))
console.log(uid('aaa'))
console.log(uid('aaa'))
//out:
//$xxx-7QPHK93FGD7J9MZ4WMR.0
//$xxx-R7L4ZDY8CXRJ9MZ4WMR.1
//$aaa-OXLFBCZSAJ9MZ4WMS.0
//$aaa-0WC22S6JO229J9MZ4WMS.1
Global options
CountMode
uid.$CountMode = true
console.log(uid())
console.log(uid())
//out:
//$-1
//$-2
Middleware
Namer
uid.$Namer = (v) => {
return `Name:${v}>`
}
console.log(uid())
//out:
//Name:$->8LCBQBC5WFEJ9NRU9T8.1
Processor
uid.$Processor = (v) => {
return v.toLowerCase()
}
console.log(uid())
//out:
//$-3ivv71g6c9jj9nru9tb.0
Validator
uid.$Validator = (v) => {
return `Id:[${v}]`
}
console.log(uid())
//out:
//Id:[$-Z6V1L57ICRJ9NRU9T6.0]
Prefix
uid.$Prefix '#'
console.log(uid())
//out:
//#-9Z9QBEH17PTJ9NRU9T9.0
Suffix
uid.$Suffix '_'
console.log(uid())
//out:
//$_B51IXY4J0TUJ9NRU9T9.1
Apis
uid( )
Get a UniqueId
uid( Name
:String )
Get a named UniqueId
uid.resetAll()
Reset all
uid.reset( Name
:String )
Reset Id by name
uid.init( Name
:String , Options
:{ } )
Init a Id
This is not necessary
Options:{
CountMode: Boolean, //set true to use Count Mode / set false to ignore global setting
prefix: String,
suffix: String
Namer: Function,
Processor: Function,
Validator: Function
}
uid.set( Name
:String , Options
:{ } )
Set Id's Options
Options as above