GUID :
A GUID (Global Unique Identifier) is Microsoft’s implementation of a unique identifier (UUID).
- In its simplest form, Guid lets we generate raw GUID formatted strings:
- Let’s generate a new Guid instance.
- We’ve now got an object which we can work with programmatic manner. Lets check the validity of our Guid using the built-in validator :
- A handy bit of functionality is that its toString method returns the string value.
- If we need a placeholder Guid, or a value to represent a non-GUID, use the static EMPTY property:
- Once we have a Guid object, we can’t change its value:
- To instantiate an Guid object using an existing GUID string, use the constructor:
- we can check the equality of two different Guid objects using the equals instance method.
- Compare a Guid object to a GUID string:
- Compare two Guid objects:
CommonJS Module:
[ad type=”banner”]
UUID:
- “Universally Unique Identifier (UUID) is an identifier standard used in software construction, standardized by the Open Software Foundation (OSF) as part of the Distributed Computing Environment (DCE).”
- A UUID is a 16-octet (128-bit) number.
- A UUID is represented by 32 lowercase hexadecimal digits and it displayed in 5 groups separated by hyphens(-).
- This represent in form of 8-4-4-4-12 for a total of 36 characters (32 alphanumeric characters and four hyphens).
- Simple, fast generation of RFC4122 UUIDS.
CommonJS Module:
npm install uuid
- To Generate and return a RFC4122 v1 (timestamp-based) UUID.
- options – (Object) Optional uuid state to apply.
Properties may include the following:
- node – (Array) Node id as Array of 6 bytes . Default: Randomly generated ID.
- 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.
- buffer – (Array | Buffer) Array or buffer where UUID bytes are to be written.
- offset – (Number) Starting index in buffer at which to begin writing.
Example1: Generate string UUID with fully-specified options
Example2: In-place generation of two binary IDs
- To Generate and return a RFC4122 v4 UUID.
- options – (Object) Optional uuid state to apply.
Properties:
- random – (Number[16]) Array of 16 numbers (0-255) to use in place of randomly generated values
- rng –
- (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.
Example1: Generate string UUID with fully-specified options
Example2: Generate two IDs in a single buffer
How to Create a GUID / UUID in Javascript
1.To create an rfc4122 version 4 compliant guid