Skip to content
Hank Chan edited this page Nov 18, 2018 · 11 revisions

npmlist's API is made available in Promise, which is also accessible via async/await.

Install

$ npm install @hankchanocd/npmlist

Import

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;

Features

npmSearch

npmSearch(modules: [ module: String ])

Search npm modules on npms.io with score analysis


raw()

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

rawNoColor()

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

Async/await

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

npmList()

List module's dependencies - used by npl -l


raw()

npmList()
	.raw()
	.then(i => yourFunction)
	.catch(err => console.log(err));

// @express@1.0.0
// ├── Dependencies
// ├── chalk@2.4.1

rawNoColor()

npmList()
	.rawNoColor()
	.then(i => yourFunction)
	.catch(err => console.log(err));

 

npmRecent

npmRecent()

List recent global installs - used by npl -t


raw()

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

rawNoColor()

npmRecent()
	.all()
	.then(i => i.rawNoColor())
	.then(i => yourFunction)
	.catch(err => console.log(err));

 

npmGlobal

npmGlobal()

List global installs - used by npl -g


raw()

npmGlobal()
	.then(i => i.simple().raw())
	.then(i => yourFunction)
	.catch(err => console.log(err));

// ├── 0x@4.5.3
// ├── aerobatic-cli@1.1.4

rawNoColor()

npmGlobal()
	.then(i => i.simple().rawNoColor())
	.then(i => yourFunction)
	.catch(err => console.log(err));

 

npmScripts

npmScripts()

Return a list of scripts - used by npl -s


raw()

npmScripts()
	.raw()
	.then(i => yourFunction)
	.catch(err => console.log(err));

// @express@1.0.0
// build => babel src/ -d build/ --quiet
// commit => git-cz

rawNoColor()

npmScripts()
	.rawNoColor()
	.then(i => yourFunction)
	.catch(err => console.log(err));

 

npmRegistry

npmRegistry(module: String)

Fetch package dependencies from npm registry - used by npl module


raw()

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

rawNoColor()

npmRegistry(module)
	.then(i => i.simple().rawNoColor())
	.then(i => yourFunction)
	.catch(err => console.log(err));

 

StringUtil

cleanTagName

cleanTagName(str: string)

let str = "surl-cli@semantically-release";
StringUtil.cleanTagName(str); // 'surl-cli'

 

getRidOfColors

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

getRidOfQuotationMarks(str: String)

StringUtil.getRidOfQuotationMarks(str);

 

truncate

truncate(str: String, maxWidth: Number, truncateMarker: Boolean)

Parameters

  • str: required
  • maxWidth: optional, default = 50
  • truncateMarker: optional, default = true
let str = "surl-cli@semantically-release";
StringUtil.truncate(str, 8, false); // => 'surl-cli...'