pkg-bin
v1.0.2
Published
Get a command name from a package.json object
Downloads
19
Maintainers
Readme
pkg-bin
Get a command name from a package.json object
const pkgBin = require('pkg-bin');
const pakcageJson = {
name: 'my-tool-cli',
bin: {
'my-tool': 'lib/cli.js'
}
};
pkgBin(pakcageJson); //=> 'my-tool'
Installation
npm install pkg-bin
API
const pkgBin = require('pkg-bin');
pkgBin(pkgData)
pkgData: Object
(package.json object)
Return: String
(a command name)
It returns a command name of the given package.
pkgBin({
name: 'hi',
bin: 'path/to/bin.js'
}); //=> 'hi'
If the package includes multiple commands, it returns the first one.
pkgBin({
name: 'hi',
bin: {
hello1: 'path/to/hello1.js',
hello2: 'path/to/hello2.js'
hello3: 'path/to/hello3.js'
}
}); //=> 'hello1'
If the package includes no commands, it returns null
.
pkgBin({name: 'hi'}); //=> null