Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shinnn/pkg-bin
Get a command name from a package.json object
https://github.com/shinnn/pkg-bin
Last synced: 26 days ago
JSON representation
Get a command name from a package.json object
- Host: GitHub
- URL: https://github.com/shinnn/pkg-bin
- Owner: shinnn
- Created: 2016-03-31T11:31:11.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-08-19T16:45:21.000Z (about 7 years ago)
- Last Synced: 2024-10-10T02:34:26.517Z (about 1 month ago)
- Language: JavaScript
- Size: 37.1 KB
- Stars: 3
- Watchers: 1
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# pkg-bin
[![NPM version](https://img.shields.io/npm/v/pkg-bin.svg)](https://www.npmjs.com/package/pkg-bin)
[![Build Status](https://travis-ci.org/shinnn/pkg-bin.svg?branch=master)](https://travis-ci.org/shinnn/pkg-bin)
[![Coverage Status](https://img.shields.io/coveralls/shinnn/pkg-bin.svg)](https://coveralls.io/r/shinnn/pkg-bin)Get a command name from a [package.json](https://docs.npmjs.com/files/package.json) object
```javascript
const pkgBin = require('pkg-bin');const pakcageJson = {
name: 'my-tool-cli',
bin: {
'my-tool': 'lib/cli.js'
}
};pkgBin(pakcageJson); //=> 'my-tool'
```## Installation
[Use npm.](https://docs.npmjs.com/cli/install)
```
npm install pkg-bin
```## API
```javascript
const pkgBin = require('pkg-bin');
```### pkgBin(*pkgData*)
*pkgData*: `Object` ([package.json](https://github.com/npm/npm/blob/master/doc/files/package.json.md) object)
Return: `String` (a command name)It returns a command name of the given package.
```javascript
pkgBin({
name: 'hi',
bin: 'path/to/bin.js'
}); //=> 'hi'
```If the package includes multiple commands, it returns the first one.
```javascript
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`.
```javascript
pkgBin({name: 'hi'}); //=> null
```## License
[Creative Commons Zero v1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/deed)