From ef9041790f301750715e7b58bf2632b3b801f944 Mon Sep 17 00:00:00 2001 From: Steve Lacy Date: Fri, 27 Feb 2015 09:09:20 -0800 Subject: [PATCH] move to named functions for error handling --- index.js | 56 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/index.js b/index.js index 2c2768c..e58418a 100644 --- a/index.js +++ b/index.js @@ -6,34 +6,6 @@ var through = require('through2'); var semver = require('semver'); var Dot = require('dot-object'); -var setDefaultOptions = function(opts) { - opts = opts || {}; - opts.key = opts.key || 'version'; - opts.indent = opts.indent || void 0; - // default type bump is patch - if (!opts.type || !semver.inc('0.0.1', opts.type)) { - opts.type = 'patch'; - } - // if passed specific version - validate it - if (opts.version && !semver.valid(opts.version, opts.type)) { - gutil.log('invalid version used as option', gutil.colors.red(opts.version)); - opts.version = null; - } - return opts; -}; - -// Preserver new line at the end of a file -var possibleNewline = function (json) { - var lastChar = (json.slice(-1) === '\n') ? '\n' : ''; - return lastChar; -}; - -// Figured out which "space" params to be used for JSON.stringfiy. -var space = function space(json) { - var match = json.match(/^(?:(\t+)|( +))"/m); - return match ? (match[1] ? '\t' : match[2].length) : ''; -}; - module.exports = function(opts) { // set task options opts = setDefaultOptions(opts); @@ -84,3 +56,31 @@ module.exports = function(opts) { cb(null, file); }); }; + +function setDefaultOptions(opts) { + opts = opts || {}; + opts.key = opts.key || 'version'; + opts.indent = opts.indent || void 0; + // default type bump is patch + if (!opts.type || !semver.inc('0.0.1', opts.type)) { + opts.type = 'patch'; + } + // if passed specific version - validate it + if (opts.version && !semver.valid(opts.version, opts.type)) { + gutil.log('invalid version used as option', gutil.colors.red(opts.version)); + opts.version = null; + } + return opts; +} + +// Preserver new line at the end of a file +function possibleNewline(json) { + var lastChar = (json.slice(-1) === '\n') ? '\n' : ''; + return lastChar; +} + +// Figured out which "space" params to be used for JSON.stringfiy. +function space(json) { + var match = json.match(/^(?:(\t+)|( +))"/m); + return match ? (match[1] ? '\t' : match[2].length) : ''; +}