Skip to content

Commit fb9a7bf

Browse files
committed
refactor(project): refactored with more simple APIs
1 parent b70c138 commit fb9a7bf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+5094
-2044
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
/libs/
2-
/samples/
1+
/lib/
2+
/examples/
33
/node_modules/
4+
typedoc-sidebar.json

.husky/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_

.husky/commit-msg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npx --no-install commitlint --edit "$1"
5+
npm run typecheck && npm run lint && npm run test

.npmignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,12 @@
44
/node_modules/
55
/.gitignore
66
/.npmignore
7-
/tslint.json
87
/tsconfig.json
8+
/examples/
9+
/src/examples/
10+
/.eslintrc
11+
/.eslintignore
12+
/utils/
13+
/.husky/
14+
/eslint.config.js
15+
/commitlint.config.js

.vscode/launch.json

Lines changed: 0 additions & 74 deletions
This file was deleted.

CHANGES.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Changes Logs
22

3+
## v2.0.0
4+
5+
- feat(algo): added implements of GUIDv4 algorithm.
6+
- feat(algo): added implements of GUIDv5 algorithm.
7+
- fix(algo): allow Snowflake using custom epoch.
8+
- fix(algo): implement Snowflake-SI with more customization options.
9+
- deprecate(algo): removed the Snowflake-SI-vA algorithm, which is no longer recommended.
10+
- test(project): added unit tests.
11+
- deprecate(deps): removed all runtime dependencies.
12+
313
## v1.0.0
414

515
- Refactored the project.

README.md

Lines changed: 21 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# LiteRT/UUID
22

3+
[![Strict TypeScript Checked](https://badgen.net/badge/TS/Strict "Strict TypeScript Checked")](https://www.typescriptlang.org)
34
[![npm version](https://img.shields.io/npm/v/@litert/uuid.svg?colorB=brightgreen)](https://www.npmjs.com/package/@litert/uuid "Stable Version")
45
[![License](https://img.shields.io/npm/l/@litert/uuid.svg?maxAge=2592000?style=plastic)](https://github.com/litert/uuid/blob/master/LICENSE)
56
[![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.
1011

1112
## Requirement
1213

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)
1516

1617
## Installation
1718

@@ -21,122 +22,36 @@ Install by NPM:
2122
npm i @litert/uuid --save
2223
```
2324

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
4326

44-
### Snowflake-SI Usage
27+
- [English](https://litert.org/projects/uuid.js)
4528

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
6830

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)
7532

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).
11234

113-
### Snowflake-SI-vA Usage
35+
- [Snowflake-SI](./docs/en-US/Snowflake-SI.md)
11436

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.
11740

118-
const factory = UUID.SnowflakeBIvA.createFactory();
41+
- UUIDv4
11942

120-
const makeUUID = factory.create({
43+
The UUID version 4 algorithm generates random UUIDs.
12144

122-
/**
123-
* The ID of machine, 0 ~ 1023
124-
*/
125-
"machineId": 333,
45+
- UUIDv5
12646

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.
13348

134-
console.log(nextUUID());
135-
console.log(nextUUID());
136-
console.log(nextUUID.machineId);
137-
console.log(Number.isSafeInteger(nextUUID()));
49+
## Examples
13850

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)
14055

14156
## License
14257

0 commit comments

Comments
 (0)