Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@renovatebot/ruby-semver

Package Overview
Dependencies
Maintainers
1
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@renovatebot/ruby-semver - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

62

dist/index.d.ts

@@ -1,14 +0,58 @@

export declare type ReleaseType = "major" | "premajor" | "minor" | "preminor" | "patch" | "prepatch" | "prerelease";
export declare function eq(version1: string, version2: string): boolean;
export declare function gt(version1: string, version2: string): boolean;
export declare function gte(version1: string, version2: string): boolean;
export declare function lte(version1: string, version2: string): boolean;
export declare function valid(input: string): boolean;
export declare type ReleaseType = 'major' | 'premajor' | 'minor' | 'preminor' | 'patch' | 'prepatch' | 'prerelease';
/**
* v1 == v2 This is true if they're logically equivalent, even if they're not the exact same string. You already know how to compare strings.
*/
export declare function eq(v1: string, v2: string): boolean;
/**
* v1 > v2
*/
export declare function gt(v1: string, v2: string): boolean;
/**
* v1 >= v2
*/
export declare function gte(v1: string, v2: string): boolean;
/**
* v1 > v2
*/
export declare function lt(v1: string, v2: string): boolean;
/**
* v1 >= v2
*/
export declare function lte(v1: string, v2: string): boolean;
/**
* Return the parsed version, or null if it's not valid.
*/
export declare function valid(version: string): string | null;
/**
* Return true if the version satisfies the range.
*/
export declare function satisfies(version: string, range: string): boolean;
export declare function maxSatisfying(versions: string[], range: string): string;
export declare function minSatisfying(versions: string[], range: string): string;
export declare function diff(version1: string, version2: string): ReleaseType;
/**
* Return the highest version in the list that satisfies the range, or null if none of them do.
*/
export declare function maxSatisfying(versions: string[], range: string): string | null;
/**
* Return the lowest version in the list that satisfies the range, or null if none of them do.
*/
export declare function minSatisfying(versions: string[], range: string): string | null;
/**
* Return the major version number.
*/
export declare function major(v: string): number;
/**
* Return the minor version number.
*/
export declare function minor(v: string): number;
/**
* Return the patch version number.
*/
export declare function patch(v: string): number;
/**
* Returns an array of prerelease components, or null if none exist.
*/
export declare function prerelease(v: string): string[] | null;
/**
* Adapted from:
* https://github.com/snyk/ruby-semver/blob/1a3a761f0aceea14dcd558d7bd23c0c54a22d52c/lib/comparison.js
*/
export declare function diff(v1: string, v2: string): ReleaseType | null;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function eq(version1, version2) {
return false;
var version_1 = require("./ruby/version");
var requirement_1 = require("./ruby/requirement");
/**
* v1 == v2 This is true if they're logically equivalent, even if they're not the exact same string. You already know how to compare strings.
*/
function eq(v1, v2) {
var x = version_1.Version.create(v1);
var y = version_1.Version.create(v2);
return x.compare(y) === 0;
}
exports.eq = eq;
function gt(version1, version2) {
return false;
/**
* v1 > v2
*/
function gt(v1, v2) {
var x = version_1.Version.create(v1);
var y = version_1.Version.create(v2);
return x.compare(y) === 1;
}
exports.gt = gt;
function gte(version1, version2) {
return false;
/**
* v1 >= v2
*/
function gte(v1, v2) {
var x = version_1.Version.create(v1);
var y = version_1.Version.create(v2);
return x.compare(y) !== -1;
}
exports.gte = gte;
function lte(version1, version2) {
return false;
/**
* v1 > v2
*/
function lt(v1, v2) {
var x = version_1.Version.create(v1);
var y = version_1.Version.create(v2);
return x.compare(y) === -1;
}
exports.lt = lt;
/**
* v1 >= v2
*/
function lte(v1, v2) {
var x = version_1.Version.create(v1);
var y = version_1.Version.create(v2);
return x.compare(y) !== 1;
}
exports.lte = lte;
function valid(input) {
return false;
/**
* Return the parsed version, or null if it's not valid.
*/
function valid(version) {
if (!version)
return null;
return version_1.Version.isCorrect(version) ? version : null;
}
exports.valid = valid;
/**
* Return true if the version satisfies the range.
*/
function satisfies(version, range) {
return false;
try {
var v = new version_1.Version(version);
var r = new (requirement_1.Requirement.bind.apply(requirement_1.Requirement, [void 0].concat(range.split(/\s*,\s*/))))();
return r.isSatisfiedBy(v);
}
catch (_) {
return false;
}
}
exports.satisfies = satisfies;
/**
* Return the highest version in the list that satisfies the range, or null if none of them do.
*/
function maxSatisfying(versions, range) {
return "0.0.0";
return versions.reduce(function (x, y) {
var isValid = satisfies(y, range);
if (isValid && (!x || lt(x, y)))
return y;
return x;
}, null);
}
exports.maxSatisfying = maxSatisfying;
/**
* Return the lowest version in the list that satisfies the range, or null if none of them do.
*/
function minSatisfying(versions, range) {
return "0..0.0";
return versions.reduce(function (x, y) {
var isValid = satisfies(y, range);
if (isValid && (!x || gt(x, y)))
return y;
return x;
}, null);
}
exports.minSatisfying = minSatisfying;
function diff(version1, version2) {
return "major";
}
exports.diff = diff;
/**
* Return the major version number.
*/
function major(v) {
return 0;
if (!v)
return null;
var version = version_1.Version.create(v);
if (!version)
return null;
var segments = version.splitSegments()[0];
var x = segments[0];
return x;
}
exports.major = major;
/**
* Return the minor version number.
*/
function minor(v) {
return 0;
if (!v)
return null;
var version = version_1.Version.create(v);
if (!version)
return null;
var segments = version.splitSegments()[0];
var x = segments[1];
return x || null;
}
exports.minor = minor;
/**
* Return the patch version number.
*/
function patch(v) {
return 0;
if (!v)
return null;
var version = version_1.Version.create(v);
if (!version)
return null;
var segments = version.splitSegments()[0];
var x = segments[2];
return x || null;
}
exports.patch = patch;
/**
* Returns an array of prerelease components, or null if none exist.
*/
function prerelease(v) {
return null;
if (!v)
return null;
var version = version_1.Version.create(v);
if (!version)
return null;
var _a = version.splitSegments(), segments = _a[1];
return segments.length ? segments.map(function (x) { return x.toString(); }) : null;
}
exports.prerelease = prerelease;
/**
* Adapted from:
* https://github.com/snyk/ruby-semver/blob/1a3a761f0aceea14dcd558d7bd23c0c54a22d52c/lib/comparison.js
*/
function diff(v1, v2) {
if (!v1 || !v2)
return null;
var version1 = version_1.Version.create(v1);
var version2 = version_1.Version.create(v2);
if (!version1 || !version2)
return null;
if (version1.compare(version2) === 0) {
return null;
}
var hasPrerelease;
var segments = [version1.getSegments(), version2.getSegments()]
.map(function (seg) {
var prereleaseIndex = seg.findIndex(function (v) { return String(v).match(/[a-zA-Z]/); });
if (prereleaseIndex === -1) {
return seg;
}
hasPrerelease = true;
return seg.slice(0, prereleaseIndex);
})
.sort(function (a, b) { return b.length - a.length; });
var diffPosition = segments[0].findIndex(function (v, i) { return v !== segments[1][i]; });
if (diffPosition === -1 && hasPrerelease) {
return 'prerelease';
}
var diffType = ['major', 'minor'][diffPosition] || 'patch';
return ((hasPrerelease ? 'pre' : '') + diffType);
}
exports.diff = diff;

@@ -0,2 +1,20 @@

import { Version } from './version';
export declare type RawRequirement = Version | string | null;
export declare type ParsedRequirement = [string, Version];
export declare class Requirement {
readonly _requirements: ParsedRequirement[];
static PATTERN: RegExp;
static DEFAULT_REQUIREMENT: ParsedRequirement;
static create(...inputs: any[]): Requirement;
static default(): Requirement;
static parse(obj: any): ParsedRequirement;
constructor(...requirements: RawRequirement[]);
concat(newReqs: RawRequirement[]): void;
isNone(): boolean;
isPrerelease(): boolean;
isSatisfiedBy(v: Version): boolean;
isSpecific(): boolean;
eql(other: Requirement): boolean;
_tildeRequirements(): ParsedRequirement[];
}
export declare const parse: typeof Requirement.parse;

740

dist/ruby/requirement.js
"use strict";
// https://github.com/ruby/ruby/blob/d4a86e407ec2057c2c7ad757aa76dad757f34c3a/lib/rubygems/requirement.rb
Object.defineProperty(exports, "__esModule", { value: true });
// import { Version } from "./version";
// # frozen_string_literal: true

@@ -14,309 +16,443 @@ // require "rubygems/version"

//
var version_1 = require("./version");
/**
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat#Alternative
*/
function flatten(input) {
var stack = input.slice();
var res = [];
while (stack.length) {
var next = stack.pop();
if (Array.isArray(next)) {
stack.push.apply(stack, next);
}
else {
res.push(next);
}
}
return res.reverse();
}
// TODO: consider richer `eql` semantics
var defaultEql = function (x, y) { return x === y; };
function uniq(array, eql) {
if (eql === void 0) { eql = defaultEql; }
return array.filter(function (x, idx, arr) {
return arr.findIndex(function (y) { return eql(x, y); }) === idx;
});
}
function reqsEql(xReqs, yReqs, eql) {
if (xReqs.length !== yReqs.length)
return false;
for (var idx = 0; idx < xReqs.length; idx += 1) {
if (!eql(xReqs[idx], yReqs[idx]))
return false;
}
return true;
}
// class Gem::Requirement
//
var Requirement = /** @class */ (function () {
// ##
// # An array of requirement pairs. The first element of the pair is
// # the op, and the second is the Gem::Version.
//
// attr_reader :requirements #:nodoc:
// ##
// # Constructs a requirement from +requirements+. Requirements can be
// # Strings, Gem::Versions, or Arrays of those. +nil+ and duplicate
// # requirements are ignored. An empty set of +requirements+ is the
// # same as <tt>">= 0"</tt>.
//
// def initialize(*requirements)
// requirements = requirements.flatten
// requirements.compact!
// requirements.uniq!
//
// if requirements.empty?
// @requirements = [DefaultRequirement]
// else
// @requirements = requirements.map! { |r| self.class.parse r }
// end
// end
function Requirement() {
var requirements = [];
for (var _i = 0; _i < arguments.length; _i++) {
requirements[_i] = arguments[_i];
}
var flattened = flatten(requirements);
var compacted = flattened.filter(function (x) { return x !== null; });
var unique = uniq(compacted);
if (unique.length === 0) {
this._requirements = [Requirement.DEFAULT_REQUIREMENT];
}
else {
this._requirements = unique.map(function (r) { return Requirement.parse(r); });
}
}
// ##
// # The default requirement matches any version
//
// DefaultPrereleaseRequirement = [">=", Gem::Version.new("0.a")].freeze
// static DEFAULT_PRERELEASE_REQUIREMENT: ParsedRequirement = [
// '>=',
// new Version('0.a'),
// ];
// ##
// # Raised when a bad requirement is encountered
//
// class BadRequirementError < ArgumentError; end
// ##
// # Factory method to create a Gem::Requirement object. Input may be
// # a Version, a String, or nil. Intended to simplify client code.
// #
// # If the input is "weird", the default version requirement is
// # returned.
//
// def self.create(*inputs)
// return new inputs if inputs.length > 1
//
// input = inputs.shift
//
// case input
// when Gem::Requirement then
// input
// when Gem::Version, Array then
// new input
// when '!' then
// source_set
// else
// if input.respond_to? :to_str
// new [input.to_str]
// else
// default
// end
// end
// end
Requirement.create = function () {
var inputs = [];
for (var _i = 0; _i < arguments.length; _i++) {
inputs[_i] = arguments[_i];
}
if (inputs.length > 1)
return new (Requirement.bind.apply(Requirement, [void 0].concat(inputs)))();
var input = inputs.shift();
if (input instanceof Requirement)
return input;
if (input instanceof Array)
return new (Requirement.bind.apply(Requirement, [void 0].concat(input)))();
if (input instanceof version_1.Version)
return new Requirement(input);
try {
return new Requirement(input.toString());
}
catch (_) {
return Requirement.default();
}
};
// def self.default
// new '>= 0'
// end
Requirement.default = function () {
return new Requirement('>= 0');
};
// def self.default_prerelease
// new '>= 0.a'
// end
//
// ###
// # A source set requirement, used for Gemfiles and lockfiles
//
// def self.source_set # :nodoc:
// SOURCE_SET_REQUIREMENT
// end
// ##
// # Parse +obj+, returning an <tt>[op, version]</tt> pair. +obj+ can
// # be a String or a Gem::Version.
// #
// # If +obj+ is a String, it can be either a full requirement
// # specification, like <tt>">= 1.2"</tt>, or a simple version number,
// # like <tt>"1.2"</tt>.
// #
// # parse("> 1.0") # => [">", Gem::Version.new("1.0")]
// # parse("1.0") # => ["=", Gem::Version.new("1.0")]
// # parse(Gem::Version.new("1.0")) # => ["=, Gem::Version.new("1.0")]
//
// def self.parse(obj)
// return ["=", obj] if Gem::Version === obj
//
// unless PATTERN =~ obj.to_s
// raise BadRequirementError, "Illformed requirement [#{obj.inspect}]"
// end
//
// if $1 == ">=" && $2 == "0"
// DefaultRequirement
// elsif $1 == ">=" && $2 == "0.a"
// DefaultPrereleaseRequirement
// else
// [$1 || "=", Gem::Version.new($2)]
// end
// end
Requirement.parse = function (obj) {
var err = function () {
throw new Error("Illformed requirement [" + obj + "]");
};
if (obj instanceof version_1.Version)
return ['=', obj];
var objStr;
try {
objStr = obj.toString();
}
catch (_) {
err();
}
var match = objStr.match(Requirement.PATTERN);
if (!match)
err();
var $1 = match[1], $2 = match[2];
return [$1 || '=', new version_1.Version($2)];
};
// ##
// # Concatenates the +new+ requirements onto this requirement.
//
// def concat(new)
// new = new.flatten
// new.compact!
// new.uniq!
// new = new.map { |r| self.class.parse r }
//
// @requirements.concat new
// end
Requirement.prototype.concat = function (newReqs) {
var _this = this;
var flattened = flatten(newReqs);
var compacted = flattened.filter(function (x) { return x !== null; });
var unique = uniq(compacted);
var parsed = unique.map(function (x) { return Requirement.parse(x); });
parsed.forEach(function (x) { return _this._requirements.push(x); });
};
//
// ##
// # Formats this requirement for use in a Gem::RequestSet::Lockfile.
//
// def for_lockfile # :nodoc:
// return if [DefaultRequirement] == @requirements
//
// list = requirements.sort_by do |_, version|
// version
// end.map do |op, version|
// "#{op} #{version}"
// end.uniq
//
// " (#{list.join ', '})"
// end
// ##
// # true if this gem has no requirements.
//
// def none?
// if @requirements.size == 1
// @requirements[0] == DefaultRequirement
// else
// false
// end
// end
Requirement.prototype.isNone = function () {
if (this._requirements.length === 1) {
var _a = this._requirements[0], op = _a[0], v = _a[1];
return (op === Requirement.DEFAULT_REQUIREMENT[0] &&
v.compare(Requirement.DEFAULT_REQUIREMENT[1]) === 0);
}
return false;
};
// ##
// # true if the requirement is for only an exact version
//
// def exact?
// return false unless @requirements.size == 1
// @requirements[0][0] == "="
// end
//
// def as_list # :nodoc:
// requirements.map { |op, version| "#{op} #{version}" }
// end
//
// def hash # :nodoc:
// requirements.sort.hash
// end
//
// def marshal_dump # :nodoc:
// fix_syck_default_key_in_requirements
//
// [@requirements]
// end
//
// def marshal_load(array) # :nodoc:
// @requirements = array[0]
//
// fix_syck_default_key_in_requirements
// end
//
// def yaml_initialize(tag, vals) # :nodoc:
// vals.each do |ivar, val|
// instance_variable_set "@#{ivar}", val
// end
//
// Gem.load_yaml
// fix_syck_default_key_in_requirements
// end
//
// def init_with(coder) # :nodoc:
// yaml_initialize coder.tag, coder.map
// end
//
// def to_yaml_properties # :nodoc:
// ["@requirements"]
// end
//
// def encode_with(coder) # :nodoc:
// coder.add 'requirements', @requirements
// end
//
// ##
// # A requirement is a prerelease if any of the versions inside of it
// # are prereleases
// def prerelease?
// requirements.any? { |r| r.last.prerelease? }
// end
Requirement.prototype.isPrerelease = function () {
return this._requirements.some(function (_a) {
var ver = _a[1];
return ver.isPrerelease();
});
};
// def pretty_print(q) # :nodoc:
// q.group 1, 'Gem::Requirement.new(', ')' do
// q.pp as_list
// end
// end
// ##
// # True if +version+ satisfies this Requirement.
//
// def satisfied_by?(version)
// raise ArgumentError, "Need a Gem::Version: #{version.inspect}" unless
// Gem::Version === version
// # #28965: syck has a bug with unquoted '=' YAML.loading as YAML::DefaultKey
// requirements.all? { |op, rv| (OPS[op] || OPS["="]).call version, rv }
// end
Requirement.prototype.isSatisfiedBy = function (v) {
return this._requirements.every(function (_a) {
var op = _a[0], r = _a[1];
// "=" => lambda { |v, r| v == r },
// "!=" => lambda { |v, r| v != r },
// ">" => lambda { |v, r| v > r },
// "<" => lambda { |v, r| v < r },
// ">=" => lambda { |v, r| v >= r },
// "<=" => lambda { |v, r| v <= r },
// "~>" => lambda { |v, r| v >= r && v.release < r.bump }
switch (op) {
case '=':
return v.compare(r) === 0;
case '!=':
return v.compare(r) !== 0;
case '>':
return v.compare(r) === 1;
case '<':
return v.compare(r) === -1;
case '>=':
return v.compare(r) !== -1;
case '<=':
return v.compare(r) !== 1;
case '~>':
return v.compare(r) !== -1 && v.release().compare(r.bump()) === -1;
/* istanbul ignore next */
default:
return false;
}
});
};
// alias :=== :satisfied_by?
// alias :=~ :satisfied_by?
// ##
// # True if the requirement will not always match the latest version.
//
// def specific?
// return true if @requirements.length > 1 # GIGO, > 1, > 2 is silly
//
// not %w[> >=].include? @requirements.first.first # grab the operator
// end
Requirement.prototype.isSpecific = function () {
if (this._requirements.length > 1)
return true;
var firstOp = this._requirements[0][0];
return !(firstOp === '>' || firstOp === '>=');
};
// def to_s # :nodoc:
// as_list.join ", "
// end
// def ==(other) # :nodoc:
// return unless Gem::Requirement === other
//
// # An == check is always necessary
// return false unless requirements == other.requirements
//
// # An == check is sufficient unless any requirements use ~>
// return true unless _tilde_requirements.any?
//
// # If any requirements use ~> we use the stricter `#eql?` that also checks
// # that version precision is the same
// _tilde_requirements.eql?(other._tilde_requirements)
// end
Requirement.prototype.eql = function (other) {
if (!reqsEql(this._requirements, other._requirements, function (_a, _b) {
var xOp = _a[0], xVer = _a[1];
var yOp = _b[0], yVer = _b[1];
return xOp === yOp && xVer.compare(yVer) === 0;
})) {
return false;
}
var tildeReqs = this._tildeRequirements();
if (tildeReqs.length === 0)
return true;
return reqsEql(tildeReqs, other._tildeRequirements(), function (_a, _b) {
var xVer = _a[1];
var yVer = _b[1];
return xVer.strictEql(yVer);
});
};
// protected
//
// def _tilde_requirements
// requirements.select { |r| r.first == "~>" }
// end
Requirement.prototype._tildeRequirements = function () {
return this._requirements.filter(function (_a) {
var op = _a[0];
return op === '~>';
});
};
// OPS = { #:nodoc:
// "=" => lambda { |v, r| v == r },
// "!=" => lambda { |v, r| v != r },
// ">" => lambda { |v, r| v > r },
// "<" => lambda { |v, r| v < r },
// ">=" => lambda { |v, r| v >= r },
// "<=" => lambda { |v, r| v <= r },
// "~>" => lambda { |v, r| v >= r && v.release < r.bump }
// }.freeze
//
// SOURCE_SET_REQUIREMENT = Struct.new(:for_lockfile).new "!" # :nodoc:
//
// quoted = OPS.keys.map { |k| Regexp.quote k }.join "|"
// PATTERN_RAW = "\\s*(#{quoted})?\\s*(#{Gem::Version::VERSION_PATTERN})\\s*".freeze # :nodoc:
// ##
// # A regular expression that matches a requirement
//
// PATTERN = /\A#{PATTERN_RAW}\z/.freeze
Requirement.PATTERN = /^\s*(=|!=|>|<|>=|<=|~>)?\s*([0-9]+(\.[0-9a-zA-Z]+)*(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?)\s*$/;
// ##
// # The default requirement matches any non-prerelease version
// DefaultRequirement = [">=", Gem::Version.new(0)].freeze
Requirement.DEFAULT_REQUIREMENT = ['>=', new version_1.Version('0')];
return Requirement;
}());
exports.Requirement = Requirement;
// class Gem::Requirement
//
// OPS = { #:nodoc:
// "=" => lambda { |v, r| v == r },
// "!=" => lambda { |v, r| v != r },
// ">" => lambda { |v, r| v > r },
// "<" => lambda { |v, r| v < r },
// ">=" => lambda { |v, r| v >= r },
// "<=" => lambda { |v, r| v <= r },
// "~>" => lambda { |v, r| v >= r && v.release < r.bump }
// }.freeze
//
// SOURCE_SET_REQUIREMENT = Struct.new(:for_lockfile).new "!" # :nodoc:
//
// quoted = OPS.keys.map { |k| Regexp.quote k }.join "|"
// PATTERN_RAW = "\\s*(#{quoted})?\\s*(#{Gem::Version::VERSION_PATTERN})\\s*".freeze # :nodoc:
//
// ##
// # A regular expression that matches a requirement
//
// PATTERN = /\A#{PATTERN_RAW}\z/.freeze
//
// ##
// # The default requirement matches any non-prerelease version
//
// DefaultRequirement = [">=", Gem::Version.new(0)].freeze
//
// ##
// # The default requirement matches any version
//
// DefaultPrereleaseRequirement = [">=", Gem::Version.new("0.a")].freeze
//
// ##
// # Raised when a bad requirement is encountered
//
// class BadRequirementError < ArgumentError; end
//
// ##
// # Factory method to create a Gem::Requirement object. Input may be
// # a Version, a String, or nil. Intended to simplify client code.
// #
// # If the input is "weird", the default version requirement is
// # returned.
//
// def self.create(*inputs)
// return new inputs if inputs.length > 1
//
// input = inputs.shift
//
// case input
// when Gem::Requirement then
// input
// when Gem::Version, Array then
// new input
// when '!' then
// source_set
// else
// if input.respond_to? :to_str
// new [input.to_str]
// else
// default
// end
// end
// end
//
// def self.default
// new '>= 0'
// end
//
// def self.default_prerelease
// new '>= 0.a'
// end
//
// ###
// # A source set requirement, used for Gemfiles and lockfiles
//
// def self.source_set # :nodoc:
// SOURCE_SET_REQUIREMENT
// end
//
// ##
// # Parse +obj+, returning an <tt>[op, version]</tt> pair. +obj+ can
// # be a String or a Gem::Version.
// #
// # If +obj+ is a String, it can be either a full requirement
// # specification, like <tt>">= 1.2"</tt>, or a simple version number,
// # like <tt>"1.2"</tt>.
// #
// # parse("> 1.0") # => [">", Gem::Version.new("1.0")]
// # parse("1.0") # => ["=", Gem::Version.new("1.0")]
// # parse(Gem::Version.new("1.0")) # => ["=, Gem::Version.new("1.0")]
//
// def self.parse(obj)
// return ["=", obj] if Gem::Version === obj
//
// unless PATTERN =~ obj.to_s
// raise BadRequirementError, "Illformed requirement [#{obj.inspect}]"
// end
//
// if $1 == ">=" && $2 == "0"
// DefaultRequirement
// elsif $1 == ">=" && $2 == "0.a"
// DefaultPrereleaseRequirement
// else
// [$1 || "=", Gem::Version.new($2)]
// end
// end
//
// ##
// # An array of requirement pairs. The first element of the pair is
// # the op, and the second is the Gem::Version.
//
// attr_reader :requirements #:nodoc:
//
// ##
// # Constructs a requirement from +requirements+. Requirements can be
// # Strings, Gem::Versions, or Arrays of those. +nil+ and duplicate
// # requirements are ignored. An empty set of +requirements+ is the
// # same as <tt>">= 0"</tt>.
//
// def initialize(*requirements)
// requirements = requirements.flatten
// requirements.compact!
// requirements.uniq!
//
// if requirements.empty?
// @requirements = [DefaultRequirement]
// else
// @requirements = requirements.map! { |r| self.class.parse r }
// end
// end
//
// ##
// # Concatenates the +new+ requirements onto this requirement.
//
// def concat(new)
// new = new.flatten
// new.compact!
// new.uniq!
// new = new.map { |r| self.class.parse r }
//
// @requirements.concat new
// end
//
// ##
// # Formats this requirement for use in a Gem::RequestSet::Lockfile.
//
// def for_lockfile # :nodoc:
// return if [DefaultRequirement] == @requirements
//
// list = requirements.sort_by do |_, version|
// version
// end.map do |op, version|
// "#{op} #{version}"
// end.uniq
//
// " (#{list.join ', '})"
// end
//
// ##
// # true if this gem has no requirements.
//
// def none?
// if @requirements.size == 1
// @requirements[0] == DefaultRequirement
// else
// false
// end
// end
//
// ##
// # true if the requirement is for only an exact version
//
// def exact?
// return false unless @requirements.size == 1
// @requirements[0][0] == "="
// end
//
// def as_list # :nodoc:
// requirements.map { |op, version| "#{op} #{version}" }
// end
//
// def hash # :nodoc:
// requirements.sort.hash
// end
//
// def marshal_dump # :nodoc:
// fix_syck_default_key_in_requirements
//
// [@requirements]
// end
//
// def marshal_load(array) # :nodoc:
// @requirements = array[0]
//
// fix_syck_default_key_in_requirements
// end
//
// def yaml_initialize(tag, vals) # :nodoc:
// vals.each do |ivar, val|
// instance_variable_set "@#{ivar}", val
// end
//
// Gem.load_yaml
// fix_syck_default_key_in_requirements
// end
//
// def init_with(coder) # :nodoc:
// yaml_initialize coder.tag, coder.map
// end
//
// def to_yaml_properties # :nodoc:
// ["@requirements"]
// end
//
// def encode_with(coder) # :nodoc:
// coder.add 'requirements', @requirements
// end
//
// ##
// # A requirement is a prerelease if any of the versions inside of it
// # are prereleases
//
// def prerelease?
// requirements.any? { |r| r.last.prerelease? }
// end
//
// def pretty_print(q) # :nodoc:
// q.group 1, 'Gem::Requirement.new(', ')' do
// q.pp as_list
// end
// end
//
// ##
// # True if +version+ satisfies this Requirement.
//
// def satisfied_by?(version)
// raise ArgumentError, "Need a Gem::Version: #{version.inspect}" unless
// Gem::Version === version
// # #28965: syck has a bug with unquoted '=' YAML.loading as YAML::DefaultKey
// requirements.all? { |op, rv| (OPS[op] || OPS["="]).call version, rv }
// end
//
// alias :=== :satisfied_by?
// alias :=~ :satisfied_by?
//
// ##
// # True if the requirement will not always match the latest version.
//
// def specific?
// return true if @requirements.length > 1 # GIGO, > 1, > 2 is silly
//
// not %w[> >=].include? @requirements.first.first # grab the operator
// end
//
// def to_s # :nodoc:
// as_list.join ", "
// end
//
// def ==(other) # :nodoc:
// return unless Gem::Requirement === other
//
// # An == check is always necessary
// return false unless requirements == other.requirements
//
// # An == check is sufficient unless any requirements use ~>
// return true unless _tilde_requirements.any?
//
// # If any requirements use ~> we use the stricter `#eql?` that also checks
// # that version precision is the same
// _tilde_requirements.eql?(other._tilde_requirements)
// end
//
// protected
//
// def _tilde_requirements
// requirements.select { |r| r.first == "~>" }
// end
//
// private
//
// def fix_syck_default_key_in_requirements # :nodoc:
// Gem.load_yaml
//
// # Fixup the Syck DefaultKey bug
// @requirements.each do |r|
// if r[0].kind_of? Gem::SyckDefaultKey
// r[0] = "="
// end
// end
// end
//
// end
//
// class Gem::Version
//
// # This is needed for compatibility with older yaml
// # gemspecs.
//
// Requirement = Gem::Requirement # :nodoc:
//
// end
exports.parse = Requirement.parse;

@@ -0,2 +1,21 @@

export declare type SegmentElement = string | number;
export declare class Version {
static ANCHORED_VERSION_PATTERN: RegExp;
private readonly _version;
private _segments;
version(): string;
toString(): string;
static isCorrect(version: any): boolean;
static create(input: any): Version | null;
constructor(version: any);
bump(): Version;
strictEql(other: Version): boolean;
isPrerelease(): boolean;
release(): Version;
approximateRecommendation(): string;
compare(other: Version): number;
canonicalSegments(): SegmentElement[];
getSegments(): SegmentElement[];
splitSegments(): [number[], SegmentElement[]];
}
export declare const create: typeof Version.create;
"use strict";
// # frozen_string_literal: true
// ##
// # The Version class processes string versions into comparable
// # values. A version string should normally be a series of numbers
// # separated by periods. Each part (digits separated by periods) is
// # considered its own number, and these are used for sorting. So for
// # instance, 3.10 sorts higher than 3.2 because ten is greater than
// # two.
// #
// # If any part contains letters (currently only a-z are supported) then
// # that version is considered prerelease. Versions with a prerelease
// # part in the Nth part sort less than versions with N-1
// # parts. Prerelease parts are sorted alphabetically using the normal
// # Ruby string sorting rules. If a prerelease part contains both
// # letters and numbers, it will be broken into multiple parts to
// # provide expected sort behavior (1.0.a10 becomes 1.0.a.10, and is
// # greater than 1.0.a9).
// #
// # Prereleases sort between real releases (newest to oldest):
// #
// # 1. 1.0
// # 2. 1.0.b1
// # 3. 1.0.a.2
// # 4. 0.9
// #
// # If you want to specify a version restriction that includes both prereleases
// # and regular releases of the 1.x series this is the best way:
// #
// # s.add_dependency 'example', '>= 1.0.0.a', '< 2.0.0'
// #
// # == How Software Changes
// #
// # Users expect to be able to specify a version constraint that gives them
// # some reasonable expectation that new versions of a library will work with
// # their software if the version constraint is true, and not work with their
// # software if the version constraint is false. In other words, the perfect
// # system will accept all compatible versions of the library and reject all
// # incompatible versions.
// #
// # Libraries change in 3 ways (well, more than 3, but stay focused here!).
// #
// # 1. The change may be an implementation detail only and have no effect on
// # the client software.
// # 2. The change may add new features, but do so in a way that client software
// # written to an earlier version is still compatible.
// # 3. The change may change the public interface of the library in such a way
// # that old software is no longer compatible.
// #
// # Some examples are appropriate at this point. Suppose I have a Stack class
// # that supports a <tt>push</tt> and a <tt>pop</tt> method.
// #
// # === Examples of Category 1 changes:
// #
// # * Switch from an array based implementation to a linked-list based
// # implementation.
// # * Provide an automatic (and transparent) backing store for large stacks.
// #
// # === Examples of Category 2 changes might be:
// #
// # * Add a <tt>depth</tt> method to return the current depth of the stack.
// # * Add a <tt>top</tt> method that returns the current top of stack (without
// # changing the stack).
// # * Change <tt>push</tt> so that it returns the item pushed (previously it
// # had no usable return value).
// #
// # === Examples of Category 3 changes might be:
// #
// # * Changes <tt>pop</tt> so that it no longer returns a value (you must use
// # <tt>top</tt> to get the top of the stack).
// # * Rename the methods to <tt>push_item</tt> and <tt>pop_item</tt>.
// #
// # == RubyGems Rational Versioning
// #
// # * Versions shall be represented by three non-negative integers, separated
// # by periods (e.g. 3.1.4). The first integers is the "major" version
// # number, the second integer is the "minor" version number, and the third
// # integer is the "build" number.
// #
// # * A category 1 change (implementation detail) will increment the build
// # number.
// #
// # * A category 2 change (backwards compatible) will increment the minor
// # version number and reset the build number.
// #
// # * A category 3 change (incompatible) will increment the major build number
// # and reset the minor and build numbers.
// #
// # * Any "public" release of a gem should have a different version. Normally
// # that means incrementing the build number. This means a developer can
// # generate builds all day long, but as soon as they make a public release,
// # the version must be updated.
// #
// # === Examples
// #
// # Let's work through a project lifecycle using our Stack example from above.
// #
// # Version 0.0.1:: The initial Stack class is release.
// # Version 0.0.2:: Switched to a linked=list implementation because it is
// # cooler.
// # Version 0.1.0:: Added a <tt>depth</tt> method.
// # Version 1.0.0:: Added <tt>top</tt> and made <tt>pop</tt> return nil
// # (<tt>pop</tt> used to return the old top item).
// # Version 1.1.0:: <tt>push</tt> now returns the value pushed (it used it
// # return nil).
// # Version 1.1.1:: Fixed a bug in the linked list implementation.
// # Version 1.1.2:: Fixed a bug introduced in the last fix.
// #
// # Client A needs a stack with basic push/pop capability. They write to the
// # original interface (no <tt>top</tt>), so their version constraint looks like:
// #
// # gem 'stack', '>= 0.0'
// #
// # Essentially, any version is OK with Client A. An incompatible change to
// # the library will cause them grief, but they are willing to take the chance
// # (we call Client A optimistic).
// #
// # Client B is just like Client A except for two things: (1) They use the
// # <tt>depth</tt> method and (2) they are worried about future
// # incompatibilities, so they write their version constraint like this:
// #
// # gem 'stack', '~> 0.1'
// #
// # The <tt>depth</tt> method was introduced in version 0.1.0, so that version
// # or anything later is fine, as long as the version stays below version 1.0
// # where incompatibilities are introduced. We call Client B pessimistic
// # because they are worried about incompatible future changes (it is OK to be
// # pessimistic!).
// #
// # == Preventing Version Catastrophe:
// #
// # From: http://blog.zenspider.com/2008/10/rubygems-howto-preventing-cata.html
// #
// # Let's say you're depending on the fnord gem version 2.y.z. If you
// # specify your dependency as ">= 2.0.0" then, you're good, right? What
// # happens if fnord 3.0 comes out and it isn't backwards compatible
// # with 2.y.z? Your stuff will break as a result of using ">=". The
// # better route is to specify your dependency with an "approximate" version
// # specifier ("~>"). They're a tad confusing, so here is how the dependency
// # specifiers work:
// #
// # Specification From ... To (exclusive)
// # ">= 3.0" 3.0 ... &infin;
// # "~> 3.0" 3.0 ... 4.0
// # "~> 3.0.0" 3.0.0 ... 3.1
// # "~> 3.5" 3.5 ... 4.0
// # "~> 3.5.0" 3.5.0 ... 3.6
// # "~> 3" 3.0 ... 4.0
// #
// # For the last example, single-digit versions are automatically extended with
// # a zero to give a sensible result.
// https://github.com/ruby/ruby/blob/d4a86e407ec2057c2c7ad757aa76dad757f34c3a/lib/rubygems/version.rb
Object.defineProperty(exports, "__esModule", { value: true });
var Version = /** @class */ (function () {
function Version() {
}
return Version;
}());
exports.Version = Version;
// class Gem::Version

@@ -164,245 +9,380 @@ //

// include Comparable
//
// VERSION_PATTERN = '[0-9]+(?>\.[0-9a-zA-Z]+)*(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?'.freeze # :nodoc:
// ANCHORED_VERSION_PATTERN = /\A\s*(#{VERSION_PATTERN})?\s*\z/.freeze # :nodoc:
//
// ##
// # A string representation of this Version.
//
// def version
// @version.dup
// end
//
// alias to_s version
//
// ##
// # True if the +version+ string matches RubyGems' requirements.
//
// def self.correct?(version)
// unless Gem::Deprecate.skip
// warn "nil versions are discouraged and will be deprecated in Rubygems 4" if version.nil?
// end
//
// !!(version.to_s =~ ANCHORED_VERSION_PATTERN)
// end
//
// ##
// # Factory method to create a Version object. Input may be a Version
// # or a String. Intended to simplify client code.
// #
// # ver1 = Version.create('1.3.17') # -> (Version object)
// # ver2 = Version.create(ver1) # -> (ver1)
// # ver3 = Version.create(nil) # -> nil
//
// def self.create(input)
// if self === input # check yourself before you wreck yourself
// input
// elsif input.nil?
// nil
// else
// new input
// end
// end
//
// @@all = {}
//
// def self.new(version) # :nodoc:
// return super unless Gem::Version == self
//
// @@all[version] ||= super
// end
//
// ##
// # Constructs a Version from the +version+ string. A version string is a
// # series of digits or ASCII letters separated by dots.
//
// def initialize(version)
// unless self.class.correct?(version)
// raise ArgumentError, "Malformed version number string #{version}"
// end
//
// # If version is an empty string convert it to 0
// version = 0 if version.is_a?(String) && version =~ /\A\s*\Z/
//
// @version = version.to_s.strip.gsub("-",".pre.")
// @segments = nil
// end
//
// ##
// # Return a new version object where the next to the last revision
// # number is one greater (e.g., 5.3.1 => 5.4).
// #
// # Pre-release (alpha) parts, e.g, 5.3.1.b.2 => 5.4, are ignored.
//
// def bump
// @bump ||= begin
// segments = self.segments
// segments.pop while segments.any? { |s| String === s }
// segments.pop if segments.size > 1
//
// segments[-1] = segments[-1].succ
// self.class.new segments.join(".")
// end
// end
//
// ##
// # A Version is only eql? to another version if it's specified to the
// # same precision. Version "1.0" is not the same as version "1".
//
// def eql?(other)
// self.class === other and @version == other._version
// end
//
// def hash # :nodoc:
// canonical_segments.hash
// end
//
// def init_with(coder) # :nodoc:
// yaml_initialize coder.tag, coder.map
// end
//
// def inspect # :nodoc:
// "#<#{self.class} #{version.inspect}>"
// end
//
// ##
// # Dump only the raw version string, not the complete object. It's a
// # string for backwards (RubyGems 1.3.5 and earlier) compatibility.
//
// def marshal_dump
// [version]
// end
//
// ##
// # Load custom marshal format. It's a string for backwards (RubyGems
// # 1.3.5 and earlier) compatibility.
//
// def marshal_load(array)
// initialize array[0]
// end
//
// def yaml_initialize(tag, map) # :nodoc:
// @version = map['version']
// @segments = nil
// @hash = nil
// end
//
// def to_yaml_properties # :nodoc:
// ["@version"]
// end
//
// def encode_with(coder) # :nodoc:
// coder.add 'version', @version
// end
//
// ##
// # A version is considered a prerelease if it contains a letter.
//
// def prerelease?
// unless instance_variable_defined? :@prerelease
// @prerelease = !!(@version =~ /[a-zA-Z]/)
// end
// @prerelease
// end
//
// def pretty_print(q) # :nodoc:
// q.text "Gem::Version.new(#{version.inspect})"
// end
//
// ##
// # The release for this version (e.g. 1.2.0.a -> 1.2.0).
// # Non-prerelease versions return themselves.
//
// def release
// @release ||= if prerelease?
// segments = self.segments
// segments.pop while segments.any? { |s| String === s }
// self.class.new segments.join('.')
// else
// self
// end
// end
//
// def segments # :nodoc:
// _segments.dup
// end
//
// ##
// # A recommended version for use with a ~> Requirement.
//
// def approximate_recommendation
// segments = self.segments
//
// segments.pop while segments.any? { |s| String === s }
// segments.pop while segments.size > 2
// segments.push 0 while segments.size < 2
//
// recommendation = "~> #{segments.join(".")}"
// recommendation += ".a" if prerelease?
// recommendation
// end
//
// ##
// # Compares this version with +other+ returning -1, 0, or 1 if the
// # other version is larger, the same, or smaller than this
// # one. Attempts to compare to something that's not a
// # <tt>Gem::Version</tt> return +nil+.
//
// def <=>(other)
// return unless Gem::Version === other
// return 0 if @version == other._version || canonical_segments == other.canonical_segments
//
// lhsegments = canonical_segments
// rhsegments = other.canonical_segments
//
// lhsize = lhsegments.size
// rhsize = rhsegments.size
// limit = (lhsize > rhsize ? lhsize : rhsize) - 1
//
// i = 0
//
// while i <= limit
// lhs, rhs = lhsegments[i] || 0, rhsegments[i] || 0
// i += 1
//
// next if lhs == rhs
// return -1 if String === lhs && Numeric === rhs
// return 1 if Numeric === lhs && String === rhs
//
// return lhs <=> rhs
// end
//
// return 0
// end
//
// def canonical_segments
// @canonical_segments ||=
// _split_segments.map! do |segments|
// segments.reverse_each.drop_while {|s| s == 0 }.reverse
// end.reduce(&:concat)
// end
//
// protected
//
// def _version
// @version
// end
//
// def _segments
// # segments is lazy so it can pick up version values that come from
// # old marshaled versions, which don't go through marshal_load.
// # since this version object is cached in @@all, its @segments should be frozen
//
// @segments ||= @version.scan(/[0-9]+|[a-z]+/i).map do |s|
// /^\d+$/ =~ s ? s.to_i : s
// end.freeze
// end
//
// def _split_segments
// string_start = _segments.index {|s| s.is_a?(String) }
// string_segments = segments
// numeric_segments = string_segments.slice!(0, string_start || string_segments.size)
// return numeric_segments, string_segments
// end
//
// end
var Version = /** @class */ (function () {
// @@all = {}
//
// def self.new(version) # :nodoc:
// return super unless Gem::Version == self
//
// @@all[version] ||= super
// end
//
// ##
// # Constructs a Version from the +version+ string. A version string is a
// # series of digits or ASCII letters separated by dots.
//
// def initialize(version)
// unless self.class.correct?(version)
// raise ArgumentError, "Malformed version number string #{version}"
// end
//
// # If version is an empty string convert it to 0
// version = 0 if version.is_a?(String) && version =~ /\A\s*\Z/
//
// @version = version.to_s.strip.gsub("-",".pre.")
// @segments = nil
// end
function Version(version) {
if (!Version.isCorrect(version)) {
throw new Error("Malformed version number string " + version);
}
var versionStr = version.toString();
if (/^\s*$/.test(versionStr)) {
versionStr = '0';
}
this._version = versionStr.trim().replace(/-/g, '.pre.');
this._segments = null;
}
// ##
// # A string representation of this Version.
//
// def version
// @version.dup
// end
Version.prototype.version = function () {
return this._version;
};
// alias to_s version
Version.prototype.toString = function () {
return this.version();
};
// ##
// # True if the +version+ string matches RubyGems' requirements.
//
// def self.correct?(version)
// unless Gem::Deprecate.skip
// warn "nil versions are discouraged and will be deprecated in Rubygems 4" if version.nil?
// end
//
// !!(version.to_s =~ ANCHORED_VERSION_PATTERN)
// end
Version.isCorrect = function (version) {
var versionStr;
try {
versionStr = version.toString();
}
catch (_) {
return false;
}
return Version.ANCHORED_VERSION_PATTERN.test(versionStr);
};
// ##
// # Factory method to create a Version object. Input may be a Version
// # or a String. Intended to simplify client code.
// #
// # ver1 = Version.create('1.3.17') # -> (Version object)
// # ver2 = Version.create(ver1) # -> (ver1)
// # ver3 = Version.create(nil) # -> nil
//
// def self.create(input)
// if self === input # check yourself before you wreck yourself
// input
// elsif input.nil?
// nil
// else
// new input
// end
// end
Version.create = function (input) {
if (input instanceof Version)
return input;
if (input === null)
return null;
try {
return new Version(input);
}
catch (_a) {
return null;
}
};
// ##
// # Return a new version object where the next to the last revision
// # number is one greater (e.g., 5.3.1 => 5.4).
// #
// # Pre-release (alpha) parts, e.g, 5.3.1.b.2 => 5.4, are ignored.
//
// def bump
// @bump ||= begin
// segments = self.segments
// segments.pop while segments.any? { |s| String === s }
// segments.pop if segments.size > 1
//
// segments[-1] = segments[-1].succ
// self.class.new segments.join(".")
// end
// end
Version.prototype.bump = function () {
var segments = this.getSegments();
while (segments.findIndex(function (x) { return typeof x === 'string'; }) !== -1)
segments.pop();
var lastIdx = segments.length - 2;
if (lastIdx >= 0) {
segments.pop();
}
else {
lastIdx = 0;
}
segments[lastIdx] = segments[lastIdx] + 1;
return new Version(segments.join('.'));
};
// ##
// # A Version is only eql? to another version if it's specified to the
// # same precision. Version "1.0" is not the same as version "1".
//
// def eql?(other)
// self.class === other and @version == other._version
// end
Version.prototype.strictEql = function (other) {
return other.version() === this._version;
};
//
// def hash # :nodoc:
// canonical_segments.hash
// end
//
// def init_with(coder) # :nodoc:
// yaml_initialize coder.tag, coder.map
// end
//
// def inspect # :nodoc:
// "#<#{self.class} #{version.inspect}>"
// end
//
// ##
// # Dump only the raw version string, not the complete object. It's a
// # string for backwards (RubyGems 1.3.5 and earlier) compatibility.
//
// def marshal_dump
// [version]
// end
//
// ##
// # Load custom marshal format. It's a string for backwards (RubyGems
// # 1.3.5 and earlier) compatibility.
//
// def marshal_load(array)
// initialize array[0]
// end
//
// def yaml_initialize(tag, map) # :nodoc:
// @version = map['version']
// @segments = nil
// @hash = nil
// end
//
// def to_yaml_properties # :nodoc:
// ["@version"]
// end
//
// def encode_with(coder) # :nodoc:
// coder.add 'version', @version
// end
//
// ##
// # A version is considered a prerelease if it contains a letter.
//
// def prerelease?
// unless instance_variable_defined? :@prerelease
// @prerelease = !!(@version =~ /[a-zA-Z]/)
// end
// @prerelease
// end
Version.prototype.isPrerelease = function () {
return /[a-zA-Z]/.test(this._version);
};
// def pretty_print(q) # :nodoc:
// q.text "Gem::Version.new(#{version.inspect})"
// end
//
// ##
// # The release for this version (e.g. 1.2.0.a -> 1.2.0).
// # Non-prerelease versions return themselves.
// def release
// @release ||= if prerelease?
// segments = self.segments
// segments.pop while segments.any? { |s| String === s }
// self.class.new segments.join('.')
// else
// self
// end
// end
Version.prototype.release = function () {
if (this.isPrerelease()) {
var segments = this.getSegments();
while (segments.findIndex(function (x) { return typeof x === 'string'; }) !== -1)
segments.pop();
return new Version(segments.join('.'));
}
return this;
};
// def segments # :nodoc:
// _segments.dup
// end
//
// ##
// # A recommended version for use with a ~> Requirement.
//
// def approximate_recommendation
// segments = self.segments
//
// segments.pop while segments.any? { |s| String === s }
// segments.pop while segments.size > 2
// segments.push 0 while segments.size < 2
//
// recommendation = "~> #{segments.join(".")}"
// recommendation += ".a" if prerelease?
// recommendation
// end
Version.prototype.approximateRecommendation = function () {
var segments = this.getSegments();
while (segments.findIndex(function (x) { return typeof x === 'string'; }) !== -1)
segments.pop();
while (segments.length > 2)
segments.pop();
while (segments.length < 2)
segments.push(0);
var recommendation = "~> " + segments.join('.');
if (this.isPrerelease())
recommendation += '.a';
return recommendation;
};
// ##
// # Compares this version with +other+ returning -1, 0, or 1 if the
// # other version is larger, the same, or smaller than this
// # one. Attempts to compare to something that's not a
// # <tt>Gem::Version</tt> return +nil+.
//
// def <=>(other)
// return unless Gem::Version === other
// return 0 if @version == other._version || canonical_segments == other.canonical_segments
//
// lhsegments = canonical_segments
// rhsegments = other.canonical_segments
//
// lhsize = lhsegments.size
// rhsize = rhsegments.size
// limit = (lhsize > rhsize ? lhsize : rhsize) - 1
//
// i = 0
//
// while i <= limit
// lhs, rhs = lhsegments[i] || 0, rhsegments[i] || 0
// i += 1
//
// next if lhs == rhs
// return -1 if String === lhs && Numeric === rhs
// return 1 if Numeric === lhs && String === rhs
//
// return lhs <=> rhs
// end
//
// return 0
// end
Version.prototype.compare = function (other) {
if (other === null)
return null;
var segEq = function (x, y) {
if (x.length !== y.length)
return false;
for (var idx = 0; idx < x.length; idx += 1) {
if (x[idx] !== y[idx])
return false;
}
return true;
};
if (this._version === other._version ||
segEq(this.canonicalSegments(), other.canonicalSegments())) {
return 0;
}
var lhsegments = this.canonicalSegments();
var rhsegments = other.canonicalSegments();
var lhsize = lhsegments.length;
var rhsize = rhsegments.length;
var limit = (lhsize > rhsize ? lhsize : rhsize) - 1;
var i = 0;
while (i <= limit) {
var lhs = lhsegments[i] || 0;
var rhs = rhsegments[i] || 0;
i += 1;
// eslint-disable-next-line no-continue
if (lhs === rhs)
continue;
var isLeftStr = typeof lhs === 'string';
var isRightStr = typeof rhs === 'string';
if (isLeftStr && !isRightStr)
return -1;
if (!isLeftStr && isRightStr)
return 1;
lhs = lhs.toString();
rhs = rhs.toString();
return lhs.localeCompare(rhs, undefined, { numeric: true });
}
/* istanbul ignore next */
return 0;
};
// def canonical_segments
// @canonical_segments ||=
// _split_segments.map! do |segments|
// segments.reverse_each.drop_while {|s| s == 0 }.reverse
// end.reduce(&:concat)
// end
Version.prototype.canonicalSegments = function () {
var canonicals = this.splitSegments().map(function (segments) {
var segmentsReverse = segments.reverse();
var sliceIdx = segmentsReverse.findIndex(function (s) { return s !== 0; });
return segmentsReverse.slice(sliceIdx).reverse();
});
return Array.prototype.concat.apply([], canonicals);
};
//
// protected
//
// def _version
// @version
// end
// def _segments
// # segments is lazy so it can pick up version values that come from
// # old marshaled versions, which don't go through marshal_load.
// # since this version object is cached in @@all, its @segments should be frozen
//
// @segments ||= @version.scan(/[0-9]+|[a-z]+/i).map do |s|
// /^\d+$/ =~ s ? s.to_i : s
// end.freeze
// end
Version.prototype.getSegments = function () {
if (!this._segments) {
this._segments = this._version
.match(/[0-9]+|[a-z]+/gi)
.map(function (s) { return (/^\d+$/.test(s) ? parseInt(s, 10) : s); });
}
return this._segments.slice();
};
// def _split_segments
// string_start = _segments.index {|s| s.is_a?(String) }
// string_segments = segments
// numeric_segments = string_segments.slice!(0, string_start || string_segments.size)
// return numeric_segments, string_segments
// end
Version.prototype.splitSegments = function () {
var stringStart = this.getSegments().findIndex(function (x) { return typeof x === 'string'; });
stringStart = stringStart === -1 ? null : stringStart;
var stringSegments = this.getSegments();
var numericSegments = stringSegments.splice(0, stringStart || stringSegments.length);
return [numericSegments, stringSegments];
};
// VERSION_PATTERN = '[0-9]+(?>\.[0-9a-zA-Z]+)*(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?'.freeze # :nodoc:
// ANCHORED_VERSION_PATTERN = /\A\s*(#{VERSION_PATTERN})?\s*\z/.freeze # :nodoc:
Version.ANCHORED_VERSION_PATTERN = /^\s*([0-9]+(\.[0-9a-zA-Z]+)*(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?)?\s*$/;
return Version;
}()); // end
exports.Version = Version;
exports.create = Version.create;
{
"name": "@renovatebot/ruby-semver",
"version": "0.1.0",
"version": "0.1.1",
"license": "MIT",

@@ -5,0 +5,0 @@ "description": "Ruby SemVer in TypeScript.",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc