1.0.0 • Published 6 months ago

@lokalise/id-utils v1.0.0

Weekly downloads
-
License
-
Repository
-
Last release
6 months ago

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