Add docs
This commit is contained in:
parent
14bb0026e0
commit
9e447b2a11
|
@ -55,6 +55,9 @@ var i;
|
||||||
for (i = 0; i < 100; i += 1) {
|
for (i = 0; i < 100; i += 1) {
|
||||||
console.log(hri.random());
|
console.log(hri.random());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Use custom pattern of number-noun-adjective
|
||||||
|
console.log(hri.get('#na'));
|
||||||
```
|
```
|
||||||
|
|
||||||
### bower / browser
|
### bower / browser
|
||||||
|
|
23
index.js
23
index.js
|
@ -46,20 +46,27 @@
|
||||||
// Accepts a format as a stirng of 'a' for adjective, 'n' for noun, and '#' for number
|
// Accepts a format as a stirng of 'a' for adjective, 'n' for noun, and '#' for number
|
||||||
function get(format) {
|
function get(format) {
|
||||||
populate();
|
populate();
|
||||||
hri = new Array();
|
let hri = [];
|
||||||
for (var i = 0; i < format.length; i++) {
|
for (let item of format) {
|
||||||
switch (format[i]) {
|
switch (item) {
|
||||||
case 'a': hri.push(adjectives.pop()); break;
|
case 'a':
|
||||||
case 'n': hri.push(animals.pop()); break;
|
hri.push(adjectives.pop());
|
||||||
case '#': hri.push(adjectives.pop()); break;
|
break;
|
||||||
|
case 'n':
|
||||||
|
hri.push(animals.pop());
|
||||||
|
break;
|
||||||
|
case '#':
|
||||||
|
hri.push(numbers.pop());
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
throw 'Unexpected value ' + format[i] + '. Expected a,n,#';
|
throw 'Unexpected value ' + item + '. Expected a,n,#';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return hri.join('-');
|
return hri.join('-');
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.humanReadableIds = { random: random };
|
exports.humanReadableIds = {random: random, get: get};
|
||||||
exports.hri = exports.humanReadableIds;
|
exports.hri = exports.humanReadableIds;
|
||||||
|
|
||||||
}('undefined' !== typeof exports && exports || new Function('return this')()));
|
}('undefined' !== typeof exports && exports || new Function('return this')()));
|
||||||
|
|
|
@ -9,4 +9,8 @@
|
||||||
for (i = 0; i < 100; i += 1) {
|
for (i = 0; i < 100; i += 1) {
|
||||||
console.log(hri.random());
|
console.log(hri.random());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < 10; i += 1) {
|
||||||
|
console.log(hri.get('#na'));
|
||||||
|
}
|
||||||
}('undefined' !== typeof exports && exports || new Function('return this')()));
|
}('undefined' !== typeof exports && exports || new Function('return this')()));
|
||||||
|
|
Loading…
Reference in New Issue