1.0.3 • Published 2 years ago

package-bin v1.0.3

Weekly downloads
-
License
CC0-1.0
Repository
github
Last release
2 years ago

Package-bin

NPM version Coverage Status

Get a command name from a package.json object

const pkgBin = require('package-bin');

const packageJson = {
  name: 'my-tool-cli',
  bin: {
    'my-tool': 'lib/cli.js'
  }
};

pkgBin(pakcageJson); //=> 'my-tool'

Installation

Use npm.

npm install package-bin

API

const pkgBin = require('package-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