Migrate from other libraries
Keep familiar formats while moving to direct, portable imports.
Migration is usually an import change first. Keep the stored identifier format stable, then move generation behind the new direct entry point. Every example below shows the value returned by the uniku generator.
From uuid
- import { v4 as uuidv4, v5 as uuidv5, v7 as uuidv7 } from 'uuid'
+ import { uuidv4 } from 'uniku/uuid/v4'
+ import { uuidv5 } from 'uniku/uuid/v5'
+ import { uuidv7 } from 'uniku/uuid/v7'const randomId: string = uuidv4()
const orderedId: string = uuidv7()
const derivedId: string = uuidv5('www.example.com', uuidv5.DNS)uniku generates UUID v4, v5, and v7. There is no uniku equivalent for v1, v3, or v6; keep the uuid package for those, or generate them elsewhere and only use uniku for v4, v5, and v7 values.
The rest of uuid's API maps onto uniku's per-generator methods, scoped to the version you imported:
uuid | uniku |
|---|---|
parse(id) | uuidv4.toBytes(id) / uuidv5.toBytes(id) / uuidv7.toBytes(id) accept any UUID version, plus NIL and MAX. Unlike parse(), they validate only the length, the separators, and the hex characters — not the version nibble or the RFC variant |
stringify(bytes) | uuidv4.fromBytes(bytes) / uuidv5.fromBytes(bytes) / uuidv7.fromBytes(bytes) |
validate(id) | uuidv4.isValid(id) / uuidv5.isValid(id) / uuidv7.isValid(id) |
version(id) | Implied by which isValid matches: each accepts only its own version. |
Name-based UUID v5
uuid's v5(name, namespace) becomes uuidv5(name, namespace), with the same argument order. The buffer form v5(name, namespace, buf, offset) keeps its order too. Both produce the same IDs for the same inputs, so stored v5 values stay valid.
uuid | uniku |
|---|---|
v5(name, namespace) | uuidv5(name, namespace) |
v5(name, namespace, buf, offset) | uuidv5(name, namespace, buf, offset) |
v5.DNS / v5.URL | uuidv5.DNS / uuidv5.URL |
uniku also exposes uuidv5.OID and uuidv5.X500, and uuidv5.namespace(ns) to parse a namespace once for many names. See UUID v5.
From nanoid
- import { nanoid } from 'nanoid'
+ import { nanoid } from 'uniku/nanoid'const id: string = nanoid()From ulid
- import { ulid } from 'ulid'
+ import { ulid } from 'uniku/ulid'const id: string = ulid()From typeid-js
typeid-js returns a TypeID object. uniku returns the canonical string directly.
- import { typeid } from 'typeid-js'
+ import { typeid } from 'uniku/typeid'
- const id = typeid('user').toString()
+ const id: string = typeid('user')From @paralleldrive/cuid2
- import { createId } from '@paralleldrive/cuid2'
+ import { cuidv2 } from 'uniku/cuid/v2'const id: string = cuidv2()From @owpz/ksuid
- import { KSUID } from '@owpz/ksuid'
+ import { ksuid } from 'uniku/ksuid'
- const id = KSUID.random().toString()
+ const id: string = ksuid()From bson
- import { ObjectId } from 'bson'
+ import { objectid } from 'uniku/objectid'
- const id = new ObjectId().toHexString()
+ const id: string = objectid()From tsid-ts
tsid-ts exposes a TSID object. uniku uses the native bigint as TSID's primary value.
- import { TSID } from 'tsid-ts'
+ import { tsid } from 'uniku/tsid'
- const id = TSID.create().toString()
+ const id: bigint = tsid()Convert at a string boundary when you need the canonical Base32 form:
const publicId: string = tsid.toString(id)From xid-ts or nexid
Both libraries implement the rs/xid representation. uniku returns the canonical string directly and does not require asynchronous setup.
- import { Xid } from 'xid-ts'
+ import { xid } from 'uniku/xid'
- const id = new Xid().toString()
+ const id: string = xid()Use xid.toBytes(id) and xid.fromBytes(bytes) when you store the 12-byte value.
Before replacing an existing generator, test the representation you store and expose. UUIDs, ULIDs, ObjectIDs, and XIDs have canonical byte forms; Nanoid and CUID v2 are string-native.