smart-guid
v0.2.1
Published
Small and smart GUID generator
Downloads
131
Readme
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
string
specifies the pattern in which all lowercasex
andy
will be replaced by generatedchar
. - All
-
will be treated as delimiters, and returned intacted. y
chars are a result ofx & 0x3 | 0x8
bitwise operation.
- pattern
SUID( pattern, base )
- base
int
in range: 2-36 specifies thestring.base
. - base = 2 will return binary format ( half byte )
- base
SUID( pattern, base, fullByte )
- fullByte
boolean
have effect only in binary modebase = 2
and returns full byte numbers ( 8 digits ).
- fullByte
Default
pattern : xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
base : 16
fullByte : 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-H
Tests
npm test
Release History
- 0.1.0 Initial release