Skip to content

Commit

Permalink
feat: add compareVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
fjc0k committed Feb 15, 2019
1 parent 5586120 commit 00a90d4
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"typescript": "^3.1.6"
},
"dependencies": {
"compare-versions": "^3.4.0",
"is-chinese-phone-number": "^0.1.9"
}
}
3 changes: 3 additions & 0 deletions src/compareVersion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import compareVersion from 'compare-versions'

export default compareVersion
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export { default as bindEvent } from './bindEvent'
export { default as castArray } from './castArray'
export { default as chunk } from './chunk'
export { default as clamp } from './clamp'
export { default as compareVersion } from './compareVersion'
export { default as defaultValue } from './defaultValue'
export { default as endsWith } from './endsWith'
export { default as fill } from './fill'
Expand Down
9 changes: 9 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1599,3 +1599,12 @@ describe('groupBy', () => {
expect(vtils.groupBy([{ i: 1 }, { i: 2 }, { i: 2, x: 0 }], 'i')).toEqual({ 1: [{ i: 1 }], 2: [{ i: 2 }, { i: 2, x: 0 }] })
})
})

describe('compareVersion', () => {
test('ok', () => {
expect(vtils.compareVersion('10.1.8', '10.0.4')).toEqual(1)
expect(vtils.compareVersion('10.0.1', '10.0.1')).toEqual(0)
expect(vtils.compareVersion('10.1.1', '10.2.2')).toEqual(-1)
expect(vtils.compareVersion('10.1.1-alpha2', '10.1.1-alpha5')).toEqual(-1)
})
})
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1559,6 +1559,10 @@ compare-func@^1.3.1:
array-ify "^1.0.0"
dot-prop "^3.0.0"

compare-versions@^3.4.0:
version "3.4.0"
resolved "https://registry.yarnpkg.com/compare-versions/-/compare-versions-3.4.0.tgz#e0747df5c9cb7f054d6d3dc3e1dbc444f9e92b26"

component-emitter@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.2.1.tgz#137918d6d78283f7df7a6b7c5a63e140e69425e6"
Expand Down

0 comments on commit 00a90d4

Please sign in to comment.