A UUID generator and validator
Switch branches/tags
Nothing to show
Latest commit 47e2357 Nov 15, 2010 @dandean dandean Unit tests
Failed to load latest commit information.
LICENSE initial commit Nov 15, 2010
README.md doc fix Nov 15, 2010
package.json reorganization Nov 15, 2010
tests.js Unit tests Nov 15, 2010
uuid-lib.js reorganization Nov 15, 2010


Uuid lets you generate and validate Universally Unique Identifiers.

In its simplest form, Uuid lets you generate raw UUID formatted strings:

// -> '6fdf6ffced7794fa407ea7b86ed9e59d'

But it has a more robust API which lets you work with UUID's as objects. Let's generate a new Uuid instance.

var uuid = Uuid.create();

We've now got an object which we can work with programmatically. Lets check the validity of our uuid using the built-in validator:

// -> true

// -> '6fdf6ffced7794fa407ea7b86ed9e59d'

A handy bit of functionality is that its toString method returns the string value, so you can do handy things like this:

var itemUrl = "http://whatever.com/items/" + uuid;
// -> 'http://whatever.com/items/6fdf6ffced7794fa407ea7b86ed9e59d'

If you need a placehold Uuid, or a value to represent a non-uuid, use the static EMPTY property:

// -> '00000000000000000000000000000000'

Once you have a Uuid object, you can't change its value (thanks ES5!):

uuid.value = "go suck it, uuid!"
// -> '6fdf6ffced7794fa407ea7b86ed9e59d'

To instantiate a Uuid object using an existing UUID string, use the constructor:

var uuid = new Uuid('6fdf6ffced7794fa407ea7b86ed9e59d');

You can check the equality of two different Uuid objects using the equals instance method.

Compare a Uuid object to a UUID string:

// -> true

Compare two Uuid objects:

uuid.equals(new Uuid('6fdf6ffced7794fa407ea7b86ed9e59d'));
// -> true


You can use npm to install uuid: npm install uuid-lib

But what if I need a GUID, not a UUID?

There's also a Guid library which has the exact same functionality, but for GUID's: https://github.com/dandean/guid