mech-guid

0.2.2 • Public • Published

mech-guid

A library of mechanisms for Guid (Globally unique IDs) data types and the generation of Guids.

Jsperf execution speeds.

See Mechanism Home for more information and other libraries.

Supported Mechanisms

empty Mechanism

Represents an empty mechanism.

empty.go - Returns an empty guid ("00000000-0000-0000-0000-000000000000")
empty.goStr - Returns an empty guid ("00000000-0000-0000-0000-000000000000")
empty.isEmpty - always true

mguid.empty.go; // returns an empty guid
mguid.empty.goStr; // returns an empty guid
mguid.empty.isEmpty; // always returns true

guid Mechanism

A guid primitive.

Create a new guid:

var newGuid = mguid.guid(); // the guid is generated right here
 
newGuid.go; // returns the new guid
newGuid.goStr; // returns the new guid
newGuid.isEmpty; // returns false

Create a guid from a string primitive:

var newGuid = mguid.guid("60bce630-5a0c-41c1-abd3-f21df4d0290f");
 
newGuid.go; // returns the guid
newGuid.goStr; // returns the guid
newGuid.isEmpty; // returns false

Create an empty guid using the empty mechanism:

var newGuid = mguid.guid(mguid.empty);
 
newGuid.go; // returns an empty guid
newGuid.goStr; // returns an empty guid
newGuid.isEmpty; // returns true

Create a guid using make. This is the same as making a guid without passing any parameter

var newGuid = mguid.guid(mguid.make.go); // the guid is generated right here
 
newGuid.go; // returns the new guid
newGuid.goStr; // returns the new guid
newGuid.isEmpty; // returns false

In the above example, we pass make.go to guid() meaning newGuid will store the value generated by make.go. In the next example, we pass make to guid(). This means, every time we invoke newGuid, newGuid will invoke make causing a new Guid to be generated every time.

var newGuid = mguid.guid(mguid.make); // the guid is NOT generated right here
 
newGuid.go; // returns a new guid
newGuid.goStr; // returns a new guid
newGuid.isEmpty; // returns false

The m.hold mechanism can be used to retain the value of mguid.make.

var newGuid = mguid.guid(m.hold(mguid.make)); // the guid is NOT generated right here
 
newGuid.go; // the guid is generated here, on the first access
newGuid.goStr; // the guid is NOT generated here, on the second access
newGuid.isEmpty; // returns false

Create an invalid guid while validate is true returns an empty guid.

var newGuid = mguid.guid("INVALID", true);
 
newGuid.go; // returns an empty guid
newGuid.goStr; // returns an empty guid
newGuid.isEmpty; // returns true

Create an invalid guid while validate is false returns the invalid guid.

var newGuid = mguid.guid("SOME VALUE", false);
 
newGuid.go; // returns "SOME VALUE"
newGuid.goStr; // returns "SOME VALUE"
newGuid.isEmpty; // returns false
 
// BUT
 
mguid.isValid(newGuid).go; // returns false

isValid Mechanism

Validates a guid.

mguid.isValid("").go; // returns false
mguid.isValid("").goBool; // returns false
mguid.isValid("an invalid guid").goBool; // returns false
mguid.isValid(mguid.make).go; // returns true
mguid.isValid(mguid.make).goBool; // returns true

make Mechanism

Creates a new guid. This is not stored internally so you will need to do something with it.

mguid.make.go; // creates a new guid
mguid.make.goStr; // creates a new guid

Setup

Using In Your Projects

Change directory to your node project.

$ npm install --save mech-guid

Development

Get Involved!

There are a lot of core mechanisms just waiting to be created. Many of them can be created in a few hours including in-depth tests. Clone mech-library to get started!

Setup

Install:

$ npm install

Continuous test:

$ gulp

Test:

$ gulp webtests

Test Server

Read documentation in gulpfile.js to see how to setup automated web testing.

$ gulp webserver

Package Sidebar

Install

npm i mech-guid

Weekly Downloads

2

Version

0.2.2

License

MIT

Last publish

Collaborators

  • erichosick