UNPKG

1.21 kBJavaScriptView Raw
1'use strict';
2
3var _ = require('lodash');
4var bestGuessHomepage = require('./best-guess-homepage');
5var semver = require('semver');
6var packageJson = require('package-json');
7var cpuCount = require('os').cpus().length;
8var throat = require('throat')(cpuCount);
9
10function getNpmInfo(packageName) {
11 return throat(function () {
12 return packageJson(packageName, { fullMetadata: true, allVersions: true });
13 }).then(function (rawData) {
14 var CRAZY_HIGH_SEMVER = '8000.0.0';
15
16 var sortedVersions = _(rawData.versions).keys().remove(_.partial(semver.gt, CRAZY_HIGH_SEMVER)).sort(semver.compare).valueOf();
17
18 var latest = rawData['dist-tags'].latest;
19 var next = rawData['dist-tags'].next;
20 var latestStableRelease = semver.satisfies(latest, '*') ? latest : semver.maxSatisfying(sortedVersions, '*');
21 return {
22 latest: latestStableRelease,
23 next: next,
24 versions: sortedVersions,
25 homepage: bestGuessHomepage(rawData)
26 };
27 }).catch(function (err) {
28 var errorMessage = 'Registry error ' + err.message;
29 return {
30 error: errorMessage
31 };
32 });
33}
34
35module.exports = getNpmInfo;
\No newline at end of file