0.3.5 • Published 3 months ago

uuid-v9 v0.3.5

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

UUID v9

Fast, lightweight, zero-dependency JavaScript/TypeScript implementation of the UUID version 9 proposal.

The v9 UUID supports both time-based sequential and random non-sequential UUIDs with an optional prefix, an optional checksum, and sufficient randomness to avoid collisions. It uses the UNIX timestamp for sequential UUIDs and CRC-8 for checksums. A version digit can be added if desired, but is omitted by default.

Installation

Install UUID v9 from npm

With npm:

npm install --save uuid-v9

or using yarn:

yarn add uuid-v9

Usage

import uuidv9, { validateUUIDv9 } from 'uuid-v9' 

const orderedId = uuidv9()
const prefixedOrderedId = uuidv9('a1b2c3d4') // up to 8 hexadecimal characters
const unorderedId = uuidv9('', false)
const prefixedUnorderedId = uuidv9('a1b2c3d4', false)
const orderedIdWithChecksum = uuidv9('', true, true)
const orderedIdWithVersion = uuidv9('', true, false, true)
const orderedIdWithCompatibility = uuidv9('', true, false, false, true)

const isValid = validateUUIDv9(orderedId) // built-in UUID validator
const isValidWithChecksum = validateUUIDv9(orderedIdWithChecksum, true)
const isValidWithVersion = validateUUIDv9(orderedIdWithVersion, true, true)
const isValidWithCompatibility = validateUUIDv9(orderedIdWithCompatibility, true, '1')

Compatibility

Some UUID validators check for specific features of v1 or v4 UUIDs. This causes some valid v9 UUIDs to appear invalid. Three possible workarounds are:

1) Use the built-in validator (recommended) 2) Use compatibility mode* 3) Bypass the validator (not recommended)

*Compatibility mode adds version and variant digits to immitate v1 or v4 UUIDs based on whether or not you have a timestamp.

Format

Here is the UUID v9 format: xxxxxxxx-xxxx-9xxx-8xxx-xxxxxxxxxxyy

x = prefix/timestamp/random, y = checksum (optional), 9 = version (optional), 8 = variant (compatibility mode)

License

This project is licensed under the MIT License.

0.3.5

3 months ago

0.3.2

3 months ago

0.3.4

3 months ago

0.3.3

3 months ago

0.3.1

3 months ago

0.3.0

3 months ago

0.2.0

3 months ago

0.1.2

3 months ago

0.1.1

3 months ago

0.1.0

4 months ago

0.0.8

4 months ago

0.0.5

4 months ago

0.0.7

4 months ago

0.0.6

4 months ago

0.0.4

4 months ago

0.0.3

4 months ago

0.0.2

4 months ago

0.0.1

4 months ago