104 lines
8.1 KiB
JavaScript
104 lines
8.1 KiB
JavaScript
"use strict";
|
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
});
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const plugins = require("./smartnpm.plugins");
|
|
// classes
|
|
const smartnpm_classes_npmpackage_1 = require("./smartnpm.classes.npmpackage");
|
|
class NpmRegistry {
|
|
constructor() {
|
|
this.searchDomain = 'https://api.npms.io/v2/search?q=';
|
|
}
|
|
search(searchObjectArg) {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
let searchString = '';
|
|
let addToSearchString = (addStringArg) => {
|
|
searchString = `${searchString}+${addStringArg}`;
|
|
};
|
|
// name
|
|
if (searchObjectArg.name) {
|
|
searchString = `${searchObjectArg.name}`;
|
|
}
|
|
// metadata
|
|
if (searchObjectArg.author) {
|
|
addToSearchString(`author:${searchObjectArg.author}`);
|
|
}
|
|
if (searchObjectArg.maintainer) {
|
|
addToSearchString(`maintainer:${searchObjectArg.maintainer}`);
|
|
}
|
|
if (searchObjectArg.scope) {
|
|
addToSearchString(`scope:${searchObjectArg.scope}`);
|
|
}
|
|
// status
|
|
if (searchObjectArg.deprecated) {
|
|
if (searchObjectArg.deprecated === true) {
|
|
addToSearchString(`is:deprecated`);
|
|
}
|
|
else {
|
|
addToSearchString(`not:deprecated`);
|
|
}
|
|
}
|
|
if (searchObjectArg.unstable) {
|
|
if (searchObjectArg.unstable === true) {
|
|
addToSearchString(`is:unstable`);
|
|
}
|
|
else {
|
|
addToSearchString(`not:unstable`);
|
|
}
|
|
}
|
|
if (searchObjectArg.insecure) {
|
|
if (searchObjectArg.insecure === true) {
|
|
addToSearchString(`is:insecure`);
|
|
}
|
|
else {
|
|
addToSearchString(`not:insecure`);
|
|
}
|
|
}
|
|
// search behaviour
|
|
if (searchObjectArg.boostExact) {
|
|
addToSearchString(`boost-exact:${searchObjectArg.boostExact}`);
|
|
}
|
|
if (searchObjectArg.scoreEffect) {
|
|
addToSearchString(`score-effect:${searchObjectArg.scoreEffect}`);
|
|
}
|
|
// analytics
|
|
if (searchObjectArg.qualityWeight) {
|
|
addToSearchString(`author:${searchObjectArg.qualityWeight}`);
|
|
}
|
|
if (searchObjectArg.popularityWeight) {
|
|
addToSearchString(`author:${searchObjectArg.popularityWeight}`);
|
|
}
|
|
if (searchObjectArg.maintenanceWeight) {
|
|
addToSearchString(`author:${searchObjectArg.maintenanceWeight}`);
|
|
}
|
|
plugins.beautylog.log(`Search on npm for ${plugins.beautycolor.coloredString(searchString, 'pink')}`);
|
|
let body;
|
|
try {
|
|
let response = (yield plugins.smartrequest.get(this.searchDomain + searchString, {}));
|
|
body = response.body;
|
|
}
|
|
catch (_a) {
|
|
// we do nothing
|
|
}
|
|
// lets create the packageArray
|
|
let packageArray = [];
|
|
// if request failed just return it empty
|
|
if (!body || typeof body === 'string') {
|
|
return packageArray;
|
|
}
|
|
for (let packageArg of body.results) {
|
|
let localPackage = new smartnpm_classes_npmpackage_1.NpmPackage(packageArg.package);
|
|
packageArray.push(localPackage);
|
|
}
|
|
return packageArray;
|
|
});
|
|
}
|
|
}
|
|
exports.NpmRegistry = NpmRegistry;
|
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRucG0uY2xhc3Nlcy5ucG1yZWdpc3RyeS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0bnBtLmNsYXNzZXMubnBtcmVnaXN0cnkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ij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