angular-semver-sort-rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 102e45589ba5b2af0fbe55909842794bf3de9b73
4
+ data.tar.gz: dfcb817ed59e86691e78b08d0cfa6b834431515c
5
+ SHA512:
6
+ metadata.gz: 0104604ea7bedccb9dffbfe7c76764d2d87d0c6a1c075501c61fee9fbf6a476e10b7700dea731b730020401e671782cb17917fe0154223076e21b7228a995b26
7
+ data.tar.gz: 6e36f4ea8b23a7e0158428045958f81f09b4cf7975496dcce19fc99771b17679fb02e2be48e4e1a9a7978a1dae999c002809f6197fb51cd6cdd6dcbe3d9811cd
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ # We don’t use rails-assets.org gems within the Rails Assets app.
7
+ # This is the only reason why this asset gem was created.
8
+
9
+ spec.name = 'angular-semver-sort-rails'
10
+ spec.version = '0.1.0'
11
+ spec.authors = ['Dominik Porada']
12
+ spec.email = ['dominik@porada.co']
13
+ spec.summary = 'angular-semver-sort packaged for Rails assets pipeline'
14
+ spec.homepage = 'https://github.com/monterail/angular-semver-sort'
15
+ spec.license = 'BSD'
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.require_paths = ['lib']
18
+
19
+ spec.add_development_dependency 'bundler', '~> 1.5'
20
+ spec.add_development_dependency 'rake'
21
+ end
@@ -0,0 +1,5 @@
1
+ module AngularSemverSortRails
2
+ if defined?(Rails)
3
+ class Engine < ::Rails::Engine; end
4
+ end
5
+ end
@@ -0,0 +1,1060 @@
1
+ /*!
2
+ angular-semver-sort v0.0.0 <http://git.io/angular-semver>
3
+ @includes <http://git.io/semver> by Isaac Z. Schlueter
4
+ @license BSD
5
+ */
6
+ ;(function(exports) {
7
+
8
+ // export the class if we are in a Node-like system.
9
+ if (typeof module === 'object' && module.exports === exports)
10
+ exports = module.exports = SemVer;
11
+
12
+ // The debug function is excluded entirely from the minified version.
13
+
14
+ // Note: this is the semver.org version of the spec that it implements
15
+ // Not necessarily the package version of this code.
16
+ exports.SEMVER_SPEC_VERSION = '2.0.0';
17
+
18
+ // The actual regexps go on exports.re
19
+ var re = exports.re = [];
20
+ var src = exports.src = [];
21
+ var R = 0;
22
+
23
+ // The following Regular Expressions can be used for tokenizing,
24
+ // validating, and parsing SemVer version strings.
25
+
26
+ // ## Numeric Identifier
27
+ // A single `0`, or a non-zero digit followed by zero or more digits.
28
+
29
+ var NUMERICIDENTIFIER = R++;
30
+ src[NUMERICIDENTIFIER] = '0|[1-9]\\d*';
31
+ var NUMERICIDENTIFIERLOOSE = R++;
32
+ src[NUMERICIDENTIFIERLOOSE] = '[0-9]+';
33
+
34
+
35
+ // ## Non-numeric Identifier
36
+ // Zero or more digits, followed by a letter or hyphen, and then zero or
37
+ // more letters, digits, or hyphens.
38
+
39
+ var NONNUMERICIDENTIFIER = R++;
40
+ src[NONNUMERICIDENTIFIER] = '\\d*[a-zA-Z-][a-zA-Z0-9-]*';
41
+
42
+
43
+ // ## Main Version
44
+ // Three dot-separated numeric identifiers.
45
+
46
+ var MAINVERSION = R++;
47
+ src[MAINVERSION] = '(' + src[NUMERICIDENTIFIER] + ')\\.' +
48
+ '(' + src[NUMERICIDENTIFIER] + ')\\.' +
49
+ '(' + src[NUMERICIDENTIFIER] + ')';
50
+
51
+ var MAINVERSIONLOOSE = R++;
52
+ src[MAINVERSIONLOOSE] = '(' + src[NUMERICIDENTIFIERLOOSE] + ')\\.' +
53
+ '(' + src[NUMERICIDENTIFIERLOOSE] + ')\\.' +
54
+ '(' + src[NUMERICIDENTIFIERLOOSE] + ')';
55
+
56
+ // ## Pre-release Version Identifier
57
+ // A numeric identifier, or a non-numeric identifier.
58
+
59
+ var PRERELEASEIDENTIFIER = R++;
60
+ src[PRERELEASEIDENTIFIER] = '(?:' + src[NUMERICIDENTIFIER] +
61
+ '|' + src[NONNUMERICIDENTIFIER] + ')';
62
+
63
+ var PRERELEASEIDENTIFIERLOOSE = R++;
64
+ src[PRERELEASEIDENTIFIERLOOSE] = '(?:' + src[NUMERICIDENTIFIERLOOSE] +
65
+ '|' + src[NONNUMERICIDENTIFIER] + ')';
66
+
67
+
68
+ // ## Pre-release Version
69
+ // Hyphen, followed by one or more dot-separated pre-release version
70
+ // identifiers.
71
+
72
+ var PRERELEASE = R++;
73
+ src[PRERELEASE] = '(?:-(' + src[PRERELEASEIDENTIFIER] +
74
+ '(?:\\.' + src[PRERELEASEIDENTIFIER] + ')*))';
75
+
76
+ var PRERELEASELOOSE = R++;
77
+ src[PRERELEASELOOSE] = '(?:-?(' + src[PRERELEASEIDENTIFIERLOOSE] +
78
+ '(?:\\.' + src[PRERELEASEIDENTIFIERLOOSE] + ')*))';
79
+
80
+ // ## Build Metadata Identifier
81
+ // Any combination of digits, letters, or hyphens.
82
+
83
+ var BUILDIDENTIFIER = R++;
84
+ src[BUILDIDENTIFIER] = '[0-9A-Za-z-]+';
85
+
86
+ // ## Build Metadata
87
+ // Plus sign, followed by one or more period-separated build metadata
88
+ // identifiers.
89
+
90
+ var BUILD = R++;
91
+ src[BUILD] = '(?:\\+(' + src[BUILDIDENTIFIER] +
92
+ '(?:\\.' + src[BUILDIDENTIFIER] + ')*))';
93
+
94
+
95
+ // ## Full Version String
96
+ // A main version, followed optionally by a pre-release version and
97
+ // build metadata.
98
+
99
+ // Note that the only major, minor, patch, and pre-release sections of
100
+ // the version string are capturing groups. The build metadata is not a
101
+ // capturing group, because it should not ever be used in version
102
+ // comparison.
103
+
104
+ var FULL = R++;
105
+ var FULLPLAIN = 'v?' + src[MAINVERSION] +
106
+ src[PRERELEASE] + '?' +
107
+ src[BUILD] + '?';
108
+
109
+ src[FULL] = '^' + FULLPLAIN + '$';
110
+
111
+ // like full, but allows v1.2.3 and =1.2.3, which people do sometimes.
112
+ // also, 1.0.0alpha1 (prerelease without the hyphen) which is pretty
113
+ // common in the npm registry.
114
+ var LOOSEPLAIN = '[v=\\s]*' + src[MAINVERSIONLOOSE] +
115
+ src[PRERELEASELOOSE] + '?' +
116
+ src[BUILD] + '?';
117
+
118
+ var LOOSE = R++;
119
+ src[LOOSE] = '^' + LOOSEPLAIN + '$';
120
+
121
+ var GTLT = R++;
122
+ src[GTLT] = '((?:<|>)?=?)';
123
+
124
+ // Something like "2.*" or "1.2.x".
125
+ // Note that "x.x" is a valid xRange identifer, meaning "any version"
126
+ // Only the first item is strictly required.
127
+ var XRANGEIDENTIFIERLOOSE = R++;
128
+ src[XRANGEIDENTIFIERLOOSE] = src[NUMERICIDENTIFIERLOOSE] + '|x|X|\\*';
129
+ var XRANGEIDENTIFIER = R++;
130
+ src[XRANGEIDENTIFIER] = src[NUMERICIDENTIFIER] + '|x|X|\\*';
131
+
132
+ var XRANGEPLAIN = R++;
133
+ src[XRANGEPLAIN] = '[v=\\s]*(' + src[XRANGEIDENTIFIER] + ')' +
134
+ '(?:\\.(' + src[XRANGEIDENTIFIER] + ')' +
135
+ '(?:\\.(' + src[XRANGEIDENTIFIER] + ')' +
136
+ '(?:(' + src[PRERELEASE] + ')' +
137
+ ')?)?)?';
138
+
139
+ var XRANGEPLAINLOOSE = R++;
140
+ src[XRANGEPLAINLOOSE] = '[v=\\s]*(' + src[XRANGEIDENTIFIERLOOSE] + ')' +
141
+ '(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' +
142
+ '(?:\\.(' + src[XRANGEIDENTIFIERLOOSE] + ')' +
143
+ '(?:(' + src[PRERELEASELOOSE] + ')' +
144
+ ')?)?)?';
145
+
146
+ // >=2.x, for example, means >=2.0.0-0
147
+ // <1.x would be the same as "<1.0.0-0", though.
148
+ var XRANGE = R++;
149
+ src[XRANGE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAIN] + '$';
150
+ var XRANGELOOSE = R++;
151
+ src[XRANGELOOSE] = '^' + src[GTLT] + '\\s*' + src[XRANGEPLAINLOOSE] + '$';
152
+
153
+ // Tilde ranges.
154
+ // Meaning is "reasonably at or greater than"
155
+ var LONETILDE = R++;
156
+ src[LONETILDE] = '(?:~>?)';
157
+
158
+ var TILDETRIM = R++;
159
+ src[TILDETRIM] = '(\\s*)' + src[LONETILDE] + '\\s+';
160
+ re[TILDETRIM] = new RegExp(src[TILDETRIM], 'g');
161
+ var tildeTrimReplace = '$1~';
162
+
163
+ var TILDE = R++;
164
+ src[TILDE] = '^' + src[LONETILDE] + src[XRANGEPLAIN] + '$';
165
+ var TILDELOOSE = R++;
166
+ src[TILDELOOSE] = '^' + src[LONETILDE] + src[XRANGEPLAINLOOSE] + '$';
167
+
168
+ // Caret ranges.
169
+ // Meaning is "at least and backwards compatible with"
170
+ var LONECARET = R++;
171
+ src[LONECARET] = '(?:\\^)';
172
+
173
+ var CARETTRIM = R++;
174
+ src[CARETTRIM] = '(\\s*)' + src[LONECARET] + '\\s+';
175
+ re[CARETTRIM] = new RegExp(src[CARETTRIM], 'g');
176
+ var caretTrimReplace = '$1^';
177
+
178
+ var CARET = R++;
179
+ src[CARET] = '^' + src[LONECARET] + src[XRANGEPLAIN] + '$';
180
+ var CARETLOOSE = R++;
181
+ src[CARETLOOSE] = '^' + src[LONECARET] + src[XRANGEPLAINLOOSE] + '$';
182
+
183
+ // A simple gt/lt/eq thing, or just "" to indicate "any version"
184
+ var COMPARATORLOOSE = R++;
185
+ src[COMPARATORLOOSE] = '^' + src[GTLT] + '\\s*(' + LOOSEPLAIN + ')$|^$';
186
+ var COMPARATOR = R++;
187
+ src[COMPARATOR] = '^' + src[GTLT] + '\\s*(' + FULLPLAIN + ')$|^$';
188
+
189
+
190
+ // An expression to strip any whitespace between the gtlt and the thing
191
+ // it modifies, so that `> 1.2.3` ==> `>1.2.3`
192
+ var COMPARATORTRIM = R++;
193
+ src[COMPARATORTRIM] = '(\\s*)' + src[GTLT] +
194
+ '\\s*(' + LOOSEPLAIN + '|' + src[XRANGEPLAIN] + ')';
195
+
196
+ // this one has to use the /g flag
197
+ re[COMPARATORTRIM] = new RegExp(src[COMPARATORTRIM], 'g');
198
+ var comparatorTrimReplace = '$1$2$3';
199
+
200
+
201
+ // Something like `1.2.3 - 1.2.4`
202
+ // Note that these all use the loose form, because they'll be
203
+ // checked against either the strict or loose comparator form
204
+ // later.
205
+ var HYPHENRANGE = R++;
206
+ src[HYPHENRANGE] = '^\\s*(' + src[XRANGEPLAIN] + ')' +
207
+ '\\s+-\\s+' +
208
+ '(' + src[XRANGEPLAIN] + ')' +
209
+ '\\s*$';
210
+
211
+ var HYPHENRANGELOOSE = R++;
212
+ src[HYPHENRANGELOOSE] = '^\\s*(' + src[XRANGEPLAINLOOSE] + ')' +
213
+ '\\s+-\\s+' +
214
+ '(' + src[XRANGEPLAINLOOSE] + ')' +
215
+ '\\s*$';
216
+
217
+ // Star ranges basically just allow anything at all.
218
+ var STAR = R++;
219
+ src[STAR] = '(<|>)?=?\\s*\\*';
220
+
221
+ // Compile to actual regexp objects.
222
+ // All are flag-free, unless they were created above with a flag.
223
+ for (var i = 0; i < R; i++) {
224
+ ;
225
+ if (!re[i])
226
+ re[i] = new RegExp(src[i]);
227
+ }
228
+
229
+ exports.parse = parse;
230
+ function parse(version, loose) {
231
+ var r = loose ? re[LOOSE] : re[FULL];
232
+ return (r.test(version)) ? new SemVer(version, loose) : null;
233
+ }
234
+
235
+ exports.valid = valid;
236
+ function valid(version, loose) {
237
+ var v = parse(version, loose);
238
+ return v ? v.version : null;
239
+ }
240
+
241
+
242
+ exports.clean = clean;
243
+ function clean(version, loose) {
244
+ var s = parse(version, loose);
245
+ return s ? s.version : null;
246
+ }
247
+
248
+ exports.SemVer = SemVer;
249
+
250
+ function SemVer(version, loose) {
251
+ if (version instanceof SemVer) {
252
+ if (version.loose === loose)
253
+ return version;
254
+ else
255
+ version = version.version;
256
+ }
257
+
258
+ if (!(this instanceof SemVer))
259
+ return new SemVer(version, loose);
260
+
261
+ ;
262
+ this.loose = loose;
263
+ var m = version.trim().match(loose ? re[LOOSE] : re[FULL]);
264
+
265
+ if (!m)
266
+ throw new TypeError('Invalid Version: ' + version);
267
+
268
+ this.raw = version;
269
+
270
+ // these are actually numbers
271
+ this.major = +m[1];
272
+ this.minor = +m[2];
273
+ this.patch = +m[3];
274
+
275
+ // numberify any prerelease numeric ids
276
+ if (!m[4])
277
+ this.prerelease = [];
278
+ else
279
+ this.prerelease = m[4].split('.').map(function(id) {
280
+ return (/^[0-9]+$/.test(id)) ? +id : id;
281
+ });
282
+
283
+ this.build = m[5] ? m[5].split('.') : [];
284
+ this.format();
285
+ }
286
+
287
+ SemVer.prototype.format = function() {
288
+ this.version = this.major + '.' + this.minor + '.' + this.patch;
289
+ if (this.prerelease.length)
290
+ this.version += '-' + this.prerelease.join('.');
291
+ return this.version;
292
+ };
293
+
294
+ SemVer.prototype.inspect = function() {
295
+ return '<SemVer "' + this + '">';
296
+ };
297
+
298
+ SemVer.prototype.toString = function() {
299
+ return this.version;
300
+ };
301
+
302
+ SemVer.prototype.compare = function(other) {
303
+ ;
304
+ if (!(other instanceof SemVer))
305
+ other = new SemVer(other, this.loose);
306
+
307
+ return this.compareMain(other) || this.comparePre(other);
308
+ };
309
+
310
+ SemVer.prototype.compareMain = function(other) {
311
+ if (!(other instanceof SemVer))
312
+ other = new SemVer(other, this.loose);
313
+
314
+ return compareIdentifiers(this.major, other.major) ||
315
+ compareIdentifiers(this.minor, other.minor) ||
316
+ compareIdentifiers(this.patch, other.patch);
317
+ };
318
+
319
+ SemVer.prototype.comparePre = function(other) {
320
+ if (!(other instanceof SemVer))
321
+ other = new SemVer(other, this.loose);
322
+
323
+ // NOT having a prerelease is > having one
324
+ if (this.prerelease.length && !other.prerelease.length)
325
+ return -1;
326
+ else if (!this.prerelease.length && other.prerelease.length)
327
+ return 1;
328
+ else if (!this.prerelease.lenth && !other.prerelease.length)
329
+ return 0;
330
+
331
+ var i = 0;
332
+ do {
333
+ var a = this.prerelease[i];
334
+ var b = other.prerelease[i];
335
+ ;
336
+ if (a === undefined && b === undefined)
337
+ return 0;
338
+ else if (b === undefined)
339
+ return 1;
340
+ else if (a === undefined)
341
+ return -1;
342
+ else if (a === b)
343
+ continue;
344
+ else
345
+ return compareIdentifiers(a, b);
346
+ } while (++i);
347
+ };
348
+
349
+ SemVer.prototype.inc = function(release) {
350
+ switch (release) {
351
+ case 'major':
352
+ this.major++;
353
+ this.minor = -1;
354
+ case 'minor':
355
+ this.minor++;
356
+ this.patch = -1;
357
+ case 'patch':
358
+ this.patch++;
359
+ this.prerelease = [];
360
+ break;
361
+ case 'prerelease':
362
+ if (this.prerelease.length === 0)
363
+ this.prerelease = [0];
364
+ else {
365
+ var i = this.prerelease.length;
366
+ while (--i >= 0) {
367
+ if (typeof this.prerelease[i] === 'number') {
368
+ this.prerelease[i]++;
369
+ i = -2;
370
+ }
371
+ }
372
+ if (i === -1) // didn't increment anything
373
+ this.prerelease.push(0);
374
+ }
375
+ break;
376
+
377
+ default:
378
+ throw new Error('invalid increment argument: ' + release);
379
+ }
380
+ this.format();
381
+ return this;
382
+ };
383
+
384
+ exports.inc = inc;
385
+ function inc(version, release, loose) {
386
+ try {
387
+ return new SemVer(version, loose).inc(release).version;
388
+ } catch (er) {
389
+ return null;
390
+ }
391
+ }
392
+
393
+ exports.compareIdentifiers = compareIdentifiers;
394
+
395
+ var numeric = /^[0-9]+$/;
396
+ function compareIdentifiers(a, b) {
397
+ var anum = numeric.test(a);
398
+ var bnum = numeric.test(b);
399
+
400
+ if (anum && bnum) {
401
+ a = +a;
402
+ b = +b;
403
+ }
404
+
405
+ return (anum && !bnum) ? -1 :
406
+ (bnum && !anum) ? 1 :
407
+ a < b ? -1 :
408
+ a > b ? 1 :
409
+ 0;
410
+ }
411
+
412
+ exports.rcompareIdentifiers = rcompareIdentifiers;
413
+ function rcompareIdentifiers(a, b) {
414
+ return compareIdentifiers(b, a);
415
+ }
416
+
417
+ exports.compare = compare;
418
+ function compare(a, b, loose) {
419
+ return new SemVer(a, loose).compare(b);
420
+ }
421
+
422
+ exports.compareLoose = compareLoose;
423
+ function compareLoose(a, b) {
424
+ return compare(a, b, true);
425
+ }
426
+
427
+ exports.rcompare = rcompare;
428
+ function rcompare(a, b, loose) {
429
+ return compare(b, a, loose);
430
+ }
431
+
432
+ exports.sort = sort;
433
+ function sort(list, loose) {
434
+ return list.sort(function(a, b) {
435
+ return exports.compare(a, b, loose);
436
+ });
437
+ }
438
+
439
+ exports.rsort = rsort;
440
+ function rsort(list, loose) {
441
+ return list.sort(function(a, b) {
442
+ return exports.rcompare(a, b, loose);
443
+ });
444
+ }
445
+
446
+ exports.gt = gt;
447
+ function gt(a, b, loose) {
448
+ return compare(a, b, loose) > 0;
449
+ }
450
+
451
+ exports.lt = lt;
452
+ function lt(a, b, loose) {
453
+ return compare(a, b, loose) < 0;
454
+ }
455
+
456
+ exports.eq = eq;
457
+ function eq(a, b, loose) {
458
+ return compare(a, b, loose) === 0;
459
+ }
460
+
461
+ exports.neq = neq;
462
+ function neq(a, b, loose) {
463
+ return compare(a, b, loose) !== 0;
464
+ }
465
+
466
+ exports.gte = gte;
467
+ function gte(a, b, loose) {
468
+ return compare(a, b, loose) >= 0;
469
+ }
470
+
471
+ exports.lte = lte;
472
+ function lte(a, b, loose) {
473
+ return compare(a, b, loose) <= 0;
474
+ }
475
+
476
+ exports.cmp = cmp;
477
+ function cmp(a, op, b, loose) {
478
+ var ret;
479
+ switch (op) {
480
+ case '===': ret = a === b; break;
481
+ case '!==': ret = a !== b; break;
482
+ case '': case '=': case '==': ret = eq(a, b, loose); break;
483
+ case '!=': ret = neq(a, b, loose); break;
484
+ case '>': ret = gt(a, b, loose); break;
485
+ case '>=': ret = gte(a, b, loose); break;
486
+ case '<': ret = lt(a, b, loose); break;
487
+ case '<=': ret = lte(a, b, loose); break;
488
+ default: throw new TypeError('Invalid operator: ' + op);
489
+ }
490
+ return ret;
491
+ }
492
+
493
+ exports.Comparator = Comparator;
494
+ function Comparator(comp, loose) {
495
+ if (comp instanceof Comparator) {
496
+ if (comp.loose === loose)
497
+ return comp;
498
+ else
499
+ comp = comp.value;
500
+ }
501
+
502
+ if (!(this instanceof Comparator))
503
+ return new Comparator(comp, loose);
504
+
505
+ ;
506
+ this.loose = loose;
507
+ this.parse(comp);
508
+
509
+ if (this.semver === ANY)
510
+ this.value = '';
511
+ else
512
+ this.value = this.operator + this.semver.version;
513
+ }
514
+
515
+ var ANY = {};
516
+ Comparator.prototype.parse = function(comp) {
517
+ var r = this.loose ? re[COMPARATORLOOSE] : re[COMPARATOR];
518
+ var m = comp.match(r);
519
+
520
+ if (!m)
521
+ throw new TypeError('Invalid comparator: ' + comp);
522
+
523
+ this.operator = m[1];
524
+ // if it literally is just '>' or '' then allow anything.
525
+ if (!m[2])
526
+ this.semver = ANY;
527
+ else {
528
+ this.semver = new SemVer(m[2], this.loose);
529
+
530
+ // <1.2.3-rc DOES allow 1.2.3-beta (has prerelease)
531
+ // >=1.2.3 DOES NOT allow 1.2.3-beta
532
+ // <=1.2.3 DOES allow 1.2.3-beta
533
+ // However, <1.2.3 does NOT allow 1.2.3-beta,
534
+ // even though `1.2.3-beta < 1.2.3`
535
+ // The assumption is that the 1.2.3 version has something you
536
+ // *don't* want, so we push the prerelease down to the minimum.
537
+ if (this.operator === '<' && !this.semver.prerelease.length) {
538
+ this.semver.prerelease = ['0'];
539
+ this.semver.format();
540
+ }
541
+ }
542
+ };
543
+
544
+ Comparator.prototype.inspect = function() {
545
+ return '<SemVer Comparator "' + this + '">';
546
+ };
547
+
548
+ Comparator.prototype.toString = function() {
549
+ return this.value;
550
+ };
551
+
552
+ Comparator.prototype.test = function(version) {
553
+ ;
554
+ return (this.semver === ANY) ? true :
555
+ cmp(version, this.operator, this.semver, this.loose);
556
+ };
557
+
558
+
559
+ exports.Range = Range;
560
+ function Range(range, loose) {
561
+ if ((range instanceof Range) && range.loose === loose)
562
+ return range;
563
+
564
+ if (!(this instanceof Range))
565
+ return new Range(range, loose);
566
+
567
+ this.loose = loose;
568
+
569
+ // First, split based on boolean or ||
570
+ this.raw = range;
571
+ this.set = range.split(/\s*\|\|\s*/).map(function(range) {
572
+ return this.parseRange(range.trim());
573
+ }, this).filter(function(c) {
574
+ // throw out any that are not relevant for whatever reason
575
+ return c.length;
576
+ });
577
+
578
+ if (!this.set.length) {
579
+ throw new TypeError('Invalid SemVer Range: ' + range);
580
+ }
581
+
582
+ this.format();
583
+ }
584
+
585
+ Range.prototype.inspect = function() {
586
+ return '<SemVer Range "' + this.range + '">';
587
+ };
588
+
589
+ Range.prototype.format = function() {
590
+ this.range = this.set.map(function(comps) {
591
+ return comps.join(' ').trim();
592
+ }).join('||').trim();
593
+ return this.range;
594
+ };
595
+
596
+ Range.prototype.toString = function() {
597
+ return this.range;
598
+ };
599
+
600
+ Range.prototype.parseRange = function(range) {
601
+ var loose = this.loose;
602
+ range = range.trim();
603
+ ;
604
+ // `1.2.3 - 1.2.4` => `>=1.2.3 <=1.2.4`
605
+ var hr = loose ? re[HYPHENRANGELOOSE] : re[HYPHENRANGE];
606
+ range = range.replace(hr, hyphenReplace);
607
+ ;
608
+ // `> 1.2.3 < 1.2.5` => `>1.2.3 <1.2.5`
609
+ range = range.replace(re[COMPARATORTRIM], comparatorTrimReplace);
610
+ ;
611
+
612
+ // `~ 1.2.3` => `~1.2.3`
613
+ range = range.replace(re[TILDETRIM], tildeTrimReplace);
614
+
615
+ // `^ 1.2.3` => `^1.2.3`
616
+ range = range.replace(re[CARETTRIM], caretTrimReplace);
617
+
618
+ // normalize spaces
619
+ range = range.split(/\s+/).join(' ');
620
+
621
+ // At this point, the range is completely trimmed and
622
+ // ready to be split into comparators.
623
+
624
+ var compRe = loose ? re[COMPARATORLOOSE] : re[COMPARATOR];
625
+ var set = range.split(' ').map(function(comp) {
626
+ return parseComparator(comp, loose);
627
+ }).join(' ').split(/\s+/);
628
+ if (this.loose) {
629
+ // in loose mode, throw out any that are not valid comparators
630
+ set = set.filter(function(comp) {
631
+ return !!comp.match(compRe);
632
+ });
633
+ }
634
+ set = set.map(function(comp) {
635
+ return new Comparator(comp, loose);
636
+ });
637
+
638
+ return set;
639
+ };
640
+
641
+ // Mostly just for testing and legacy API reasons
642
+ exports.toComparators = toComparators;
643
+ function toComparators(range, loose) {
644
+ return new Range(range, loose).set.map(function(comp) {
645
+ return comp.map(function(c) {
646
+ return c.value;
647
+ }).join(' ').trim().split(' ');
648
+ });
649
+ }
650
+
651
+ // comprised of xranges, tildes, stars, and gtlt's at this point.
652
+ // already replaced the hyphen ranges
653
+ // turn into a set of JUST comparators.
654
+ function parseComparator(comp, loose) {
655
+ ;
656
+ comp = replaceCarets(comp, loose);
657
+ ;
658
+ comp = replaceTildes(comp, loose);
659
+ ;
660
+ comp = replaceXRanges(comp, loose);
661
+ ;
662
+ comp = replaceStars(comp, loose);
663
+ ;
664
+ return comp;
665
+ }
666
+
667
+ function isX(id) {
668
+ return !id || id.toLowerCase() === 'x' || id === '*';
669
+ }
670
+
671
+ // ~, ~> --> * (any, kinda silly)
672
+ // ~2, ~2.x, ~2.x.x, ~>2, ~>2.x ~>2.x.x --> >=2.0.0 <3.0.0
673
+ // ~2.0, ~2.0.x, ~>2.0, ~>2.0.x --> >=2.0.0 <2.1.0
674
+ // ~1.2, ~1.2.x, ~>1.2, ~>1.2.x --> >=1.2.0 <1.3.0
675
+ // ~1.2.3, ~>1.2.3 --> >=1.2.3 <1.3.0
676
+ // ~1.2.0, ~>1.2.0 --> >=1.2.0 <1.3.0
677
+ function replaceTildes(comp, loose) {
678
+ return comp.trim().split(/\s+/).map(function(comp) {
679
+ return replaceTilde(comp, loose);
680
+ }).join(' ');
681
+ }
682
+
683
+ function replaceTilde(comp, loose) {
684
+ var r = loose ? re[TILDELOOSE] : re[TILDE];
685
+ return comp.replace(r, function(_, M, m, p, pr) {
686
+ ;
687
+ var ret;
688
+
689
+ if (isX(M))
690
+ ret = '';
691
+ else if (isX(m))
692
+ ret = '>=' + M + '.0.0-0 <' + (+M + 1) + '.0.0-0';
693
+ else if (isX(p))
694
+ // ~1.2 == >=1.2.0- <1.3.0-
695
+ ret = '>=' + M + '.' + m + '.0-0 <' + M + '.' + (+m + 1) + '.0-0';
696
+ else if (pr) {
697
+ ;
698
+ if (pr.charAt(0) !== '-')
699
+ pr = '-' + pr;
700
+ ret = '>=' + M + '.' + m + '.' + p + pr +
701
+ ' <' + M + '.' + (+m + 1) + '.0-0';
702
+ } else
703
+ // ~1.2.3 == >=1.2.3-0 <1.3.0-0
704
+ ret = '>=' + M + '.' + m + '.' + p + '-0' +
705
+ ' <' + M + '.' + (+m + 1) + '.0-0';
706
+
707
+ ;
708
+ return ret;
709
+ });
710
+ }
711
+
712
+ // ^ --> * (any, kinda silly)
713
+ // ^2, ^2.x, ^2.x.x --> >=2.0.0 <3.0.0
714
+ // ^2.0, ^2.0.x --> >=2.0.0 <3.0.0
715
+ // ^1.2, ^1.2.x --> >=1.2.0 <2.0.0
716
+ // ^1.2.3 --> >=1.2.3 <2.0.0
717
+ // ^1.2.0 --> >=1.2.0 <2.0.0
718
+ function replaceCarets(comp, loose) {
719
+ return comp.trim().split(/\s+/).map(function(comp) {
720
+ return replaceCaret(comp, loose);
721
+ }).join(' ');
722
+ }
723
+
724
+ function replaceCaret(comp, loose) {
725
+ var r = loose ? re[CARETLOOSE] : re[CARET];
726
+ return comp.replace(r, function(_, M, m, p, pr) {
727
+ ;
728
+ var ret;
729
+
730
+ if (isX(M))
731
+ ret = '';
732
+ else if (isX(m))
733
+ ret = '>=' + M + '.0.0-0 <' + (+M + 1) + '.0.0-0';
734
+ else if (isX(p)) {
735
+ if (M === '0')
736
+ ret = '>=' + M + '.' + m + '.0-0 <' + M + '.' + (+m + 1) + '.0-0';
737
+ else
738
+ ret = '>=' + M + '.' + m + '.0-0 <' + (+M + 1) + '.0.0-0';
739
+ } else if (pr) {
740
+ ;
741
+ if (pr.charAt(0) !== '-')
742
+ pr = '-' + pr;
743
+ if (M === '0') {
744
+ if (m === '0')
745
+ ret = '=' + M + '.' + m + '.' + p + pr;
746
+ else
747
+ ret = '>=' + M + '.' + m + '.' + p + pr +
748
+ ' <' + M + '.' + (+m + 1) + '.0-0';
749
+ } else
750
+ ret = '>=' + M + '.' + m + '.' + p + pr +
751
+ ' <' + (+M + 1) + '.0.0-0';
752
+ } else {
753
+ if (M === '0') {
754
+ if (m === '0')
755
+ ret = '=' + M + '.' + m + '.' + p;
756
+ else
757
+ ret = '>=' + M + '.' + m + '.' + p + '-0' +
758
+ ' <' + M + '.' + (+m + 1) + '.0-0';
759
+ } else
760
+ ret = '>=' + M + '.' + m + '.' + p + '-0' +
761
+ ' <' + (+M + 1) + '.0.0-0';
762
+ }
763
+
764
+ ;
765
+ return ret;
766
+ });
767
+ }
768
+
769
+ function replaceXRanges(comp, loose) {
770
+ ;
771
+ return comp.split(/\s+/).map(function(comp) {
772
+ return replaceXRange(comp, loose);
773
+ }).join(' ');
774
+ }
775
+
776
+ function replaceXRange(comp, loose) {
777
+ comp = comp.trim();
778
+ var r = loose ? re[XRANGELOOSE] : re[XRANGE];
779
+ return comp.replace(r, function(ret, gtlt, M, m, p, pr) {
780
+ ;
781
+ var xM = isX(M);
782
+ var xm = xM || isX(m);
783
+ var xp = xm || isX(p);
784
+ var anyX = xp;
785
+
786
+ if (gtlt === '=' && anyX)
787
+ gtlt = '';
788
+
789
+ if (gtlt && anyX) {
790
+ // replace X with 0, and then append the -0 min-prerelease
791
+ if (xM)
792
+ M = 0;
793
+ if (xm)
794
+ m = 0;
795
+ if (xp)
796
+ p = 0;
797
+
798
+ if (gtlt === '>') {
799
+ // >1 => >=2.0.0-0
800
+ // >1.2 => >=1.3.0-0
801
+ // >1.2.3 => >= 1.2.4-0
802
+ gtlt = '>=';
803
+ if (xM) {
804
+ // no change
805
+ } else if (xm) {
806
+ M = +M + 1;
807
+ m = 0;
808
+ p = 0;
809
+ } else if (xp) {
810
+ m = +m + 1;
811
+ p = 0;
812
+ }
813
+ }
814
+
815
+
816
+ ret = gtlt + M + '.' + m + '.' + p + '-0';
817
+ } else if (xM) {
818
+ // allow any
819
+ ret = '*';
820
+ } else if (xm) {
821
+ // append '-0' onto the version, otherwise
822
+ // '1.x.x' matches '2.0.0-beta', since the tag
823
+ // *lowers* the version value
824
+ ret = '>=' + M + '.0.0-0 <' + (+M + 1) + '.0.0-0';
825
+ } else if (xp) {
826
+ ret = '>=' + M + '.' + m + '.0-0 <' + M + '.' + (+m + 1) + '.0-0';
827
+ }
828
+
829
+ ;
830
+
831
+ return ret;
832
+ });
833
+ }
834
+
835
+ // Because * is AND-ed with everything else in the comparator,
836
+ // and '' means "any version", just remove the *s entirely.
837
+ function replaceStars(comp, loose) {
838
+ ;
839
+ // Looseness is ignored here. star is always as loose as it gets!
840
+ return comp.trim().replace(re[STAR], '');
841
+ }
842
+
843
+ // This function is passed to string.replace(re[HYPHENRANGE])
844
+ // M, m, patch, prerelease, build
845
+ // 1.2 - 3.4.5 => >=1.2.0-0 <=3.4.5
846
+ // 1.2.3 - 3.4 => >=1.2.0-0 <3.5.0-0 Any 3.4.x will do
847
+ // 1.2 - 3.4 => >=1.2.0-0 <3.5.0-0
848
+ function hyphenReplace($0,
849
+ from, fM, fm, fp, fpr, fb,
850
+ to, tM, tm, tp, tpr, tb) {
851
+
852
+ if (isX(fM))
853
+ from = '';
854
+ else if (isX(fm))
855
+ from = '>=' + fM + '.0.0-0';
856
+ else if (isX(fp))
857
+ from = '>=' + fM + '.' + fm + '.0-0';
858
+ else
859
+ from = '>=' + from;
860
+
861
+ if (isX(tM))
862
+ to = '';
863
+ else if (isX(tm))
864
+ to = '<' + (+tM + 1) + '.0.0-0';
865
+ else if (isX(tp))
866
+ to = '<' + tM + '.' + (+tm + 1) + '.0-0';
867
+ else if (tpr)
868
+ to = '<=' + tM + '.' + tm + '.' + tp + '-' + tpr;
869
+ else
870
+ to = '<=' + to;
871
+
872
+ return (from + ' ' + to).trim();
873
+ }
874
+
875
+
876
+ // if ANY of the sets match ALL of its comparators, then pass
877
+ Range.prototype.test = function(version) {
878
+ if (!version)
879
+ return false;
880
+ for (var i = 0; i < this.set.length; i++) {
881
+ if (testSet(this.set[i], version))
882
+ return true;
883
+ }
884
+ return false;
885
+ };
886
+
887
+ function testSet(set, version) {
888
+ for (var i = 0; i < set.length; i++) {
889
+ if (!set[i].test(version))
890
+ return false;
891
+ }
892
+ return true;
893
+ }
894
+
895
+ exports.satisfies = satisfies;
896
+ function satisfies(version, range, loose) {
897
+ try {
898
+ range = new Range(range, loose);
899
+ } catch (er) {
900
+ return false;
901
+ }
902
+ return range.test(version);
903
+ }
904
+
905
+ exports.maxSatisfying = maxSatisfying;
906
+ function maxSatisfying(versions, range, loose) {
907
+ return versions.filter(function(version) {
908
+ return satisfies(version, range, loose);
909
+ }).sort(function(a, b) {
910
+ return rcompare(a, b, loose);
911
+ })[0] || null;
912
+ }
913
+
914
+ exports.validRange = validRange;
915
+ function validRange(range, loose) {
916
+ try {
917
+ // Return '*' instead of '' so that truthiness works.
918
+ // This will throw if it's invalid anyway
919
+ return new Range(range, loose).range || '*';
920
+ } catch (er) {
921
+ return null;
922
+ }
923
+ }
924
+
925
+ // Determine if version is less than all the versions possible in the range
926
+ exports.ltr = ltr;
927
+ function ltr(version, range, loose) {
928
+ return outside(version, range, '<', loose);
929
+ }
930
+
931
+ // Determine if version is greater than all the versions possible in the range.
932
+ exports.gtr = gtr;
933
+ function gtr(version, range, loose) {
934
+ return outside(version, range, '>', loose);
935
+ }
936
+
937
+ exports.outside = outside;
938
+ function outside(version, range, hilo, loose) {
939
+ version = new SemVer(version, loose);
940
+ range = new Range(range, loose);
941
+
942
+ var gtfn, ltefn, ltfn, comp, ecomp;
943
+ switch (hilo) {
944
+ case '>':
945
+ gtfn = gt;
946
+ ltefn = lte;
947
+ ltfn = lt;
948
+ comp = '>';
949
+ ecomp = '>=';
950
+ break;
951
+ case '<':
952
+ gtfn = lt;
953
+ ltefn = gte;
954
+ ltfn = gt;
955
+ comp = '<';
956
+ ecomp = '<=';
957
+ break;
958
+ default:
959
+ throw new TypeError('Must provide a hilo val of "<" or ">"');
960
+ }
961
+
962
+ // If it satisifes the range it is not outside
963
+ if (satisfies(version, range, loose)) {
964
+ return false;
965
+ }
966
+
967
+ // From now on, variable terms are as if we're in "gtr" mode.
968
+ // but note that everything is flipped for the "ltr" function.
969
+
970
+ for (var i = 0; i < range.set.length; ++i) {
971
+ var comparators = range.set[i];
972
+
973
+ var high = null;
974
+ var low = null;
975
+
976
+ comparators.forEach(function(comparator) {
977
+ high = high || comparator;
978
+ low = low || comparator;
979
+ if (gtfn(comparator.semver, high.semver, loose)) {
980
+ high = comparator;
981
+ } else if (ltfn(comparator.semver, low.semver, loose)) {
982
+ low = comparator;
983
+ }
984
+ });
985
+
986
+ // If the edge version comparator has a operator then our version
987
+ // isn't outside it
988
+ if (high.operator === comp || high.operator === ecomp) {
989
+ return false;
990
+ }
991
+
992
+ // If the lowest version comparator has an operator and our version
993
+ // is less than it then it isn't higher than the range
994
+ if ((!low.operator || low.operator === comp) &&
995
+ ltefn(version, low.semver)) {
996
+ return false;
997
+ } else if (low.operator === ecomp && ltfn(version, low.semver)) {
998
+ return false;
999
+ }
1000
+ }
1001
+ return true;
1002
+ }
1003
+
1004
+ // Use the define() function if we're in AMD land
1005
+ if (typeof define === 'function' && define.amd)
1006
+ define(exports);
1007
+
1008
+ })(
1009
+ typeof exports === 'object' ? exports :
1010
+ typeof define === 'function' && define.amd ? {} :
1011
+ semver = {}
1012
+ );
1013
+
1014
+ ;angular.module('semverSort', []).filter('semverSort', [
1015
+ '$window', '$log', function($window, $log) {
1016
+ 'use strict';
1017
+
1018
+ var semver = $window.semver;
1019
+
1020
+ var WARNING_FALLBACK = '`semverSort` will fall back to alphabetical sorting.';
1021
+ var WARNING_UNAVAILABLE = 'Semver library is unvailable. ' + WARNING_FALLBACK;
1022
+ var WARNING_NONSEMVER = 'This collection contains non-semver strings. ' + WARNING_FALLBACK;
1023
+
1024
+ var sortAlphabetically = function(collection, prop) {
1025
+ var items = collection.slice(0);
1026
+ return !prop ? items.sort() : items.sort(function(A, B) {
1027
+ var a = A[prop], b = B[prop];
1028
+ if ( a > b ) return 1;
1029
+ if ( a < b ) return -1;
1030
+ return 0;
1031
+ });
1032
+ };
1033
+
1034
+ if ( !(semver && 'SEMVER_SPEC_VERSION' in semver) ) {
1035
+ $log.warn(WARNING_UNAVAILABLE);
1036
+ return sortAlphabetically;
1037
+ }
1038
+
1039
+ var areItemsValid = function(collection, prop) {
1040
+ var items = !prop ? collection : collection.map(function(item) {
1041
+ return item[prop];
1042
+ });
1043
+ return items.every(function(item) {
1044
+ return semver.valid(item, true);
1045
+ });
1046
+ };
1047
+
1048
+ return function(collection, prop) {
1049
+ if ( !areItemsValid(collection, prop) ) {
1050
+ $log.warn(WARNING_NONSEMVER);
1051
+ return sortAlphabetically(collection, prop);
1052
+ }
1053
+
1054
+ var items = collection.slice(0);
1055
+ return !prop ? semver.sort(items, true) : items.sort(function(A, B) {
1056
+ return semver.compare(A[prop], B[prop], true);
1057
+ });
1058
+ };
1059
+ }
1060
+ ]);
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: angular-semver-sort-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dominik Porada
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description:
42
+ email:
43
+ - dominik@porada.co
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - Gemfile
49
+ - Rakefile
50
+ - angular-semver-sort-rails.gemspec
51
+ - lib/angular-semver-sort-rails.rb
52
+ - vendor/assets/javascripts/angular-semver-sort.js
53
+ homepage: https://github.com/monterail/angular-semver-sort
54
+ licenses:
55
+ - BSD
56
+ metadata: {}
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubyforge_project:
73
+ rubygems_version: 2.2.0
74
+ signing_key:
75
+ specification_version: 4
76
+ summary: angular-semver-sort packaged for Rails assets pipeline
77
+ test_files: []
78
+ has_rdoc: