You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+20-2Lines changed: 20 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,6 +27,7 @@ Instead, herein is proposed ULID:
27
27
- Uses Crockford's base32 for better efficiency and readability (5 bits per character)
28
28
- Case insensitive
29
29
- No special characters (URL safe)
30
+
- Monotonic sort order (correctly detects and handles the same millisecond)
30
31
31
32
## JavaScript
32
33
@@ -43,8 +44,13 @@ import ulid from 'ulid'
43
44
44
45
ulid() // 01ARZ3NDEKTSV4RRFFQ69G5FAV
45
46
46
-
// You can also input a seed time which will consistently give you the same time component
47
-
// This is useful for migrating to ulid
47
+
// You can also input a seed time which will consistently
48
+
// give you the same string for the time component. This is
49
+
// useful for migrating to ulid.
50
+
//
51
+
// Note that multiple calls with the same seed time will
52
+
// still monotonically increase the random component for
53
+
// strict sort order.
48
54
ulid(1469918176385) // 01ARYZ6S41TSV4RRFFQ69G5FAV
49
55
```
50
56
@@ -118,6 +124,18 @@ Below is the current specification of ULID as implemented in this repository.
118
124
119
125
The left-most character must be sorted first, and the right-most character sorted last (lexical order). The default ASCII character set must be used. Within the same millisecond, sort order is not guaranteed
120
126
127
+
#### Monotonicity
128
+
129
+
When generating a ULID within the same millisecond, we can provide some
130
+
guarantees regarding sort order. Namely, if the same millisecond is detected, the `random` component is incremented by 1 bit in the least significant bit position (with carrying). For example:
131
+
132
+
```javascript
133
+
ulid() // 01BX5ZZKBKACTAV9WEVGEMMVRZ
134
+
ulid() // 01BX5ZZKBKACTAV9WEVGEMMVS0
135
+
```
136
+
137
+
If, in the extremely unlikely event that, you manage to generate at most 80 ^ 2 ULIDs within the same millisecond, or cause the random component to overflow in any other way, the generation will fail.
0 commit comments