Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
shinnn committed Jul 10, 2018
0 parents commit c6dd39b
Show file tree
Hide file tree
Showing 10 changed files with 3,997 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.nyc_output
coverage
node_modules
9 changes: 9 additions & 0 deletions .travis.yml
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=
6 changes: 6 additions & 0 deletions LICENSE
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.
52 changes: 52 additions & 0 deletions README.md
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
32 changes: 32 additions & 0 deletions index.js
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);
};

0 comments on commit c6dd39b

Please sign in to comment.