Simple, fast generation of RFC4122 UUIDS.
Features:
npm install uuid// Generate a v1 UUID (time-based) const uuidV1 = ;; // -> '6c84fb90-12c4-11e1-840d-7b25c5ee775a' // Generate a v4 UUID (random) const uuidV4 = ;; // -> '110ec58a-a0f2-4ac4-8393-c866d813b8d1' Browser-ready versions of this module are available via wzrd.in.
(Note: Do not do this in production. Just don't. wzrd.in is a great service, but if you're deploying a "real" service you should be using a packaging tool like browserify or webpack. If you do go this route you would be well advised to link to a specific version instead of uuid@latest to avoid having your code break when we roll out breaking changes.)
Generate a V4 uuid. See uuid.v4 documentation below.
options [, buffer [, offset]]])Generate and return a RFC4122 v1 (timestamp-based) UUID.
options - (Object) Optional uuid state to apply. Properties may include:
node - (Array) Node id as Array of 6 bytes (per 4.1.6). Default: Randomly generated ID. See note 1.clockseq - (Number between 0 - 0x3fff) RFC clock sequence. Default: An internally maintained clockseq is used.msecs - (Number | Date) Time in milliseconds since unix Epoch. Default: The current time is used.nsecs - (Number between 0-9999) additional time, in 100-nanosecond units. Ignored if msecs is unspecified. Default: internal uuid counter is used, as per 4.2.1.2.buffer - (Array | Buffer) Array or buffer where UUID bytes are to be written.
offset - (Number) Starting index in buffer at which to begin writing.
Returns buffer, if specified, otherwise the string form of the UUID
Notes:
Example: Generate string UUID with fully-specified options
uuid; // -> "710b962e-041c-11e1-9234-0123456789ab" Example: In-place generation of two binary IDs
// Generate two ids in an array const arr = 32; // -> [] uuid; // -> [02 a2 ce 90 14 32 11 e1 85 58 0b 48 8e 4f c1 15] uuid; // -> [02 a2 ce 90 14 32 11 e1 85 58 0b 48 8e 4f c1 15 02 a3 1c b0 14 32 11 e1 85 58 0b 48 8e 4f c1 15] options [, buffer [, offset]]])Generate and return a RFC4122 v4 UUID.
options - (Object) Optional uuid state to apply. Properties may include:
random - (Number[16]) Array of 16 numbers (0-255) to use in place of randomly generated valuesrng - (Function) Random # generator to use. Set to one of the built-in generators - uuid.mathRNG (all platforms), uuid.nodeRNG (node.js only), uuid.whatwgRNG (WebKit only) - or a custom function that returns an array[16] of byte values.buffer - (Array | Buffer) Array or buffer where UUID bytes are to be written.
offset - (Number) Starting index in buffer at which to begin writing.
Returns buffer, if specified, otherwise the string form of the UUID
Example: Generate string UUID with fully-specified options
uuid;// -> "109156be-c4fb-41ea-b1b4-efe1671c5836" Example: Generate two IDs in a single buffer
const buffer = 32; // (or 'new Buffer' in node.js) uuid;uuid;npm testThe code for the legacy node-uuid package is available in the node-uuid branch.