From 4862a8848ad0ffb154c976224a3c3c350f01670e Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Fri, 26 Apr 2019 20:10:51 +0200 Subject: [PATCH] Require Node.js 8, add TypeScript definition --- .gitattributes | 3 +-- .gitignore | 1 + .npmrc | 1 + .travis.yml | 6 ++--- index.d.ts | 23 ++++++++++++++++ index.test-d.ts | 6 +++++ license | 20 +++----------- package.json | 70 +++++++++++++++++++++++++------------------------ readme.md | 5 ++-- test.js | 14 +++++----- 10 files changed, 84 insertions(+), 65 deletions(-) create mode 100644 .npmrc create mode 100644 index.d.ts create mode 100644 index.test-d.ts diff --git a/.gitattributes b/.gitattributes index 391f0a4..6313b56 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1 @@ -* text=auto -*.js text eol=lf +* text=auto eol=lf diff --git a/.gitignore b/.gitignore index 3c3629e..239ecff 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules +yarn.lock diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..43c97e7 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/.travis.yml b/.travis.yml index b18bae5..f98fed0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ -sudo: false language: node_js node_js: - - '6' - - '4' + - '12' + - '10' + - '8' diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..d989bef --- /dev/null +++ b/index.d.ts @@ -0,0 +1,23 @@ +/** +Truncate a semver version: `1.2.3` → `1.2.0`. + +@param version - Semver version. +@param type - Version type to truncate to. + +@example +``` +import semverTruncate = require('semver-truncate'); + +semverTruncate('1.2.3-foo', 'patch'); +//=> '1.2.3' + +semverTruncate('1.2.3', 'minor'); +//=> '1.2.0' + +semverTruncate('1.2.3', 'major'); +//=> '1.0.0' +``` +*/ +declare function semverTruncate(version: string, type: 'patch' | 'minor' | 'major'): string; + +export = semverTruncate; diff --git a/index.test-d.ts b/index.test-d.ts new file mode 100644 index 0000000..6c382d9 --- /dev/null +++ b/index.test-d.ts @@ -0,0 +1,6 @@ +import {expectType} from 'tsd'; +import semverTruncate = require('.'); + +expectType(semverTruncate('1.2.3-foo', 'patch')); +expectType(semverTruncate('1.2.3', 'minor')); +expectType(semverTruncate('1.2.3', 'major')); diff --git a/license b/license index 654d0bf..e7af2f7 100644 --- a/license +++ b/license @@ -1,21 +1,9 @@ -The MIT License (MIT) +MIT License Copyright (c) Sindre Sorhus (sindresorhus.com) -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: +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 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. +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. diff --git a/package.json b/package.json index 25af270..e78269e 100644 --- a/package.json +++ b/package.json @@ -1,36 +1,38 @@ { - "name": "semver-truncate", - "version": "1.1.2", - "description": "Truncate a semver version: `1.2.3` → `1.2.0`", - "license": "MIT", - "repository": "sindresorhus/semver-truncate", - "author": { - "name": "Sindre Sorhus", - "email": "sindresorhus@gmail.com", - "url": "sindresorhus.com" - }, - "engines": { - "node": ">=4" - }, - "scripts": { - "test": "xo && ava" - }, - "files": [ - "index.js" - ], - "keywords": [ - "semver", - "version", - "semantic", - "truncate", - "shorten", - "simplify" - ], - "dependencies": { - "semver": "^5.3.0" - }, - "devDependencies": { - "ava": "*", - "xo": "*" - } + "name": "semver-truncate", + "version": "1.1.2", + "description": "Truncate a semver version: `1.2.3` → `1.2.0`", + "license": "MIT", + "repository": "sindresorhus/semver-truncate", + "author": { + "name": "Sindre Sorhus", + "email": "sindresorhus@gmail.com", + "url": "sindresorhus.com" + }, + "engines": { + "node": ">=8" + }, + "scripts": { + "test": "xo && ava && tsd" + }, + "files": [ + "index.js", + "index.d.ts" + ], + "keywords": [ + "semver", + "version", + "semantic", + "truncate", + "shorten", + "simplify" + ], + "dependencies": { + "semver": "^6.0.0" + }, + "devDependencies": { + "ava": "^1.4.1", + "tsd": "^0.7.2", + "xo": "^0.24.0" + } } diff --git a/readme.md b/readme.md index fb734a3..593c71c 100644 --- a/readme.md +++ b/readme.md @@ -6,7 +6,7 @@ ## Install ``` -$ npm install --save semver-truncate +$ npm install semver-truncate ``` @@ -38,8 +38,7 @@ Semver version. #### type -Type: `string`
-Values: `patch` `minor` `major` +Type: `'patch' | 'minor' | 'major'` Version type to truncate to. diff --git a/test.js b/test.js index 2f41417..b98ccb0 100644 --- a/test.js +++ b/test.js @@ -1,10 +1,10 @@ import test from 'ava'; -import m from '.'; +import semverTruncate from '.'; -test(t => { - t.is(m('1.2.3-foo', 'patch'), '1.2.3'); - t.is(m('1.2.3+foo', 'patch'), '1.2.3'); - t.is(m('1.2.3', 'minor'), '1.2.0'); - t.is(m('1.2.3', 'major'), '1.0.0'); - t.is(m('7.0.8-0ubuntu0.16.04.2', 'patch'), '7.0.8', 'PHP on Ubuntu'); +test('main', t => { + t.is(semverTruncate('1.2.3-foo', 'patch'), '1.2.3'); + t.is(semverTruncate('1.2.3+foo', 'patch'), '1.2.3'); + t.is(semverTruncate('1.2.3', 'minor'), '1.2.0'); + t.is(semverTruncate('1.2.3', 'major'), '1.0.0'); + t.is(semverTruncate('7.0.8-0ubuntu0.16.04.2', 'patch'), '7.0.8', 'PHP on Ubuntu'); });