forked from nodejs/nodejs.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetNvmData.js
More file actions
22 lines (17 loc) · 723 Bytes
/
getNvmData.js
File metadata and controls
22 lines (17 loc) · 723 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const createGitHubHeaders = require('./createGitHubHeaders');
const { nvmTags } = require('../apiUrls');
const isNvmTag = data => data && typeof data.name === 'string';
const areNvmTags = data => Array.isArray(data) && data.every(isNvmTag);
function getLatestNvmVersion() {
const parseNvmVersions = nvmTagsData => {
if (!areNvmTags(nvmTagsData) || nvmTagsData.length === 0) {
// GitHub might rate-limit and we don't want to block development because of that
return { version: 'unknown' };
}
return { version: nvmTagsData[0].name };
};
return fetch(nvmTags, createGitHubHeaders())
.then(response => response.json())
.then(parseNvmVersions);
}
module.exports = getLatestNvmVersion;