stamp id
v1.0.2
Library to generate and validate ID by pattern.
npm i stamp-id
import stampId from 'stamp-id'
// generate
const id = stampId.generate()
// validate
const isValid = stampId.validate(id)
// 1
const id = stampId.generate('ddd-dd-dddd')
// --> "253-15-7920
// 2
stampId.setAlphabet('N', '23456789')
const id = stampId.generate('+1 Ndd-Ndd-dddd')
// --> "+1 517-724-3835"
// 3
stampId.setAlphabet('R', 'AAAAAAAAAB')
const id = stampId.generate('R')
// --> "A" (90% probability) or "B" (10% probability)
'b': '01',
'd': '0123456789',
'h': '0123456789abcdef',
'H': '0123456789ABCDEF',
'c': 'abcdefghijklmnopqrstuvwxyz',
'C': 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'a': 'abcdefghijklmnopqrstuvwxyz0123456789',
'A': 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
'z': 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
// 1
const id = 'FRIDAY13'
const isValid = stampId.validate(id, 'CCCCCC13')
// --> true
// 1
stampId.setAlphabet('?', '-+./')`
const id = 'a0+b1/z9.gg-zz'
const isValid = stampId.validate(id, 'aa?aa?aa?aa?aa')
// --> true
string
Generate new random id.
boolean
Validate id against pattern.
Add new or update existing alphabet.
string
Generate new random id.
Kind: global function
Returns: string
- Random id.
Param | Type | Default | Description |
---|---|---|---|
[pattern] | string |
"zzzzzzzz" |
Text pattern of desired id. |
boolean
Validate id against pattern.
Kind: global function
Returns: boolean
- True if the id could be generated with the pattern.
Param | Type | Default | Description |
---|---|---|---|
id | string |
Id to test. | |
[pattern] | string |
"zzzzzzzz" |
Text pattern. |
[flags] | string |
Flags string ("i" means ignore case). |
Add new or update existing alphabet.
Kind: global function
Param | Type | Description |
---|---|---|
code | string |
One character which will be used in patterns. |
abc | string |
Alphabet chars. |