dojox/uuid/_base (version 1.10)

See the dojox/uuid/_base reference documentation for more information.

Property Summary

Method Summary

  • assert(booleanValue,message) Throws an exception if the assertion fails.
  • generateNilUuid() This function returns the Nil UUID: "00000000-0000-0000-0000-000000000000".
  • generateRandomUuid() This function generates random UUIDs, meaning "version 4" UUIDs.
  • generateTimeBasedUuid(node) This function generates time-based UUIDs, meaning "version 1" UUIDs.
  • getNode(uuidString) If this is a version 1 UUID (a time-based UUID), getNode() returns a 12-character string with the "node" or "pseudonode" portion of the UUID, which is the rightmost 12 characters.
  • getTimestamp(uuidString,returnType) If this is a version 1 UUID (a time-based UUID), this method returns the timestamp value encoded in the UUID.
  • getVariant(uuidString) Returns a variant code that indicates what type of UUID this is.
  • getVersion(uuidString) Returns a version number that indicates what type of UUID this is.
  • isValid(uuidString) Returns true if the UUID was initialized with a valid value.
  • Uuid(input) This is the constructor for the Uuid class.

Properties

NIL_UUID
Defined by: dojox/uuid/_base
variant
Defined by: dojox/uuid/_base
version
Defined by: dojox/uuid/_base

Methods

assert(booleanValue,message)
Defined by dojox/uuid/_base

Throws an exception if the assertion fails.

If the asserted condition is true, this method does nothing. If the condition is false, we throw an error with a error message.

Parameter Type Description
booleanValue Boolean
message String
Optional
generateNilUuid()
Defined by dojox/uuid/_base

This function returns the Nil UUID: "00000000-0000-0000-0000-000000000000".

The Nil UUID is described in section 4.1.7 of RFC 4122: http://tools.ietf.org/html/rfc4122#section-4.1.7

Examples

Example 1

var string = dojox.uuid.generateNilUuid();

generateRandomUuid()

This function generates random UUIDs, meaning "version 4" UUIDs.

A typical generated value would be something like this: "3b12f1df-5232-4804-897e-917bf397618a"

For more information about random UUIDs, see sections 4.4 and 4.5 of RFC 4122: http://tools.ietf.org/html/rfc4122#section-4.4

This generator function is designed to be small and fast, but not necessarily good.

Small: This generator has a small footprint. Once comments are stripped, it's only about 25 lines of code, and it doesn't dojo.require() any other modules.

Fast: This generator can generate lots of new UUIDs fairly quickly (at least, more quickly than the other dojo UUID generators).

Not necessarily good: We use Math.random() as our source of randomness, which may or may not provide much randomness.

Examples

Example 1

var string = dojox.uuid.generateRandomUuid();

generateTimeBasedUuid(node)

This function generates time-based UUIDs, meaning "version 1" UUIDs.

Parameter Type Description
node String
Optional

A 12-character hex string representing either a pseudo-node or hardware-node (an IEEE 802.3 network node). A hardware-node will be something like "017bf397618a", always with the first bit being 0. A pseudo-node will be something like "f17bf397618a", always with the first bit being 1.

Examples

Example 1

string = dojox.uuid.generateTimeBasedUuid(); string = dojox.uuid.generateTimeBasedUuid("017bf397618a"); dojox.uuid.generateTimeBasedUuid.setNode("017bf397618a"); string = dojox.uuid.generateTimeBasedUuid(); // the generated UUID has node == "017bf397618a"

getNode(uuidString)
Defined by dojox/uuid/_base

If this is a version 1 UUID (a time-based UUID), getNode() returns a 12-character string with the "node" or "pseudonode" portion of the UUID, which is the rightmost 12 characters.

Parameter Type Description
uuidString String
getTimestamp(uuidString,returnType)
Defined by dojox/uuid/_base

If this is a version 1 UUID (a time-based UUID), this method returns the timestamp value encoded in the UUID. The caller can ask for the timestamp to be returned either as a JavaScript Date object or as a 15-character string of hex digits.

Parameter Type Description
uuidString String
returnType String
Optional

Any of these five values: "string", String, "hex", "date", Date

Returns:any

Returns the timestamp value as a JavaScript Date object or a 15-character string of hex digits.

Examples

Example 1

var uuidString = "b4308fb0-86cd-11da-a72b-0800200c9a66"; var date, string, hexString; date = dojox.uuid.getTimestamp(uuidString); // returns a JavaScript Date date = dojox.uuid.getTimestamp(uuidString, Date); // string = dojox.uuid.getTimestamp(uuidString, String); // "Mon, 16 Jan 2006 20:21:41 GMT" hexString = dojox.uuid.getTimestamp(uuidString, "hex"); // "1da86cdb4308fb0"

getVariant(uuidString)
Defined by dojox/uuid/_base

Returns a variant code that indicates what type of UUID this is. Returns one of the enumerated dojox.uuid.variant values.

Parameter Type Description
uuidString String

Examples

Example 1

var variant = dojox.uuid.getVariant("3b12f1df-5232-4804-897e-917bf397618a"); dojox.uuid.assert(variant == dojox.uuid.variant.DCE);

Example 2

"3b12f1df-5232-4804-897e-917bf397618a"
                ^
                |
    (variant "10__" == DCE)
getVersion(uuidString)
Defined by dojox/uuid/_base

Returns a version number that indicates what type of UUID this is. Returns one of the enumerated dojox.uuid.version values.

Parameter Type Description
uuidString String

Examples

Example 1

var version = dojox.uuid.getVersion("b4308fb0-86cd-11da-a72b-0800200c9a66"); dojox.uuid.assert(version == dojox.uuid.version.TIME_BASED);

isValid(uuidString)
Defined by dojox/uuid/_base

Returns true if the UUID was initialized with a valid value.

Parameter Type Description
uuidString String
Uuid(input)
Defined by dojox/uuid/Uuid

This is the constructor for the Uuid class. The Uuid class offers methods for inspecting existing UUIDs.

Parameter Type Description
input String
Optional

Examples

Example 1

var uuid; uuid = new dojox.uuid.Uuid("3b12f1df-5232-4804-897e-917bf397618a"); uuid = new dojox.uuid.Uuid(); // "00000000-0000-0000-0000-000000000000" uuid = new dojox.uuid.Uuid(dojox.uuid.generateRandomUuid()); uuid = new dojox.uuid.Uuid(dojox.uuid.generateTimeBasedUuid()); dojox.uuid.Uuid.setGenerator(dojox.uuid.generateRandomUuid); uuid = new dojox.uuid.Uuid(); dojox.uuid.assert(!uuid.isEqual(dojox.uuid.NIL_UUID));

Error in the documentation? Can’t find what you are looking for? Let us know!