Skip to content

Commit

Permalink
just use lodash whenever possible
Browse files Browse the repository at this point in the history
  • Loading branch information
stevemao committed Apr 3, 2015
1 parent 084d24a commit a7ed3df
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
15 changes: 7 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
'use strict';
var dotProp = require('dot-prop');
var each = require('lodash.foreach');
var cloneDeep = require('lodash.clonedeep');
var _ = require('lodash');

function compareFunc(prop) {
return function(a, b) {
var retNumber = 0;

each((Array.isArray(prop) ? prop : [prop]), function(el) {
_.each((_.isArray(prop) ? prop : [prop]), function(el) {
var newA;
var newB;

if (typeof el === 'function') {
if (_.isFunction(el)) {
newA = prop(a);
newB = prop(b);
} else if (typeof el === 'string') {
} else if (_.isString(el)) {
newA = dotProp(a, el);
newB = dotProp(b, el);
} else {
newA = cloneDeep(a);
newB = cloneDeep(b);
newA = _.cloneDeep(a);
newB = _.cloneDeep(b);
}

if (typeof newA === 'string' && typeof newB === 'string') {
if (_.isString(newA) && _.isString(newB)) {
retNumber = newA.localeCompare(newB);
if (retNumber !== 0) {
return false;
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
],
"dependencies": {
"dot-prop": "^1.0.1",
"lodash.clonedeep": "^3.0.0",
"lodash.foreach": "^3.0.2"
"lodash": "^3.6.0"
},
"devDependencies": {
"coveralls": "^2.11.2",
Expand Down

2 comments on commit a7ed3df

@arthurvr
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requiring the whole lodash seems like quite a bunch for a utility module.

@stevemao
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.. Do you think I shouldn't require lodash at all or small modules?

Please sign in to comment.