README
UUCID
Universally Unique Chronologically-Sortable Identifier compatible with UUID v4.
Install
$ npm install uucid
Spec
UUCID.js is licensed under MIT, but the UUCID Spec is licensed under OWFa-1.0.
Development of UUCID libraries in other programming languages is encouraged.
Usage
uucid
▸ uucid(input?: number
| string
| Date
): string
Generate a new UUCID-formatted UUIDv4 ID.
import { uucid } from 'uucid'
uucid() // Defaults to Date.now()
uucid(new Date('12/12/2012')) // Accepts an instance of `Date`.
uucid('12/12/2012') // Also accepts anything that `new Date()` accepts.
uucid(1355288400000) // Including millisecond timestamps.
// The return value of the above function calls will look something like:
// 10155077-7700-4688-b1cf-cca495323496
Parameters:
Name | Type | Default value | Description |
---|---|---|---|
input | number | string | Date |
Date.now() |
Timestamp in milliseconds, date string or a Date instance. |
Returns: string
UUID string.
extractTimestampFromUUCID
▸ extractTimestampFromUUCID(id: string
): number
Extract the timestamp from a given UUCID.
import { extractTimestampFromUUCID } from 'uucid'
extractTimestampFromUUCID('10135533-2332-4012-aada-b36571a05399')
// Returns 1355332332012
Parameters:
Name | Type | Description |
---|---|---|
id | string |
UUCID to extract the timestamp from. |
Returns: number
Extracted timestamp in milliseconds.