Skip to content

Commit

Permalink
fix: Even less lodash
Browse files Browse the repository at this point in the history
  • Loading branch information
darscan committed Jun 12, 2020
1 parent 273d82f commit 3187e9f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
5 changes: 2 additions & 3 deletions lib/ruby/gem-requirement.js
@@ -1,5 +1,4 @@
const _escapeRegExp = require('lodash.escaperegexp');
const _isEmpty = require('lodash.isempty');
const _flatten = require('lodash.flatten');
const _uniq = require('lodash.uniq');

Expand Down Expand Up @@ -82,9 +81,9 @@ module.exports = class GemRequirement {
// same as <tt>">= 0"</tt>.

constructor(...requirements) {
requirements = _uniq(_flatten(requirements));
requirements = _uniq(_flatten(requirements)).filter(Boolean);

if (_isEmpty(requirements)) {
if (requirements.length === 0) {
this.requirements = [DefaultRequirement];
} else {
this.requirements = requirements.map(GemRequirement.parse);
Expand Down
14 changes: 10 additions & 4 deletions lib/ruby/gem-version.js
Expand Up @@ -147,8 +147,6 @@
//
// For the last example, single-digit versions are automatically extended with
// a zero to give a sensible result.
const _isNumber = require('lodash.isnumber');
const _isString = require('lodash.isstring');

const VERSION_PATTERN = '[0-9]+(\.[0-9a-zA-Z]+)*(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?';
const ANCHORED_VERSION_PATTERN = new RegExp(`^\\s*(${VERSION_PATTERN})?\\s*$`);
Expand Down Expand Up @@ -380,8 +378,8 @@ class GemVersion {
continue;
}

if (_isString(lhs) && _isNumber(rhs)) { return -1; }
if (_isNumber(lhs) && _isString(rhs)) { return 1; }
if (isString(lhs) && isNumber(rhs)) { return -1; }
if (isNumber(lhs) && isString(rhs)) { return 1; }

if (lhs < rhs) { return -1; }
if (lhs > rhs) { return 1; }
Expand All @@ -397,6 +395,14 @@ class GemVersion {
// end
}

function isString(val) {
return typeof val === 'string';
}

function isNumber(val) {
return typeof val === 'number';
}

GemVersion.VERSION_PATTERN = VERSION_PATTERN;

module.exports = GemVersion;
3 changes: 0 additions & 3 deletions package.json
Expand Up @@ -21,9 +21,6 @@
"dependencies": {
"lodash.escaperegexp": "^4.1.0",
"lodash.flatten": "^4.4.0",
"lodash.isempty": "^4.4.0",
"lodash.isnumber": "^3.0.0",
"lodash.isstring": "^4.0.0",
"lodash.uniq": "^4.5.0"
}
}

0 comments on commit 3187e9f

Please sign in to comment.