short, sortable uuid. convert uuid into base 62 string along with coded timestamp.
<script src="<path-to>/suuid.bundle.min.js"></script>
<script>
var id = suuid();
var ts = suuid.timestamp(id);
var short = suuid.encode("abc0123");
</script>
sample output ( try with test/gen.ls ):
generated suuid: VLrDdVo3089xs4wK5IT9VH198BCrY5X
timestamp: 1780832488536 ( Sun Jun 07 2026 19:41:28 GMT+0800 (Taipei Standard Time) )
suuid(opt): randomly return a suuid ifoptis omitted. otherwise,optcan be:- a
base16string: return encoded corresponding string. - an object
{id, timestamp}: return an encodedidprefix with timestamp, iftimestampis true.id: a base16 string to encode.timestamp: true if prefix timestamp before encoded id. default true.
- a
suuid.timestamp(id): get timestamp ( in epoch unix timestamp ) from given suuidsuuid.encode(s): simply encode abase16string tobase62string ( with our charmap, see below )
suuid does following things:
-
prefix uuid(v4) with epoch unix timestamp
-
remove separator ( dash ) in uuid.
-
encodes values from hexadecimal to 62-based string with following charmap: ( url-safe chars )
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
while length of codes corresponding to uuid part are fixed, length of the timestamp code varys. The timestamp chars will be:
- 7 chars long before 2082AD
- 8 chars long before 8887AD
- 9 chars long before 430804AD
and the length of remaining part ( coded uuid, for randomness ) will be always 24 chars long. thus, to sort suuid before 430804AD, simply add padding zeros before id to make it 33 chars long.
-
- 18 bytes
- no timestamp
-
- 48-bit timestamp + 80-bit entropy
- base32 encoding, fixed length ( 26 character string. )
- avoiding similar chars ( like
1IiJj) and is case insensitive.
- avoiding similar chars ( like
- timestamped ( 1ms precision )
- overflow after 10889AD
-
- 32-bit timestamp + 128-bit entropy
- base62 encoding (
0-9a-zA-Z), fixed length ( 27 characters string. ) - timestamped ( 1s precision )
- offset to start from
2014-03-05 - overflow after 2150AD
- offset to start from
-
- varied length timestamp ( 42-bit+ ) + 128-bit entropy
- base62 encoding (
0-9a-zA-Z), varied length ( 31 characters + ) - timestamped ( 1ms precision )
- unix epoch timestamp ( since
1970-01-01)
- unix epoch timestamp ( since
-
- TBD
- try to add timestamp in uuid.
- just a draft, and was expired.
- Github Repo
MIT