yiwn-uid
v0.0.1
Published
Generate semi-random unique something with give prefix.
Readme
uid
Simple prefixed unique ID generator.
Installation
Using component
$ component install yiwn/uidUsing npm for browserify
$ npm install yiwn-uidUsage
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 testOrigins
Mostly from this blog post.
License
The MIT License
