0.2.1 • Published 11 years ago
smart-guid v0.2.1
smart-guid
Small and smart GUID / UUID generator.
Note that by design JavaScript can not generate full 128-bit GUIDs.
Installation
npm install smart-guid --save
Usage
Require:
var SUID = require('smart-guid');Args:
By default SUID() returns GUID in pattern xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx for e.g.: 87B793D7-EDE3-4B2C-9CBE-72A436E08E1B
SUID( pattern )- pattern
stringspecifies the pattern in which all lowercasexandywill be replaced by generatedchar. - All
-will be treated as delimiters, and returned intacted. ychars are a result ofx & 0x3 | 0x8bitwise operation.
- pattern
SUID( pattern, base )- base
intin range: 2-36 specifies thestring.base. - base = 2 will return binary format ( half byte )
- base
SUID( pattern, base, fullByte )- fullByte
booleanhave effect only in binary modebase = 2and returns full byte numbers ( 8 digits ).
- fullByte
Defaultpattern : xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxxbase : 16fullByte : false
Example:
var GUID = SUID(), // GUID = 87B793D7-EDE3-4B2C-9CBE-72A436E08E1B
UUID = SUID('xxx-5xx-Kyy'), // UUID = 369-57D-K98
bUID = SUID('x-x-y-b', 2); // BINARY = 0101-0100-1011-b
BUID = SUID('x-x-y-B', 2, true); // BINARY_FULLBYTE = 01100011-01110000-10000011-B
OUID = SUID('x-x-y-O', 8); // OCTAL = 2-7-11-O
HUID = SUID('x-x-y-H', 16); // HEX = 0-2-A-HTests
npm test
Release History
- 0.1.0 Initial release