Skip to content

Commit 039944b

Browse files
BendingBendersindresorhus
authored andcommitted
Add TypeScript definition (#16)
1 parent 0a426cb commit 039944b

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
language: node_js
22
node_js:
3+
- '12'
34
- '10'
45
- '8'

index.d.ts

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
Regular expression for matching [semver](https://github.com/npm/node-semver) versions.
3+
4+
@example
5+
```
6+
import semverRegex = require('semver-regex');
7+
8+
semverRegex().test('v1.0.0');
9+
//=> true
10+
11+
semverRegex().test('1.2.3-alpha.10.beta.0+build.unicorn.rainbow');
12+
//=> true
13+
14+
semverRegex().exec('unicorn 1.0.0 rainbow')[0];
15+
//=> '1.0.0'
16+
17+
'unicorn 1.0.0 and rainbow 2.1.3'.match(semverRegex());
18+
//=> ['1.0.0', '2.1.3']
19+
```
20+
*/
21+
declare function semverRegex(): RegExp;
22+
23+
export = semverRegex;

index.test-d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import {expectType} from 'tsd';
2+
import semverRegex = require('.');
3+
4+
expectType<RegExp>(semverRegex());

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
"node": ">=8"
1414
},
1515
"scripts": {
16-
"test": "xo && ava"
16+
"test": "xo && ava && tsd"
1717
},
1818
"files": [
19-
"index.js"
19+
"index.js",
20+
"index.d.ts"
2021
],
2122
"keywords": [
2223
"semver",
@@ -30,6 +31,7 @@
3031
],
3132
"devDependencies": {
3233
"ava": "^1.4.1",
34+
"tsd": "^0.7.2",
3335
"xo": "^0.24.0"
3436
}
3537
}

0 commit comments

Comments
 (0)