yiwn-uid
v0.0.1
Published
Generate semi-random unique something with give prefix.
Downloads
1
Readme
uid
Simple prefixed unique ID generator.
Installation
Using component
$ component install yiwn/uid
Using npm for browserify
$ npm install yiwn-uid
Usage
Example:
var uid = require('yiwn-uid');
uid('user-'); // ~> 'user-a14e';
By default, it generates a 4 char-wide random combination of hexadecimal symbols, backed by Math.random()
.
uid(); // ~> 'a14e'
Supply a string as first argument to prefix generated uid with it.
If supplied a number as second argument for uid's random part to have that exact length. If prefix
argument is omitted, it'll take the first numeric argument as length.
uid('ns-'); // ~> 'ns-a14e'
uid('ns-', 6); // -> like 'ns-a14e22'
uid(6); // -> like 'a14e22'
Test
Run tests with mocha
$ make test
Origins
Mostly from this blog post.
License
The MIT License