-
Notifications
You must be signed in to change notification settings - Fork 61
/
index.js
42 lines (33 loc) · 1.38 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
var Handlebars = require('handlebars');
var fecha = require('fecha');
var numbro = require('numbro');
var mockdata = require('./lib/mockdata');
var helpers = require('./lib/helpers');
var utils = require('./lib/utils');
var dummyjson = {
// Global seed for the random number generator
seed: null,
parse: function(string, options) {
options = options || {};
// Merge custom mockdata/helpers into the defaults, items with the same name will override
options.mockdata = Handlebars.Utils.extend({}, mockdata, options.mockdata);
options.helpers = Handlebars.Utils.extend({}, helpers, options.helpers);
// If a seed is passed in the options it will override the default one
utils.setRandomSeed(options.seed || dummyjson.seed);
// Certain helpers, such as name and email, attempt to synchronise and use the same values when
// called after one-another. This object acts as a cache so the helpers can share their values.
options.mockdata.__cache = {};
return Handlebars.compile(string)(options.mockdata, {
helpers: options.helpers,
partials: options.partials
});
},
// Expose the built-in modules so people can use them in their own helpers
mockdata: mockdata,
helpers: helpers,
utils: utils,
// Also expose the number and date formatters so people can modify their settings
fecha: fecha,
numbro: numbro
};
module.exports = dummyjson;