-
Notifications
You must be signed in to change notification settings - Fork 0
API
npmlist
's API is made available in Promise, which is also accessible via async/await.
$ npm install @hankchanocd/npmlist
Import only what you need. I'm listing all of the available imports here for sheer laziness.
const {
npmDependencies,
npmGlobal,
npmRegistry,
npmRecent,
npmScripts,
npmSearch,
StringUtil
} = require("@hankchanocd/npmlist");
const { npmList } = npmDependencies;
npmSearch(modules: [ module: String ])
Search npm modules on npms.io with score analysis
With ANSI color (For a better visual on terminal)
const { npmSearch } = require("@hankchanocd/npmlist");
let module = ["express"];
npmSearch(module)
.then(i => i.raw())
.then(i => yourFunction)
.catch(err => console.log(err));
// 92 express@4.16.4 express framework sinatra web rest restful router app api
// 91 path-to-regexp@2.4.0 express regexp route routing
Without ANSI color (Clean text)
const { npmSearch } = require("@hankchanocd/npmlist");
let module = ["express"];
npmSearch(module)
.then(i => i.rawNoColor())
.then(i => yourFunction)
.catch(err => console.log(err));
// 92 express@4.16.4 express framework sinatra web rest restful router app api
// 91 path-to-regexp@2.4.0 express regexp route routing
Since Node 8, anything written in Promise can also be written in async/await. Async/await code in the rest of the APIs is very similar to this one, so I won't repeat it.
async () => {
try {
let result = await npmSearch().raw();
yourFunction(result);
} catch (err) {
console.log(err);
}
};
npmList()
List module's dependencies - used by npl -l
npmList()
.raw()
.then(i => yourFunction)
.catch(err => console.log(err));
// @express@1.0.0
// ├── Dependencies
// ├── chalk@2.4.1
npmList()
.rawNoColor()
.then(i => yourFunction)
.catch(err => console.log(err));
npmRecent()
List recent global installs - used by npl -t
npmRecent()
.all()
.then(i => i.raw())
.then(i => yourFunction)
.catch(err => console.log(err));
// @hankchanocd/npmlist 11-16 21:37
// npm-fzf 11-16 2:22
npmRecent()
.all()
.then(i => i.rawNoColor())
.then(i => yourFunction)
.catch(err => console.log(err));
npmGlobal()
List global installs - used by npl -g
npmGlobal()
.then(i => i.simple().raw())
.then(i => yourFunction)
.catch(err => console.log(err));
// ├── 0x@4.5.3
// ├── aerobatic-cli@1.1.4
npmGlobal()
.then(i => i.simple().rawNoColor())
.then(i => yourFunction)
.catch(err => console.log(err));
npmScripts()
Return a list of scripts - used by npl -s
npmScripts()
.raw()
.then(i => yourFunction)
.catch(err => console.log(err));
// @express@1.0.0
// build => babel src/ -d build/ --quiet
// commit => git-cz
npmScripts()
.rawNoColor()
.then(i => yourFunction)
.catch(err => console.log(err));
npmRegistry(module: String)
Fetch package dependencies from npm registry - used by npl module
let module = "express";
npmRegistry(module)
.then(i => i.simple().raw())
.then(i => yourFunction)
.catch(err => console.log(err));
// ├── accepts@1.3.5
// ├── array-flatten@1.1.1
npmRegistry(module)
.then(i => i.simple().rawNoColor())
.then(i => yourFunction)
.catch(err => console.log(err));
cleanTagName(str: string)
let str = "surl-cli@semantically-release";
StringUtil.cleanTagName(str); // 'surl-cli'
getRidOfColors(str: String)
Especially useful for converting seemingly white text on terminal, which in reality is littered with ANSI color code, to reusable clean text.
StringUtil.getRidOfColors(str);
getRidOfQuotationMarks(str: String)
StringUtil.getRidOfQuotationMarks(str);
truncate(str: String, maxWidth: Number, truncateMarker: Boolean)
- str: required
- maxWidth: optional, default = 50
- truncateMarker: optional, default = true
let str = "surl-cli@semantically-release";
StringUtil.truncate(str, 8, false); // => 'surl-cli...'