-
-
Notifications
You must be signed in to change notification settings - Fork 861
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(index): cannot work at Vue 1.0.10 later
issues closes #9
- Loading branch information
Showing
3 changed files
with
110 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* Version compare | ||
* - Inspired: | ||
* https://github.com/omichelsen/compare-versions | ||
*/ | ||
|
||
const PATCH_PATTERN = /-([\w-.]+)/ | ||
|
||
|
||
function split (v) { | ||
let temp = v.split('.') | ||
let arr = temp.splice(0, 2) | ||
arr.push(temp.join('.')) | ||
return arr | ||
} | ||
|
||
/** | ||
* compare | ||
* | ||
* @param {String} v1 | ||
* @param {String} v2 | ||
* @return {Number} | ||
*/ | ||
|
||
export default function (v1, v2) { | ||
let s1 = split(v1) | ||
let s2 = split(v2) | ||
|
||
for (let i = 0; i < 3; i++) { | ||
let n1 = parseInt(s1[i] || 0, 10) | ||
let n2 = parseInt(s2[i] || 0, 10) | ||
|
||
if (n1 > n2) { return 1 } | ||
if (n2 > n1) { return -1 } | ||
} | ||
|
||
if ((s1[2] + s2[2] + '').indexOf('-') > -1) { | ||
let p1 = (PATCH_PATTERN.exec(s1[2]) || [''])[0] | ||
let p2 = (PATCH_PATTERN.exec(s2[2]) || [''])[0] | ||
|
||
if (p1 === '') { return 1 } | ||
if (p2 === '') { return -1 } | ||
if (p1 > p2) { return 1 } | ||
if (p2 > p1) { return -1 } | ||
} | ||
|
||
return 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import assert from 'power-assert' | ||
import compare from '../../src/compare' | ||
|
||
|
||
describe('compare', () => { | ||
it('should compare three-segment versions correctly', () => { | ||
assert.equal(compare('10.1.8', '10.0.4'), 1) | ||
assert.equal(compare('10.0.1', '10.0.1'), 0) | ||
assert.equal(compare('10.1.1', '10.2.2'), -1) | ||
}) | ||
|
||
it('should compare two-segment versions correctly', () => { | ||
assert.equal(compare('10.8', '10.4'), 1) | ||
assert.equal(compare('10.1', '10.1'), 0) | ||
assert.equal(compare('10.1', '10.2'), -1) | ||
}) | ||
|
||
it('should compare single-segment versions correctly', () => { | ||
assert.equal(compare('10', '9'), 1) | ||
assert.equal(compare('10', '10'), 0) | ||
assert.equal(compare('9', '10'), -1) | ||
}) | ||
|
||
it('should compare versions with different number of digits in same group', () => { | ||
assert.equal(compare('11.0.10', '11.0.2'), 1) | ||
assert.equal(compare('11.0.2', '11.0.10'), -1) | ||
}) | ||
|
||
it('should compare versions with different number of digits in different groups', () => { | ||
assert.equal(compare('11.1.10', '11.0'), 1) | ||
}) | ||
|
||
it('should compare versions with different number of digits', () => { | ||
assert.equal(compare('1.1.1', '1'), 1) | ||
assert.equal(compare('1.0.0', '1'), 0) | ||
assert.equal(compare('1.0', '1.4.1'), -1) | ||
}) | ||
|
||
it('should compare pre-release versions', () => { | ||
assert.equal(compare('1.0.0-alpha.1', '1.0.0-alpha'), 1) | ||
assert.equal(compare('1.0.0-alpha', '1.0.0-alpha'), 0) | ||
assert.equal(compare('1.0.0-alpha', '1.0.0-alpha.beta'), -1) | ||
assert.equal(compare('1.0.0-alpha', '1.0.0-beta'), -1) | ||
}) | ||
|
||
it('should give precendece to normal versions over pre-release', () => { | ||
assert.equal(compare('1.0.0', '1.0.0-alpha'), 1) | ||
assert.equal(compare('1.0.0-beta', '1'), -1) | ||
}) | ||
|
||
it('should ignore build metadata', () => { | ||
assert.equal(compare('1.4.0-build.3928', '1.4.0-build.3928+sha.a8d9d4f'), 0) | ||
assert.equal(compare('1.4.0-build.3928+sha.b8dbdb0', '1.4.0-build.3928+sha.a8d9d4f'), 0) | ||
}) | ||
}) |