1
1
# LiteRT/UUID
2
2
3
+ [ ![ Strict TypeScript Checked] ( https://badgen.net/badge/TS/Strict " Strict TypeScript Checked ")] ( https://www.typescriptlang.org )
3
4
[ ![ npm version] ( https://img.shields.io/npm/v/@litert/uuid.svg?colorB=brightgreen )] ( https://www.npmjs.com/package/@litert/uuid " Stable Version ")
4
5
[ ![ License] ( https://img.shields.io/npm/l/@litert/uuid.svg?maxAge=2592000?style=plastic )] ( https://github.com/litert/uuid/blob/master/LICENSE )
5
6
[ ![ node] ( https://img.shields.io/node/v/@litert/uuid.svg?colorB=brightgreen )] ( https://nodejs.org/dist/latest-v8.x/ )
@@ -10,8 +11,8 @@ A uuid generator library for LiteRT framework.
10
11
11
12
## Requirement
12
13
13
- - TypeScript v2.7.1 (or newer)
14
- - Node.js v7 .0.0 (or newer)
14
+ - TypeScript v5.0.0 (or newer)
15
+ - Node.js v18 .0.0 (or newer)
15
16
16
17
## Installation
17
18
@@ -21,122 +22,36 @@ Install by NPM:
21
22
npm i @litert/uuid --save
22
23
```
23
24
24
- ## Algorithms
25
-
26
- Following algorithms are supported:
27
-
28
- ### [ Snowflake] ( https://blog.twitter.com/engineering/en_us/a/2010/announcing-snowflake.html )
29
-
30
- A 64-bit integer UUID algorithm provided by Twitter.
31
-
32
- ### [ Snowflake-SI] ( ./docs/en-US/Snowflake-SI.md )
33
-
34
- The Snowflake-SI algorithm generates safe integer (52-bits integer) for
35
- JavaScript, with capacity 128 uuids per milliseconds, and 64 machine parallel
36
- working.
37
-
38
- ### [ Snowflake-SI-vA] ( ./docs/en-US/Snowflake-SI-vA.md )
39
-
40
- A variant of Snowflake-SI algorithm.
41
-
42
- ## Samples
25
+ ## Documents
43
26
44
- ### Snowflake-SI Usage
27
+ - [ English ] ( https://litert.org/projects/uuid.js )
45
28
46
- ``` ts
47
- import * as libuuid from " @litert/uuid" ;
48
-
49
- const factory = UUID .SnowflakeBI .createFactory ();
50
-
51
- const makeUUID = factory .create ({
52
-
53
- /**
54
- * The machine ID.
55
- *
56
- * By default the uinBitWidth is 8, and the rest 5 bits is left to MID, so
57
- * that the mid must be between 0 and 31.
58
- */
59
- " machineId" : 1 ,
60
-
61
- /**
62
- * The base-clock of generator. Is unchangeable once setup.
63
- *
64
- * And it cannot be earlier than 2003-03-18T07:20:19.225Z.
65
- */
66
- " baseClock" : new Date (2004 , 0 , 1 , 0 , 0 , 0 , 0 ).getTime (),
67
- });
29
+ ## Algorithms
68
30
69
- console .log (makeUUID ()); // Generate a UUID
70
- console .log (makeUUID ()); // Generate a UUID
71
- console .log (makeUUID .uinCapacity ); // See the capacity of UUIDs in 1ms
72
- console .log (makeUUID .machineId ); // See the machine ID.
73
- console .log (new Date (makeUUID .baseClock )); // See the base-clock
74
- ```
31
+ - [ Snowflake] ( https://blog.twitter.com/engineering/en_us/a/2010/announcing-snowflake.html )
75
32
76
- ### Snowflake-SI Adjustment
77
-
78
- ``` ts
79
- import * as libuuid from " @litert/uuid" ;
80
-
81
- const factory = UUID .SnowflakeBI .createFactory ();
82
-
83
- const makeUUID = factory .create ({
84
-
85
- /**
86
- * The machine ID.
87
- *
88
- * Now the uinBitWidth has been set to 12, and only 1 bit is left to MID, so
89
- * that the mid can be either 1 or 0.
90
- */
91
- " mid" : 1 ,
92
-
93
- /**
94
- * The base-clock of generator. Is unchangeable once setup.
95
- *
96
- * And it cannot be earlier than 2003-03-18T07:20:20Z
97
- */
98
- " baseClock" : new Date (2004 , 0 , 1 , 0 , 0 , 0 , 0 ).getTime (),
99
-
100
- /**
101
- * The bit-width of UIN.
102
- */
103
- " uinBitWidth" : 12
104
- });
105
-
106
- console .log (makeUUID ()); // Generate a UUID
107
- console .log (makeUUID ()); // Generate a UUID
108
- console .log (makeUUID .uinCapacity ); // See the capacity of UUIDs in 1ms
109
- console .log (makeUUID .machineId ); // See the machine ID.
110
- console .log (new Date (makeUUID .baseClock )); // See the base-clock
111
- ```
33
+ A 64-bit integer UUID algorithm provided by X (Twitter).
112
34
113
- ### Snowflake-SI-vA Usage
35
+ - [ Snowflake-SI] ( ./docs/en-US/Snowflake-SI.md )
114
36
115
- ``` ts
116
- import * as libuuid from " @litert/uuid" ;
37
+ The Snowflake-SI algorithm generates safe integer (53-bits integer) for
38
+ JavaScript, with capacity 128 uuids per milliseconds, and 64 machine parallel
39
+ working.
117
40
118
- const factory = UUID . SnowflakeBIvA . createFactory ();
41
+ - UUIDv4
119
42
120
- const makeUUID = factory . create ({
43
+ The UUID version 4 algorithm generates random UUIDs.
121
44
122
- /**
123
- * The ID of machine, 0 ~ 1023
124
- */
125
- " machineId" : 333 ,
45
+ - UUIDv5
126
46
127
- /**
128
- * Calculate the cursor of the incremental sequence insides generator by
129
- * the last generated UUID.
130
- */
131
- " cursor" : factory .calculateCursor (1562244321456127 )
132
- });
47
+ The UUID version 5 algorithm generates UUIDs based on SHA-1 hash of a namespace and a name.
133
48
134
- console .log (nextUUID ());
135
- console .log (nextUUID ());
136
- console .log (nextUUID .machineId );
137
- console .log (Number .isSafeInteger (nextUUID ()));
49
+ ## Examples
138
50
139
- ```
51
+ - [ Snowflake] ( ./src/examples/Snowflake.ts )
52
+ - [ Snowflake-SI] ( ./src/examples/SnowflakeSI.ts )
53
+ - [ UUIDv4] ( ./src/examples/UUIDv4.ts )
54
+ - [ UUIDv5] ( ./src/examples/UUIDv5.ts )
140
55
141
56
## License
142
57
0 commit comments