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 - An empty guid mechanism
- guid - Primitive 'guid' mechanism
- isValid - A guid validator mechanism
- make - Generates a random guid (algorithm stolen from e7 of How To Create a Guid)
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
mguidemptygo; // returns an empty guidmguidemptygoStr; // returns an empty guidmguidemptyisEmpty; // always returns true
guid Mechanism
A guid primitive.
Create a new guid:
var newGuid = mguid; // the guid is generated right here newGuidgo; // returns the new guidnewGuidgoStr; // returns the new guidnewGuidisEmpty; // returns false
Create a guid from a string primitive:
var newGuid = mguid; newGuidgo; // returns the guidnewGuidgoStr; // returns the guidnewGuidisEmpty; // returns false
Create an empty guid using the empty mechanism:
var newGuid = mguid; newGuidgo; // returns an empty guidnewGuidgoStr; // returns an empty guidnewGuidisEmpty; // returns true
Create a guid using make. This is the same as making a guid without passing any parameter
var newGuid = mguid; // the guid is generated right here newGuidgo; // returns the new guidnewGuidgoStr; // returns the new guidnewGuidisEmpty; // 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; // the guid is NOT generated right here newGuidgo; // returns a new guidnewGuidgoStr; // returns a new guidnewGuidisEmpty; // returns false
The m.hold mechanism can be used to retain the value of mguid.make.
var newGuid = mguid; // the guid is NOT generated right here newGuidgo; // the guid is generated here, on the first accessnewGuidgoStr; // the guid is NOT generated here, on the second accessnewGuidisEmpty; // returns false
Create an invalid guid while validate is true returns an empty guid.
var newGuid = mguid; newGuidgo; // returns an empty guidnewGuidgoStr; // returns an empty guidnewGuidisEmpty; // returns true
Create an invalid guid while validate is false returns the invalid guid.
var newGuid = mguid; newGuidgo; // returns "SOME VALUE"newGuidgoStr; // returns "SOME VALUE"newGuidisEmpty; // returns false // BUT mguidgo; // returns false
isValid Mechanism
Validates a guid.
mguidgo; // returns falsemguidgoBool; // returns falsemguidgoBool; // returns falsemguidgo; // returns truemguidgoBool; // returns true
make Mechanism
Creates a new guid. This is not stored internally so you will need to do something with it.
mguidmakego; // creates a new guidmguidmakegoStr; // 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