-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c6dd39b
Showing
10 changed files
with
3,997 additions
and
0 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,15 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_style = tab | ||
tab_width = 2 | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.{md,yml}] | ||
indent_style = space | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
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 @@ | ||
* text=auto |
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,3 @@ | ||
.nyc_output | ||
coverage | ||
node_modules |
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,9 @@ | ||
branches: | ||
except: /^v\d/ | ||
language: node_js | ||
node_js: node | ||
after_script: node_modules/.bin/nyc report --reporter=text-lcov | npx coveralls | ||
env: | ||
global: | ||
- COVERALLS_SERVICE_NAME=travis-pro | ||
- secure: JxzjfAx/2u+jeaR60J75NKeug42fNpoAW1imERqNOJcP+/3lP1iQK9hO68hCleXIcKN5rcZPquKyRgmZj5yBLD1+Lge7CgHl/1Jo849apUBPEYs0aQhPjCPvpQQwyt+cMew9hFoTkiw9+ntCc7kjR8AlYxbENd/oI57Tcy1L0/RtEeswIrwq6KxfL5o4oUybhPxjPtzHknPc6zPMAUHnw+OmEoG1fa9k/jRuSXbBEFoSkXivqSubaWWsjIuy5GhnXKUggPV0g+/c/b2Dt6sgHaokoV1K9rjAQfpME2bkPEmmV7ONLdHEM7MzJjFePVhuvrtHBqPY6+bFcYeN0/XtVy8xR+E9PGW7kuUAPbsML4poLKZJfneqBe1w4CrUltXNogMKhyvWheGfPgsT5pyiNy4E+J+djkiUK8ObjGbw3PQyoM1JT8VQueDIDcBggSfi+qKhHAvCXMOcyjWZHa7Yo8vZ+abtzmSorkxfySBUhzZBlj1rH8ALHysEm2O8UMYz8N/bSGO0z5TIX69HZxwbOOTu/9iqvFhQjHJUfFlR+6APKdMQ00gE90jXM9GDJqDJ0pEBd9m28Skt78kBcteG5vo2zln7AfwcOcXmy9DQujow7otAEa714GAU8yHjhtGsXlddTwJQaVMow4nbr8rRS4xmTCT6NoEsbjO3ueO1SzI= |
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,6 @@ | ||
ISC License (ISC) | ||
Copyright 2018 Shinnosuke Watanabe | ||
|
||
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
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,52 @@ | ||
# npm-version-compare | ||
|
||
[![npm version](https://img.shields.io/npm/v/npm-version-compare.svg)](https://www.npmjs.com/package/npm-version-compare) | ||
[![Build Status](https://travis-ci.com/shinnn/npm-version-compare.svg?branch=master)](https://travis-ci.com/shinnn/npm-version-compare) | ||
[![Coverage Status](https://img.shields.io/coveralls/shinnn/npm-version-compare.svg)](https://coveralls.io/github/shinnn/npm-version-compare?branch=master) | ||
|
||
Compare [npm CLI](https://github.com/npm/npm) version string with another version string | ||
|
||
```javascript | ||
const npmVersionCompare = require('npm-version-compare'); | ||
|
||
// When `npm --version` prints `6.1.0` | ||
|
||
(async () => { | ||
await npmVersionCompare('6.0.0'); // 1 | ||
await npmVersionCompare('6.1.0'); // 0 | ||
await npmVersionCompare('6.2.0'); // -1 | ||
})(); | ||
``` | ||
|
||
## Installation | ||
|
||
[Use](https://docs.npmjs.com/cli/install) [npm](https://docs.npmjs.com/getting-started/what-is-npm). | ||
|
||
``` | ||
npm install npm-version-compare | ||
``` | ||
|
||
## API | ||
|
||
```javascript | ||
const npmVersionCompare = require('npm-version-compare'); | ||
``` | ||
|
||
### npmVersionCompare(*version*) | ||
|
||
*version*: `string` ([SemVer](https://semver.org/) version expression) | ||
Return: `Promise<integer>` (`-1`, `0` or `1`) | ||
|
||
The resultant promise will be fulfilled with: | ||
|
||
* `-1` if a given version is greater than the version of currently installed `npm` | ||
* `0` if a given version is the same value as the `npm` version | ||
* `1` if the `npm` version is greater than a given version | ||
|
||
## Related project | ||
|
||
* [npm-cli-version](https://github.com/shinnn/npm-cli-version) — Get the currently installed npm version | ||
|
||
## License | ||
|
||
[ISC License](./LICENSE) © 2018 Shinnosuke Watanabe |
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,32 @@ | ||
'use strict'; | ||
|
||
const {inspect} = require('util'); | ||
|
||
const inspectWithKind = require('inspect-with-kind'); | ||
const parseNpmVersion = require('parse-npm-version'); | ||
|
||
const ERROR = 'Expected a semver-valid version (<string>)'; | ||
|
||
module.exports = async function npmVersionCompare(...args) { | ||
const argLen = args.length; | ||
|
||
if (argLen !== 1) { | ||
throw new RangeError(`Expected 1 argument (<string>), but got ${argLen || 'no'} arguments.`); | ||
} | ||
|
||
const [anotherVersion] = args; | ||
|
||
if (typeof anotherVersion !== 'string') { | ||
throw new TypeError(`${ERROR}, but got a non-string value ${inspectWithKind(anotherVersion)}.`); | ||
} | ||
|
||
if (anotherVersion.length === 0) { | ||
throw new RangeError(`${ERROR}, but got '' (empty string).`); | ||
} | ||
|
||
if (anotherVersion.trim().length === 0) { | ||
throw new RangeError(`${ERROR}, but got a whitespace-only string ${inspect(anotherVersion)}.`); | ||
} | ||
|
||
return (await parseNpmVersion()).compare(anotherVersion); | ||
}; |
Oops, something went wrong.