1.0.2 • Published 7 years ago

pkg-bin v1.0.2

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

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