package/package.json000664 001750 001750 0000001223 12427327361013026 0ustar00000000 000000 { "name": "semver-compare", "version": "1.0.0", "description": "compare two semver version strings, returning -1, 0, or 1", "main": "index.js", "dependencies": {}, "devDependencies": { "tape": "^3.0.0" }, "scripts": { "test": "tape test/*.js" }, "repository": { "type": "git", "url": "git://github.com/substack/semver-compare.git" }, "homepage": "https://github.com/substack/semver-compare", "keywords": [ "semver", "compare", "cmp", "comparison", "sort" ], "author": { "name": "James Halliday", "email": "mail@substack.net", "url": "http://substack.net" }, "license": "MIT" } package/LICENSE000664 001750 001750 0000002061 12427327315011545 0ustar00000000 000000 This software is released under the MIT license: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. package/index.js000664 001750 001750 0000000564 12427326667012224 0ustar00000000 000000 module.exports = function cmp (a, b) { var pa = a.split('.'); var pb = b.split('.'); for (var i = 0; i < 3; i++) { var na = Number(pa[i]); var nb = Number(pb[i]); if (na > nb) return 1; if (nb > na) return -1; if (!isNaN(na) && isNaN(nb)) return 1; if (isNaN(na) && !isNaN(nb)) return -1; } return 0; }; package/.travis.yml000664 001750 001750 0000000127 12427327447012660 0ustar00000000 000000 language: node_js node_js: - "0.8" - "0.10" before_install: - npm install -g npm package/example/cmp.js000664 001750 001750 0000000322 12427326245013307 0ustar00000000 000000 var cmp = require('../'); var versions = [ '1.2.3', '4.11.6', '4.2.0', '1.5.19', '1.5.5', '4.1.3', '2.3.1', '10.5.5', '11.3.0' ]; console.log(versions.sort(cmp).join('\n')); package/example/lex.js000664 001750 001750 0000000265 12427326237013327 0ustar00000000 000000 var versions = [ '1.2.3', '4.11.6', '4.2.0', '1.5.19', '1.5.5', '4.1.3', '2.3.1', '10.5.5', '11.3.0' ]; console.log(versions.sort().join('\n')); package/readme.markdown000664 001750 001750 0000002001 12427327464013540 0ustar00000000 000000 # semver-compare compare two semver version strings, returning -1, 0, or 1 The return value can be fed straight into `[].sort`. [![build status](https://secure.travis-ci.org/substack/semver-compare.png)](http://travis-ci.org/substack/semver-compare) # example ``` js var cmp = require('semver-compare'); var versions = [ '1.2.3', '4.11.6', '4.2.0', '1.5.19', '1.5.5', '4.1.3', '2.3.1', '10.5.5', '11.3.0' ]; console.log(versions.sort(cmp).join('\n')); ``` prints: ``` 1.2.3 1.5.5 1.5.19 2.3.1 4.1.3 4.2.0 4.11.6 10.5.5 11.3.0 ``` whereas the default lexicographic sort (`versions.sort()`) would be: ``` 1.2.3 1.5.19 1.5.5 10.5.5 11.3.0 2.3.1 4.1.3 4.11.6 4.2.0 ``` # methods ``` var cmp = require('semver-compare') ``` ## cmp(a, b) If the semver string `a` is greater than `b`, return `1`. If the semver string `b` is greater than `a`, return `-1`. If `a` equals `b`, return 0; # install With [npm](https://npmjs.org) do: ``` npm install semver-compare ``` # license MIT package/test/cmp.js000664 001750 001750 0000000674 12427326436012647 0ustar00000000 000000 var cmp = require('../'); var test = require('tape'); var versions = [ '1.2.3', '4.11.6', '4.2.0', '1.5.19', '1.5.5', '4.1.3', '2.3.1', '10.5.5', '11.3.0' ]; test('cmp', function (t) { t.plan(1); t.deepEqual(versions.sort(cmp), [ '1.2.3', '1.5.5', '1.5.19', '2.3.1', '4.1.3', '4.2.0', '4.11.6', '10.5.5', '11.3.0' ]); });