-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (33 loc) · 1.06 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
"use strict";
var nconf = require('nconf');
var stripJsonComments = require('strip-json-comments');
var getCommentedJsonFormat = function(nconfInstance) {
var nconf = nconfInstance || nconf;
return {
parse: function(data) {
return JSON.parse(stripJsonComments(data));
},
stringify: nconf.formats.json.stringify
}
};
var addCommentedJsonFormat = function(nconfInstance) {
var format = getCommentedJsonFormat(nconfInstance);
if (nconfInstance) {
nconfInstance.formats.__json = nconfInstance.formats.json;
nconfInstance.formats.json = format;
return nconfInstance;
} else {
return format;
}
};
var restoreJsonFormat = function(nconfInstance) {
if (nconfInstance && nconfInstance.formats && nconfInstance.formats.__json) {
nconfInstance.formats.json = nconfInstance.formats.__json;
} else {
// Could not restore JSON format, ignore.
}
return nconfInstance;
};
addCommentedJsonFormat.format = getCommentedJsonFormat(nconf);
addCommentedJsonFormat.restore = restoreJsonFormat;
module.exports = addCommentedJsonFormat;