Skip to content

Commit e6293ad

Browse files
committed
Cleanup code
1 parent ba06147 commit e6293ad

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

index.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
var jsbeautify = require('js-beautify').js_beautify;
2-
var merge = require('deepmerge');
2+
var deepmerge = require('deepmerge');
33
var through = require('through2');
44
var PluginError = require('plugin-error');
55
var detectIndent = require('detect-indent');
66

7-
module.exports = function (editor, jsbeautifyOptions, mergeOptions) {
8-
7+
module.exports = function (editor, jsbeautifyOptions, deepmergeOptions) {
98

109
/*
11-
* extras merge options
12-
* this options is only pass to deepmerge
10+
* deepmerge options
1311
*/
14-
mergeOptions = mergeOptions || {};
12+
deepmergeOptions = deepmergeOptions || {};
1513

1614
/*
1715
* create 'editBy' function from 'editor'
@@ -23,7 +21,7 @@ module.exports = function (editor, jsbeautifyOptions, mergeOptions) {
2321
}
2422
else if (typeof editor === 'object') {
2523
// edit JSON object by merging with user specific object
26-
editBy = function(json) { return merge(json, editor, mergeOptions); };
24+
editBy = function(json) { return deepmerge(json, editor, deepmergeOptions); };
2725
}
2826
else if (typeof editor === 'undefined') {
2927
throw new PluginError('gulp-json-editor', 'missing "editor" option');
@@ -59,7 +57,7 @@ module.exports = function (editor, jsbeautifyOptions, mergeOptions) {
5957
var indent = detectIndent(file.contents.toString('utf8'));
6058

6159
// beautify options for this particular file
62-
var beautifyOptions = merge({}, jsbeautifyOptions); // make copy
60+
var beautifyOptions = deepmerge({}, jsbeautifyOptions); // make copy
6361
beautifyOptions.indent_size = beautifyOptions.indent_size || indent.amount || 2;
6462
beautifyOptions.indent_char = beautifyOptions.indent_char || (indent.type === 'tab' ? '\t' : ' ');
6563
beautifyOptions.beautify = !('beautify' in beautifyOptions && !beautifyOptions.beautify);

test/option.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,17 @@ it('should bypass beautification when property is set', function(done) {
113113
});
114114

115115

116-
it('should merged with arrayMerge of overwriteMerge', function (done) {
116+
it('should pass-through third argument to deepmerge and do an overwriteMerge', function(done) {
117117

118118
var stream = gulp.src('test/test.json').pipe(json({
119-
"authors": ["tomcat"]
119+
authors: ['tomcat'],
120120
},{},{
121-
arrayMerge: function (dist,source,options) {
121+
arrayMerge: function(dist,source,options) {
122122
return source;
123-
}
123+
},
124124
}));
125125

126-
stream.on('data', function (file) {
126+
stream.on('data', function(file) {
127127
var expected =
128128
'{\n' +
129129
' "name": "test object",\n' +

0 commit comments

Comments
 (0)