diff options
Diffstat (limited to 'node_modules/gulp-gzip/lib/utils.js')
-rwxr-xr-x | node_modules/gulp-gzip/lib/utils.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/node_modules/gulp-gzip/lib/utils.js b/node_modules/gulp-gzip/lib/utils.js new file mode 100755 index 000000000..5658e1ca1 --- /dev/null +++ b/node_modules/gulp-gzip/lib/utils.js @@ -0,0 +1,43 @@ +var bytes = require('bytes'); + +// Merge source object with target object while handling threshold option +// Used to merge user defined plugin options with default options +function merge(target, source) { + if (typeof source === 'undefined') source = {}; + + Object.keys(source).forEach(function(key) { + if (key === 'threshold') { + target[key] = threshold(source[key]); + } else { + target[key] = source[key]; + } + }); + + return target; +} + +// Parse the threshold plugin option +// Specifies the minimum file size that will be compressed +// Can be a string, number, or boolean +function threshold(obj) { + var ret; + + switch (typeof obj) { + case 'string': + ret = bytes(obj) < 150 ? 150 : bytes(obj); + break; + case 'number': + ret = obj < 150 ? 150 : obj; + break; + case 'boolean': + ret = obj === false ? false : 150; + break; + default: + throw new Error('threshold must be String|Number|Boolean'); + } + + return ret; +} + +exports.merge = merge; +exports.threshold = threshold; |