function generate() { return build(clusterWorkerId); }
n/a
function characters(newCharacters) { if (newCharacters !== undefined) { alphabet.characters(newCharacters); } return alphabet.shuffled(); }
...
The default characters provided were selected because they are url safe.
__Example__
```js
// use $ and @ instead of - and _
shortid.characters('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
$@');
```
```js
// any 64 unicode characters work, but I wouldn't recommend this.
shortid.characters('ⒶⒷⒸⒹⒺⒻⒼⒽⒾⒿⓀⓁⓂⓃⓄⓅⓆⓇⓈⓉⓊⓋⓌⓍⓎⓏⓐⓑⓒⓓⓔⓕⓖⓗⓘⓙⓚⓛⓜⓝⓞⓟⓠⓡⓢⓣⓤⓥⓦⓧⓨⓩ①②③④⑤⑥⑦⑧⑨⑩⑪⑫');
```
...
function decode(id) { var characters = alphabet.shuffled(); return { version: characters.indexOf(id.substr(0, 1)) & 0x0f, worker: characters.indexOf(id.substr(1, 1)) & 0x0f }; }
n/a
function generate() { return build(clusterWorkerId); }
...
### Usage
```js
var shortid = require('shortid');
console.log(shortid.generate());
//PPBqWA9
```
Mongoose Unique Id
```js
_id: {
type: String,
...
function isShortId(id) { if (!id || typeof id !== 'string' || id.length < 6 ) { return false; } var characters = alphabet.characters(); var len = id.length; for(var i = 0; i < len;i++) { if (characters.indexOf(id[i]) === -1) { return false; } } return true; }
...
__Returns__ `boolean`
Check to see if an id is a valid `shortid`. Note: This only means the id _could_ have been generated by `shortid`, it doesn'
;t guarantee it.
__Example__
```js
shortid.isValid('41XTDbE');
// true
```
```js
shortid.isValid('i have spaces');
// false
```
...
function seed(seedValue) { alphabet.seed(seedValue); return module.exports; }
...
```js
shortid.worker(1);
```
---------------------------------------
#### `shortid.seed(integer)`
__Default:__ `1`
__Recommendation:__ You typically won't want to change this.
__Optional__
...
function worker(workerId) { clusterWorkerId = workerId; return module.exports; }
...
```js
shortid.isValid('i have spaces');
// false
```
---------------------------------------
#### `shortid.worker(integer)`
__Default:__ `process.env.NODE_UNIQUE_ID || 0`
__Recommendation:__ You typically won't want to change this.
__Optional__
...
function characters(_alphabet_) { setCharacters(_alphabet_); return alphabet; }
...
The default characters provided were selected because they are url safe.
__Example__
```js
// use $ and @ instead of - and _
shortid.characters('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
$@');
```
```js
// any 64 unicode characters work, but I wouldn't recommend this.
shortid.characters('ⒶⒷⒸⒹⒺⒻⒼⒽⒾⒿⓀⓁⓂⓃⓄⓅⓆⓇⓈⓉⓊⓋⓌⓍⓎⓏⓐⓑⓒⓓⓔⓕⓖⓗⓘⓙⓚⓛⓜⓝⓞⓟⓠⓡⓢⓣⓤⓥⓦⓧⓨⓩ①②③④⑤⑥⑦⑧⑨⑩⑪⑫');
```
...
function lookup(index) { var alphabetShuffled = getShuffled(); return alphabetShuffled[index]; }
n/a
function setSeed(seed) { randomFromSeed.seed(seed); if (previousSeed !== seed) { reset(); previousSeed = seed; } }
...
```js
shortid.worker(1);
```
---------------------------------------
#### `shortid.seed(integer)`
__Default:__ `1`
__Recommendation:__ You typically won't want to change this.
__Optional__
...
function getShuffled() { if (shuffled) { return shuffled; } shuffled = shuffle(); return shuffled; }
...
/**
* Decode the id to get the version and worker
* Mainly for debugging and testing.
* @param id - the shortid-generated id.
*/
function decode(id) {
var characters = alphabet.shuffled();
return {
version: characters.indexOf(id.substr(0, 1)) & 0x0f,
worker: characters.indexOf(id.substr(1, 1)) & 0x0f
};
}
module.exports = decode;
...
function generate() { return build(clusterWorkerId); }
...
### Usage
```js
var shortid = require('shortid');
console.log(shortid.generate());
//PPBqWA9
```
Mongoose Unique Id
```js
_id: {
type: String,
...
function characters(newCharacters) { if (newCharacters !== undefined) { alphabet.characters(newCharacters); } return alphabet.shuffled(); }
...
The default characters provided were selected because they are url safe.
__Example__
```js
// use $ and @ instead of - and _
shortid.characters('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
$@');
```
```js
// any 64 unicode characters work, but I wouldn't recommend this.
shortid.characters('ⒶⒷⒸⒹⒺⒻⒼⒽⒾⒿⓀⓁⓂⓃⓄⓅⓆⓇⓈⓉⓊⓋⓌⓍⓎⓏⓐⓑⓒⓓⓔⓕⓖⓗⓘⓙⓚⓛⓜⓝⓞⓟⓠⓡⓢⓣⓤⓥⓦⓧⓨⓩ①②③④⑤⑥⑦⑧⑨⑩⑪⑫');
```
...
function decode(id) { var characters = alphabet.shuffled(); return { version: characters.indexOf(id.substr(0, 1)) & 0x0f, worker: characters.indexOf(id.substr(1, 1)) & 0x0f }; }
n/a
function isShortId(id) { if (!id || typeof id !== 'string' || id.length < 6 ) { return false; } var characters = alphabet.characters(); var len = id.length; for(var i = 0; i < len;i++) { if (characters.indexOf(id[i]) === -1) { return false; } } return true; }
...
__Returns__ `boolean`
Check to see if an id is a valid `shortid`. Note: This only means the id _could_ have been generated by `shortid`, it doesn'
;t guarantee it.
__Example__
```js
shortid.isValid('41XTDbE');
// true
```
```js
shortid.isValid('i have spaces');
// false
```
...
function seed(seedValue) { alphabet.seed(seedValue); return module.exports; }
...
```js
shortid.worker(1);
```
---------------------------------------
#### `shortid.seed(integer)`
__Default:__ `1`
__Recommendation:__ You typically won't want to change this.
__Optional__
...
function worker(workerId) { clusterWorkerId = workerId; return module.exports; }
...
```js
shortid.isValid('i have spaces');
// false
```
---------------------------------------
#### `shortid.worker(integer)`
__Default:__ `process.env.NODE_UNIQUE_ID || 0`
__Recommendation:__ You typically won't want to change this.
__Optional__
...
function getNextValue() { seed = (seed * 9301 + 49297) % 233280; return seed/(233280.0); }
...
function shuffle() {
if (!alphabet) {
setCharacters(ORIGINAL);
}
var sourceArray = alphabet.split('');
var targetArray = [];
var r = randomFromSeed.nextValue();
var characterIndex;
while (sourceArray.length > 0) {
r = randomFromSeed.nextValue();
characterIndex = Math.floor(r * sourceArray.length);
targetArray.push(sourceArray.splice(characterIndex, 1)[0]);
}
...
function setSeed(_seed_) { seed = _seed_; }
...
```js
shortid.worker(1);
```
---------------------------------------
#### `shortid.seed(integer)`
__Default:__ `1`
__Recommendation:__ You typically won't want to change this.
__Optional__
...