From e6293ad6223d077f6691d5afa11f8a61f126a8aa Mon Sep 17 00:00:00 2001 From: Veeck Date: Wed, 26 Dec 2018 10:44:49 +0100 Subject: [PATCH] Cleanup code --- index.js | 14 ++++++-------- test/option.js | 10 +++++----- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index 3e6d7bb..2eb3eac 100644 --- a/index.js +++ b/index.js @@ -1,17 +1,15 @@ var jsbeautify = require('js-beautify').js_beautify; -var merge = require('deepmerge'); +var deepmerge = require('deepmerge'); var through = require('through2'); var PluginError = require('plugin-error'); var detectIndent = require('detect-indent'); -module.exports = function (editor, jsbeautifyOptions, mergeOptions) { - +module.exports = function (editor, jsbeautifyOptions, deepmergeOptions) { /* - * extras merge options - * this options is only pass to deepmerge + * deepmerge options */ - mergeOptions = mergeOptions || {}; + deepmergeOptions = deepmergeOptions || {}; /* * create 'editBy' function from 'editor' @@ -23,7 +21,7 @@ module.exports = function (editor, jsbeautifyOptions, mergeOptions) { } else if (typeof editor === 'object') { // edit JSON object by merging with user specific object - editBy = function(json) { return merge(json, editor, mergeOptions); }; + editBy = function(json) { return deepmerge(json, editor, deepmergeOptions); }; } else if (typeof editor === 'undefined') { throw new PluginError('gulp-json-editor', 'missing "editor" option'); @@ -59,7 +57,7 @@ module.exports = function (editor, jsbeautifyOptions, mergeOptions) { var indent = detectIndent(file.contents.toString('utf8')); // beautify options for this particular file - var beautifyOptions = merge({}, jsbeautifyOptions); // make copy + var beautifyOptions = deepmerge({}, jsbeautifyOptions); // make copy beautifyOptions.indent_size = beautifyOptions.indent_size || indent.amount || 2; beautifyOptions.indent_char = beautifyOptions.indent_char || (indent.type === 'tab' ? '\t' : ' '); beautifyOptions.beautify = !('beautify' in beautifyOptions && !beautifyOptions.beautify); diff --git a/test/option.js b/test/option.js index c0c910d..7d89631 100644 --- a/test/option.js +++ b/test/option.js @@ -113,17 +113,17 @@ it('should bypass beautification when property is set', function(done) { }); -it('should merged with arrayMerge of overwriteMerge', function (done) { +it('should pass-through third argument to deepmerge and do an overwriteMerge', function(done) { var stream = gulp.src('test/test.json').pipe(json({ - "authors": ["tomcat"] + authors: ['tomcat'], },{},{ - arrayMerge: function (dist,source,options) { + arrayMerge: function(dist,source,options) { return source; - } + }, })); - stream.on('data', function (file) { + stream.on('data', function(file) { var expected = '{\n' + ' "name": "test object",\n' +