-
Notifications
You must be signed in to change notification settings - Fork 3
/
example.js
63 lines (51 loc) · 1.25 KB
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const anyid = require("anyid").anyid;
console.log('Single section, random value:',
anyid().encode('Aa0').length(21).random().id()
);
console.log('Multiple sections, fix prefix and timestamp:',
anyid()
.encode('0A-IO')
.section(anyid().fixed(process.pid))
.delimiter('-')
.section(anyid().time())
.id()
);
const nanotime = () => {
return process.hrtime()[1];
};
console.log('Function value:',
anyid()
.encode('Aa0')
.section(anyid().time('s'))
.delimiter('+')
.section(anyid().of(nanotime))
.id()
);
console.log('Use different charset in sections:',
anyid()
.encode('A-IO')
.section(anyid().length(3).random())
.delimiter(' ')
.section(anyid().encode('0').length(3).random())
.delimiter(' ')
.section(anyid().length(3).random())
.id()
);
console.log('Single variable:',
anyid()
.encode('Aa0')
.section(anyid().variable())
.delimiter('-')
.section(anyid().time())
.id(Buffer.from('user-xxx'))
);
console.log('Multiple variables:',
anyid()
.encode('Aa0')
.section(anyid().variable('countryId'))
.delimiter('-')
.section(anyid().variable('userId'))
.delimiter('-')
.section(anyid().length(5).random())
.id({ countryId: 86, userId: 635023 })
);