@@ -60,15 +60,15 @@ To quickly generate a ULID, you can simply import the `ulid` function:
6060``` typescript
6161import { ulid } from " ulid" ;
6262
63- ulid (); // 01ARZ3NDEKTSV4RRFFQ69G5FAV
63+ ulid (); // " 01ARZ3NDEKTSV4RRFFQ69G5FAV"
6464```
6565
6666### Seed Time
6767
6868You can also input a seed time which will consistently give you the same string for the time component. This is useful for migrating to ulid.
6969
7070``` typescript
71- ulid (1469918176385 ) // 01ARYZ6S41TSV4RRFFQ69G5FAV
71+ ulid (1469918176385 ) // " 01ARYZ6S41TSV4RRFFQ69G5FAV"
7272```
7373
7474### Monotonic ULIDs
@@ -83,14 +83,14 @@ import { monotonicFactory } from "ulid";
8383const ulid = monotonicFactory ();
8484
8585// Strict ordering for the same timestamp, by incrementing the least-significant random bit by 1
86- ulid (150000 ); // 000XAL6S41ACTAV9WEVGEMMVR8
87- ulid (150000 ); // 000XAL6S41ACTAV9WEVGEMMVR9
88- ulid (150000 ); // 000XAL6S41ACTAV9WEVGEMMVRA
89- ulid (150000 ); // 000XAL6S41ACTAV9WEVGEMMVRB
90- ulid (150000 ); // 000XAL6S41ACTAV9WEVGEMMVRC
86+ ulid (150000 ); // " 000XAL6S41ACTAV9WEVGEMMVR8"
87+ ulid (150000 ); // " 000XAL6S41ACTAV9WEVGEMMVR9"
88+ ulid (150000 ); // " 000XAL6S41ACTAV9WEVGEMMVRA"
89+ ulid (150000 ); // " 000XAL6S41ACTAV9WEVGEMMVRB"
90+ ulid (150000 ); // " 000XAL6S41ACTAV9WEVGEMMVRC"
9191
9292// Even if a lower timestamp is passed (or generated), it will preserve sort order
93- ulid (100000 ); // 000XAL6S41ACTAV9WEVGEMMVRD
93+ ulid (100000 ); // " 000XAL6S41ACTAV9WEVGEMMVRD"
9494```
9595
9696### Pseudo-Random Number Generators
@@ -104,7 +104,7 @@ By default, `ulid` will not use `Math.random` to generate random values. You can
104104``` typescript
105105const ulid = monotonicFactory (() => Math .random ());
106106
107- ulid (); // 01BXAVRG61YJ5YSBRM51702F6M
107+ ulid (); // " 01BXAVRG61YJ5YSBRM51702F6M"
108108```
109109
110110### Validity
@@ -118,6 +118,24 @@ isValid("01ARYZ6S41TSV4RRFFQ69G5FAV"); // true
118118isValid (" 01ARYZ6S41TSV4RRFFQ69G5FA" ); // false
119119```
120120
121+ ### ULID Time
122+
123+ You can encode and decode ULID timestamps by using ` encodeTime ` and ` decodeTime ` respectively:
124+
125+ ``` typescript
126+ import { decodeTime } from " ulid" ;
127+
128+ decodeTime (" 01ARYZ6S41TSV4RRFFQ69G5FAV" ); // 1469918176385
129+ ```
130+
131+ Note that while ` decodeTime ` works on full ULIDs, ` encodeTime ` encodes only the _ time portion_ of ULIDs:
132+
133+ ``` typescript
134+ import { encodeTime } from " ulid" ;
135+
136+ encodeTime (1469918176385 ); // "01ARYZ6S41"
137+ ```
138+
121139### Tests
122140
123141Install dependencies using ` npm install ` first, and then simply run ` npm test ` to run the test suite.
0 commit comments