Skip to content

Commit

Permalink
[improvement] Refactor helper.js using lodash (faster underscore).
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Nov 8, 2012
1 parent 381d8f3 commit f22a35c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 34 deletions.
48 changes: 16 additions & 32 deletions lib/helper.js
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
};


Expand All @@ -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
Expand All @@ -137,3 +118,6 @@ exports.mkdirIfNotExists = function mkdir(directory, done) {
}
});
};

// export lodash
exports._ = _;
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -76,4 +77,4 @@
"node": ">= 0.8.4"
},
"version": "0.5.3"
}
}

0 comments on commit f22a35c

Please sign in to comment.