-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
57 lines (41 loc) · 959 Bytes
/
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
47
48
49
50
51
52
53
54
55
56
57
'use strict';
const compile = require('./lib/compile');
/**
* Factory for creating an instance
* @param {Array} plugins List of helpers to "use"
* @return {Object} An instance of jazzon
*/
function create(plugins) {
plugins = Array.isArray(plugins) ? plugins : [];
const jazzon = {
/**
* Allow access to a shallow copy of the plugins
*/
get plugins() {
return plugins.slice(0);
},
/**
* But don't allow modifying it
*/
set plugins(value) {
throw (new Error('Plugins is immutable'));
}
};
/**
* Expose the factory function for modularity
*/
jazzon.create = create;
/**
* Set up a simple "use interface"
*/
jazzon.use = (fn) => {
plugins.push(fn);
return jazzon;
};
/**
* Proxy the compile function with the current set of plugins
*/
jazzon.compile = (json) => compile(json, plugins);
return jazzon;
}
module.exports = create();