diff --git a/lib/helper.js b/lib/helper.js index 2b3e08809..e277d1235 100644 --- a/lib/helper.js +++ b/lib/helper.js @@ -1,3 +1,8 @@ +var _ = require('lodash'); +var fs = require('fs'); +var path = require('path'); + + var OS = /(iPhone OS|Mac OS X|Windows|Linux)/; var OS_MAP = { "iPhone OS": "iOS", @@ -33,24 +38,12 @@ exports.browserFullNameToShort = function(fullName) { exports.isDefined = function(value) { - return typeof value !== 'undefined'; -}; - - -exports.isFunction = function(value) { - return typeof value === 'function'; -}; - - -exports.isString = function(value) { - return typeof value === 'string'; -}; - - -exports.isObject = function(value) { - return typeof value === 'object'; + return !_.isUndefined(value); }; +exports.isFunction = _.isFunction; +exports.isString = _.isString; +exports.isObject = _.isObject; var ABS_URL = /^https?:\/\//; exports.isUrlAbsolute = function(url) { @@ -89,12 +82,9 @@ exports.arrayRemove = function(collection, item) { exports.merge = function() { - return Array.prototype.slice.call(arguments, 0).reduce(function(result, object) { - Object.getOwnPropertyNames(object).forEach(function(name) { - result[name] = object[name]; - }); - return result; - }, {}); + var args = Array.prototype.slice.call(arguments, 0); + args.unshift({}); + return _.merge.apply({}, args); }; @@ -110,20 +100,11 @@ exports.formatTimeInterval = function(time) { return str; }; - -var identity = function(path) { - return path; -}; - var replaceWinPath = function(path) { return exports.isDefined(path) ? path.replace(/\\/g, '/') : path; }; -exports.normalizeWinPath = process.platform === 'win32' ? replaceWinPath : identity; - - -var fs = require('fs'); -var path = require('path'); +exports.normalizeWinPath = process.platform === 'win32' ? replaceWinPath : _.identity; exports.mkdirIfNotExists = function mkdir(directory, done) { // TODO(vojta): handle if it's a file @@ -137,3 +118,6 @@ exports.mkdirIfNotExists = function mkdir(directory, done) { } }); }; + +// export lodash +exports._ = _; \ No newline at end of file diff --git a/package.json b/package.json index 012806986..e875ee18c 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,8 @@ "LiveScript": ">= 1.0.1", "colors": "~0.6.0-1", "dateformat": ">= 1.0.2-1.2.3", - "istanbul": "0.1.11" + "istanbul": "0.1.11", + "lodash": "~0.9.1" }, "devDependencies": { "grunt-contrib-jshint": ">= 0.1.0", @@ -76,4 +77,4 @@ "node": ">= 0.8.4" }, "version": "0.5.3" -} \ No newline at end of file +}