Skip to content
This repository was archived by the owner on Dec 19, 2025. It is now read-only.

Commit ea6e4ff

Browse files
committed
Provide type definitions
1 parent 7471404 commit ea6e4ff

File tree

8 files changed

+144
-12
lines changed

8 files changed

+144
-12
lines changed

index.d.ts

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/// <reference types="node/http" />
2+
3+
import { IncomingMessage } from "http"
4+
5+
interface CheckOptions {
6+
/**
7+
* A personal access token used for private repositories or to increase
8+
* the rate limit.
9+
*/
10+
token?: string
11+
12+
/**
13+
* The name of the Github repository to check.
14+
*/
15+
repo: string
16+
17+
/**
18+
* The owner of the repository.
19+
*/
20+
owner: string
21+
22+
/**
23+
* The current version of the application.
24+
*/
25+
currentVersion: string
26+
27+
/**
28+
* @deprecated
29+
*/
30+
reduceTraffic?: boolean
31+
32+
/**
33+
* Whether to fetch the repositories' git tags instead of the GitHub releases.
34+
* Useful when no releases are created, but only tags.
35+
*/
36+
fetchTags?: boolean
37+
38+
/**
39+
* Setting this to true will fetch the latest release only.
40+
*/
41+
latestOnly?: boolean
42+
43+
/**
44+
* Excludes pre-releases from checks.
45+
* Currently only works when no token is specified.
46+
*/
47+
excludePrereleases?: boolean
48+
}
49+
50+
/**
51+
* Describes the structure of returned tag data.
52+
*/
53+
interface TagDescriptor {
54+
/**
55+
* The name of the tag.
56+
*
57+
* @example v1.2.3
58+
*/
59+
name: string
60+
}
61+
62+
/**
63+
* Describes the structure of returned release data.
64+
*/
65+
interface ReleaseDescriptor {
66+
/**
67+
* The name of this release.
68+
*/
69+
name: string
70+
71+
/**
72+
* The tag associated with this release.
73+
*/
74+
tag: TagDescriptor
75+
76+
/**
77+
* Whether this release is a pre-release.
78+
*/
79+
isPrerelease: boolean
80+
81+
/**
82+
* A datetime string indicating the time this release was published.
83+
*/
84+
publishedAt: string
85+
86+
/**
87+
* A url where details about this release can be viewed.
88+
*/
89+
url: string
90+
}
91+
92+
type CallbackFunction = (error?: Error, update?: ReleaseDescriptor | TagDescriptor) => void
93+
94+
type RestHandlerFunction = (res: IncomingMessage) => void
95+
96+
export default function check(options: CheckOptions, callback: CallbackFunction): null | Promise<ReleaseDescriptor|TagDescriptor>
97+
export = check

jsconfig.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"compilerOptions": {
3+
"module": "CommonJS",
4+
"target": "ES6",
5+
"moduleResolution": "Node",
6+
"resolveJsonModule": true,
7+
"allowJs": true,
8+
"checkJs": true,
9+
},
10+
"include": [
11+
"index.js",
12+
"lib/**/*.js"
13+
]
14+
}

lib/check.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ const pkg = require('../package.json');
1212
* When the fetched version is greater than the given one, the newer version
1313
* is returned.
1414
*
15-
* @param options {object} The options for the version check.
16-
* @param callback {function|undefined} The callback function.
15+
* @param {CheckOptions} options The options for the version check.
16+
* @param {CallbackFunction} callback The callback function.
1717
*/
1818
const graphql = (options, callback) => {
1919
// build the query
@@ -46,10 +46,11 @@ const graphql = (options, callback) => {
4646
* When the fetched version is greater than the given one, the newer version
4747
* is returned.
4848
*
49-
* @param options {object} The options for the version check.
50-
* @param callback {function|undefined} The callback function.
49+
* @param {CheckOptions} options The options for the version check.
50+
* @param {CallbackFunction} callback The callback function.
5151
*/
5252
const rest = (options, callback) => {
53+
/** @type {RestHandlerFunction} */
5354
const handler = res => {
5455
const chunks = [];
5556
res.on('data', chunk => {
@@ -115,6 +116,7 @@ const rest = (options, callback) => {
115116
}
116117

117118
// define request options
119+
/** @type {https.RequestOptions} */
118120
const opts = {
119121
hostname: 'api.github.com',
120122
path: apiUrl,
@@ -137,8 +139,8 @@ const rest = (options, callback) => {
137139
* Github GraphQL API (v4) will be used. Otherwise we rely on the Github Rest API (v3), which
138140
* does not require authentication.
139141
*
140-
* @param options {object} The options for the version check.
141-
* @param callback {function|undefined} The callback function.
142+
* @param {CheckOptions} options The options for the version check.
143+
* @param {CallbackFunction} callback The callback function.
142144
*/
143145
module.exports = (options, callback) => {
144146
if (options === null || options === undefined) {

lib/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ const check = require('./check');
44
/**
55
* The exported checking function.
66
*
7-
* @param options {object} The options for the version check.
8-
* @param callback {function|undefined} An optional callback to pass the result to.
7+
* @param {CheckOptions} options The options for the version check.
8+
* @param {CallbackFunction} callback An optional callback to pass the result to.
99
* Can be omitted to return a Promise.
1010
* @return null or a Promise.
1111
*/

lib/query.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**
22
* Query for fetching the latest github release.
33
*
4-
* @param repo {string} The repository name.
5-
* @param owner {string} The owner of the repository.
4+
* @param {string} repo The repository name.
5+
* @param {string} owner The owner of the repository.
66
*/
77
module.exports.releases = (repo, owner) => {
88
return `
@@ -27,8 +27,8 @@ module.exports.releases = (repo, owner) => {
2727
/**
2828
* Query for fetching the latest git tag.
2929
*
30-
* @param repo {string} The repository name.
31-
* @param owner {string} The owner of the repository.
30+
* @param {string} repo The repository name.
31+
* @param {string} owner The owner of the repository.
3232
*/
3333
module.exports.tags = (repo, owner) => {
3434
return `

lib/scheme-mapper.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/**
22
* Maps a response object into the form described here:
33
* https://github.com/axelrindle/github-version-checker/wiki/API#releases
4+
*
5+
* @returns {ReleaseDescriptor}
46
*/
57
module.exports.release = obj => {
68
return {
@@ -17,6 +19,8 @@ module.exports.release = obj => {
1719
/**
1820
* Maps a response object into the form described here:
1921
* https://github.com/axelrindle/github-version-checker/wiki/API#tags
22+
*
23+
* @returns {TagDescriptor}
2024
*/
2125
module.exports.tag = obj => {
2226
return {

package-lock.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "2.2.0",
44
"description": "Version checker working with GitHub releases.",
55
"main": "index.js",
6+
"types": "index.d.ts",
67
"keywords": [
78
"version-checker",
89
"github-api"
@@ -14,6 +15,7 @@
1415
"semver": "^5.5.1"
1516
},
1617
"devDependencies": {
18+
"@types/node": "^14.18.12",
1719
"ava": "^3.15.0",
1820
"eslint": "^7.16.0",
1921
"nyc": "^15.1.0"

0 commit comments

Comments
 (0)