From f4dcb1d333bf4dc8223b05a614f2a08433d7d5dd Mon Sep 17 00:00:00 2001 From: danbulant Date: Wed, 19 Feb 2020 17:45:56 +0100 Subject: [PATCH] Get info of given package --- modules/package.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/modules/package.js b/modules/package.js index 87b917e..fc1d9e6 100644 --- a/modules/package.js +++ b/modules/package.js @@ -1,8 +1,11 @@ const fs = require("fs"); +const request = require("./requests"); + +const REPO = "https://registry.npmjs.org/"; module.exports = class Package { pkg = {}; - + load(path){ if(!fs.existsSync(path))throw Error("Path doesn't exists!"); @@ -16,4 +19,23 @@ module.exports = class Package { return json; } + + get(pkg){ + return new Promise((res, rej) => { + if(!pkg)return rej("No package name given"); + + request(REPO + pkg + "/").then((res) => { + var o = JSON.parse(res); + if(o.error == "Not found"){ + console.log("The package providen couldn't be found on the NPM repository"); + return rej(404); + } + + res("found"); + }).catch(e => { + console.warn(e); + rej(e); + }) + }); + } } \ No newline at end of file