Skip to content

Commit

Permalink
Replace _.contains and _.pluck with lodash v4 compatible _.includes a…
Browse files Browse the repository at this point in the history
…nd _.map
  • Loading branch information
raineorshine committed Oct 2, 2016
1 parent 9c695c4 commit 3944ae1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
6 changes: 3 additions & 3 deletions lib/version-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ function precisionAdd(precision, n) {
}

var index = n === 0 ? precision :
_.contains(VERSION_BASE_PARTS, precision) ? VERSION_BASE_PARTS.indexOf(precision) + n :
_.contains(VERSION_ADDED_PARTS, precision) ? VERSION_BASE_PARTS.length + n :
_.includes(VERSION_BASE_PARTS, precision) ? VERSION_BASE_PARTS.indexOf(precision) + n :
_.includes(VERSION_ADDED_PARTS, precision) ? VERSION_BASE_PARTS.length + n :
null;

if (index === null) {
Expand All @@ -68,7 +68,7 @@ function stringify(semver, precision) {
// pair each part with its delimiter and join together
return parts
.filter(function (part) {
return _.contains(VERSION_BASE_PARTS, precision) || semver[part];
return _.includes(VERSION_BASE_PARTS, precision) || semver[part];
})
.map(function (part) {
return VERSION_PART_DELIM[part] + (semver[part] || '0');
Expand Down
14 changes: 8 additions & 6 deletions lib/versionmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ function upgradeDependencyDeclaration(declaration, latestVersion, options) {
*/
function chooseVersion(part) {
return versionUtil.isWildPart(declaredSemver[part]) ? declaredSemver[part] :
_.contains(versionUtil.VERSION_BASE_PARTS, part) && declaredSemver[part] ? latestSemver[part] :
_.contains(versionUtil.VERSION_ADDED_PARTS, part) ? latestSemver[part] :
_.includes(versionUtil.VERSION_BASE_PARTS, part) && declaredSemver[part] ? latestSemver[part] :
_.includes(versionUtil.VERSION_ADDED_PARTS, part) ? latestSemver[part] :
undefined;
}

Expand All @@ -81,12 +81,14 @@ function upgradeDependencyDeclaration(declaration, latestVersion, options) {
// determine the operator
// do not compact, because [undefined, '<'] must be differentiated from ['<']
var uniqueOperators = _(parsedRange)
.pluck('operator')
.map(function (range) {
return range.operator;
})
.uniq()
.value();
var operator = uniqueOperators[0] || '';

var hasWildCard = versionUtil.WILDCARDS.some(_.partial(_.contains, newSemverString, _, 0));
var hasWildCard = versionUtil.WILDCARDS.some(_.partial(_.includes, newSemverString, _, 0));
var isLessThan = uniqueOperators[0] === '<' || uniqueOperators[0] === '<=';
var isMixed = uniqueOperators.length > 1;

Expand Down Expand Up @@ -181,11 +183,11 @@ function packageNameFilter(filter) {
} else {
// string filter
var packages = filter.split(/[\s,]+/);
filterPackages = _.contains.bind(_, packages);
filterPackages = _.includes.bind(_, packages);
}
} else if (Array.isArray(filter)) {
// array filter
filterPackages = _.contains.bind(_, filter);
filterPackages = _.includes.bind(_, filter);
} else if (filter instanceof RegExp) {
// raw RegExp
filterPackages = filter.test.bind(filter);
Expand Down

0 comments on commit 3944ae1

Please sign in to comment.