@lokalise/id-utils
v2.2.0
Published
This package adds common utils that provide IDs compatible with CockroachDB UUID type.
Downloads
11,965
Maintainers
Keywords
Readme
Id generation utils
This package adds common utils that provide IDs compatible with CockroachDB UUID type.
Usage
import { generateMonotonicUuid } from '@lokalise/id-utils'
const newId = generateMonotonicUuid()
Provided ID conforms with an abstract UUID representation (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) and is generated by ULID algorithm, which makes it lexicographically sortable. You can use basic language functions to sort by these ids:
import { generateMonotonicUuid } from '@lokalise/id-utils'
const ids = []
for (const i of Array(1000)) {
ids.push(generateMonotonicUuid())
}
const sorted = ids.sort()
// sorted == ids
UUID7
This package also provides a function to generate a UUID7. It is a:
import { generateUuid7 } from '@lokalise/id-utils'
generateUuid7()