forked from unleashlive/human-readable-ids
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (38 loc) · 1 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*jshint -W054 */
;(function (exports) {
'use strict';
var lists = exports.humanReadableIds || require('./lists')
, shuffle = exports.knuthShuffle || require('knuth-shuffle').knuthShuffle
, animals = []
, adjectives = []
, numbers = []
;
function genNumbers() {
var i = 2
;
numbers = [];
numbers.push(0);
// 1 is not plural, so we skip it
for (i = 2; i <= 100; i += 1) {
numbers.push(i);
}
return shuffle(numbers);
}
function random() {
if (!adjectives.length) {
adjectives = shuffle(lists.adjectives.slice(0));
}
if (!animals.length) {
animals = shuffle(lists.animals.slice(0));
}
if (!numbers.length) {
numbers = shuffle(genNumbers());
}
return adjectives.pop()
+ '-' + animals.pop()
+ '-' + numbers.pop()
;
}
exports.humanReadableIds = { random: random };
exports.hri = exports.humanReadableIds;
}('undefined' !== typeof exports && exports || new Function('return this')()));