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

Commit 0f451f0

Browse files
committed
Migrate example to docs
1 parent cd0e58a commit 0f451f0

11 files changed

Lines changed: 77 additions & 36 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"label": "Basic",
3+
"position": 1,
4+
"link": {
5+
"type": "generated-index",
6+
"title": "Basic Examples"
7+
}
8+
}
Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
1-
const versionCheck = require('../lib/main')
1+
# Async / Await
2+
3+
The future is now! Futuristic approach leveraging top-level await.
4+
5+
```js
6+
const versionCheck = require('github-version-checker')
27
const options = {
3-
token: require('./token'),
8+
// token: '...',
49
repo: 'github-version-checker',
510
owner: 'axelrindle',
611
currentVersion: require('../package.json').version
712
}
813

9-
versionCheck(options).then(function (update) {
14+
try {
15+
const update = await versionCheck(options)
1016
if (update) { // update is null if there is no update available, so check here
1117
console.log('An update is available! ' + update.name)
1218
console.log('You are on version ' + options.currentVersion + '!')
1319
} else {
1420
console.log('You are up to date.')
1521
}
16-
}).catch(function (error) {
17-
console.error(error)
18-
})
22+
} catch (e) {
23+
console.error(e)
24+
}
25+
```
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
const versionCheck = require('../lib/main')
1+
# Callback
2+
3+
Using a plain old callback.
4+
5+
````js
6+
const versionCheck = require('github-version-checker')
27
const options = {
3-
token: require('./token'),
8+
// token: '...',
49
repo: 'github-version-checker',
510
owner: 'axelrindle',
611
currentVersion: require('../package.json').version
@@ -19,3 +24,4 @@ versionCheck(options, function (error, update) {
1924
console.log('You are up to date.')
2025
}
2126
})
27+
```
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
const versionCheck = require('../lib/main')
1+
# Promise
2+
3+
Modern version using a Promise-based approach.
4+
5+
```js
6+
const versionCheck = require('github-version-checker')
27
const options = {
8+
// token: '...',
39
repo: 'github-version-checker',
410
owner: 'axelrindle',
511
currentVersion: require('../package.json').version
@@ -17,3 +23,4 @@ versionCheck(options)
1723
.catch(function (error) {
1824
console.error(error)
1925
})
26+
```
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"label": "Advanced",
3+
"position": 2,
4+
"link": {
5+
"type": "generated-index",
6+
"title": "Advanced Examples"
7+
}
8+
}
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1-
const versionCheck = require('../lib/main')
1+
# Fetch Git tags instead of GitHub releases
2+
3+
In case your repository does not use GitHub releases but just Git tags a call to the
4+
releases api won't work.
5+
6+
Fetch the tags instead by setting `fetchTags` to `true`:
7+
8+
```js
9+
const versionCheck = require('github-version-checker')
210
const options = {
3-
token: require('./token'),
11+
token: 'my-token',
412
repo: 'github-version-checker',
513
owner: 'axelrindle',
614
currentVersion: require('../package.json').version,
@@ -20,3 +28,4 @@ versionCheck(options, function (error, update) {
2028
console.log('You are up to date.')
2129
}
2230
})
31+
```
Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
1-
const versionCheck = require('../lib/main')
1+
# Explicitly call the REST API
2+
3+
There may be scenarios where you explicitly want to call the REST API.
4+
5+
Set the `token` to `false` to accomplish this:
6+
7+
```js
8+
const versionCheck = require('github-version-checker')
29
const options = {
10+
token: false,
311
repo: 'github-version-checker',
412
owner: 'axelrindle',
513
currentVersion: require('../package.json').version
614
}
715

816
versionCheck(options)
9-
.then(update => {
17+
.then(function (update) {
1018
if (update) { // update is null if there is no update available, so check here
1119
console.log('An update is available! ' + update.name)
1220
console.log('You are on version ' + options.currentVersion + '!')
1321
} else {
1422
console.log('You are up to date.')
1523
}
1624
})
17-
.catch(error => {
25+
.catch(function (error) {
1826
console.error(error)
1927
})
28+
```

docs/examples/index.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1+
---
2+
sidebar_position: 0
3+
---
4+
15
# Examples
6+
7+
Don't care about the API documentation? Look at the examples and copy paste the snippets right into your code!
8+
9+
![undraw our solution](/illustration/undraw_our_solution_re_8yk6.svg)

docs/static/illustration/undraw_our_solution_re_8yk6.svg

Lines changed: 1 addition & 0 deletions
Loading

examples/promise_async.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)