pkg-bin

1.0.2 • Public • Published

pkg-bin

NPM version Build Status Coverage Status

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

Use npm.

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

License

Creative Commons Zero v1.0 Universal

Dependencies (1)

Dev Dependencies (4)

Package Sidebar

Install

npm i pkg-bin

Weekly Downloads

5

Version

1.0.2

License

CC0-1.0

Last publish

Collaborators

  • shinnn