-
Notifications
You must be signed in to change notification settings - Fork 5
/
generators.js
31 lines (29 loc) · 942 Bytes
/
generators.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
/**
* @see https://github.com/json-schema-faker/grunt-jsonschema-faker#external
*
* This file contains generator functions that are used as intermediate
* preprocessors for external data collections loaded into JSON Schema.
* When a collection, having *n* items, is loaded as external data source, there
* is a question: which item to choose for particular JSON generated object?
* The functions below give the opportunity to make it one by one (a cycle),
* just a random value or anything else.
*/
var _ = require('lodash');
module.exports = {
random: function(collection){
return function(){
return _.sample(collection);
};
},
cycle: function(collection){
var ind = 0;
return function(){
var res = collection[ind];
ind++;
if (ind === collection.length){
ind = 0;
}
return res;
};
}
};