Coverage

100%
50
50
0

/Users/tdeekens/Development/GitHub/grunt-voguesy/tasks/semver/index.js

100%
50
50
0
LineHitsSource
11'use strict';
2
31var _ = require('lodash');
4
51function Semver(tolerance) {
619 this._tolerance = tolerance;
7}
8
91Semver.prototype.setComparison = function(base, comparator) {
1023 this._base = this.parse(base);
1123 this._comparator = this.parse(comparator);
12
1323 return this;
14};
15
161Semver.prototype.allMajor = function(status, comparator) {
172 var _comparator = comparator || 'latest';
18
192 var passing = _.all(status, function(version, packageName) {
203 this.setComparison(version.current, version.latest);
21
223 return this.major().ahead(this._tolerance.major);
23 }, this);
24
252 return passing;
26};
27
281Semver.prototype.allMinor = function(status, comparator) {
292 var _comparator = comparator || 'latest';
30
312 var passing = _.all(status, function(version, packageName) {
323 this.setComparison(version.current, version.latest);
33
343 return this.minor().ahead(this._tolerance.minor);
35 }, this);
36
372 return passing;
38};
39
401Semver.prototype.allPatch = function(status, comparator) {
412 var _comparator = comparator || 'latest';
42
432 var passing = _.all(status, function(version, packageName) {
443 this.setComparison(version.current, version.latest);
45
463 return this.patch().ahead(this._tolerance.patch);
47 }, this);
48
492 return passing;
50};
51
521Semver.prototype.generate = function(part) {
5327 var api = {
54 get: function() {
553 return this._base[part];
56 },
57 is: function(minor) {
583 return minor === this._base[part];
59 },
60 behind: function(range) {
616 var _tolerance = this._comparator[part] - range;
62
636 return this._base[part] >= _tolerance;
64 },
65 ahead: function(range) {
6615 var _tolerance = this._base[part] + range;
67
6815 return _tolerance >= this._comparator[part];
69 }
70 };
71
7227 return {
73 get: api.get.bind(this),
74 is: api.is.bind(this),
75 behind: api.behind.bind(this),
76 ahead: api.ahead.bind(this)
77 };
78};
79
801Semver.prototype.parse = function(version) {
8148 if (typeof version !== 'string') { return false; }
82
8344 var _split = version.split('.'),
84 _parsed;
85
8647 if (_split.length !== 3) { return false; }
87
8841 _parsed = {
89 major: parseInt(_split[0]),
90 minor: parseInt(_split[1]),
91 patch: parseInt(_split[2])
92 };
93
9441 return (
95 isNaN(_parsed.major) ||
96 isNaN(_parsed.minor) ||
97 isNaN(_parsed.patch)
98 ) ? false : _parsed;
99};
100
1011Semver.prototype.valid = function() {
1024 return (
103 this._base !== false &&
104 this._comparator !== false
105 );
106};
107
1081Semver.prototype.major = function() {
1099 return this.generate('major');
110};
111
1121Semver.prototype.minor = function() {
1139 return this.generate('minor');
114};
115
1161Semver.prototype.patch = function() {
1179 return this.generate('patch');
118};
119
1201module.exports = Semver;
121