npm package: @ianwremmel/pkgshift
Description: Inspired by jscodeshift to help keep package.json consistent
Author: Ian W. Remmel
Latest version: 1.1.1

# @ianwremmel/pkgshift

[![license](https://img.shields.io/github/license/ianwremmel/pkgshift.svg)](https://github.com/ianwremmel/pkgshift/blob/master/LICENSE)
[![standard-readme compliant](https://img.shields.io/badge/readme%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)

[![Greenkeeper badge](https://badges.greenkeeper.io/ianwremmel/pkgshift.svg?token=caf2f19a5f1fd1b4cfa3267a2d6664664c5eb5f28dab58a271959e5008bb2ca4&ts=1510965092979)](https://greenkeeper.io/)
[![dependencies Status](https://david-dm.org/ianwremmel/pkgshift/status.svg)](https://david-dm.org/ianwremmel/pkgshift)
[![devDependencies Status](https://david-dm.org/ianwremmel/pkgshift/dev-status.svg)](https://david-dm.org/ianwremmel/pkgshift?type=dev)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)

[![CircleCI](https://circleci.com/gh/ianwremmel/pkgshift.svg?style=svg)](https://circleci.com/gh/ianwremmel/pkgshift)
[![Coverage Status](https://coveralls.io/repos/github/ianwremmel/pkgshift/badge.svg?branch=master)](https://coveralls.io/github/ianwremmel/pkgshift?branch=master)

> Inspired by jscodeshift to help keep package.json consistent

## Install

```js
npm install @ianwremmel/pkgshift
```

or

```js
npm install @ianwremmel/pkgshift
```

## Usage

For the most up to date docs, run `pkgshift --help`.

### run

\`pkgshift run ./package.json -t ./tranform.js

`pkgshift`'s only command, `run`, applies a transform file to a package.json.

A transform file is of the form

```js
module.exports = function transform(pkg, {api}) {
    return Object.assign(pkg);
};
```

where `transform` implements the [transformCallback](transformcallback)  and `api` is a reference to the [TransformAPI](transformapi).

## API

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

### TransformAPI

Helper methods passed to your transform function

Type: [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)

#### setOrReplaceScript

Sets a script, or, if that script already exists, transforms it into the new
script

**Parameters**

-   `pkg` **[Package](#package)** 
-   `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** 
    -   `options.from` **([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) \| [RegExp](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp))** The original script definition. Must be
        an exact match, but if a RegExp is supplied, the substring matches will be
        available to `to`
    -   `options.name` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The name in pkg.scripts
    -   `options.to` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The final script definition. If `from` is a
        RegExp, `to` may include substring references.

### Package

The [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) defined by a package.json

Type: [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)

### pkgShift

Asynchronously apply the specified transform to the specified package.

**Parameters**

-   `tx` **[transformCallback](#transformcallback)** 
-   `pkg` **[Package](#package)** 

Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;[Package](#package)>** 

### transformCallback

Type: [Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)

**Parameters**

-   `pkg` **[Package](#package)** 
-   `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** 
    -   `options.api` **[TransformAPI](#transformapi)** 

Returns **([Package](#package) \| [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;[Package](#package)>)** 

### apply

Asynchronously apply the specified transform to the specified package.

**Parameters**

-   `tx` **[transformCallback](#transformcallback)** 
-   `pkg` **[Package](#package)** 

Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)&lt;[Package](#package)>** 

**Meta**

-   **deprecated**: Please use [pkgShift()](pkgShift())


### cli

Main command line entry point

**Parameters**

-   `options` **[PkgShiftOptions](#pkgshiftoptions)**  (optional, default `{}`)

### PkgShiftOptions

Type: [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)

**Properties**

-   `path` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** File to transform
-   `transform` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Path to the transform file.
-   `verbose` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** Show more information about the transform
    process
-   `dry` **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Dry run (no changes are made to files)
-   `print` **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Print output, useful for development
-   `silent` **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** No output

### pkgshift

**Parameters**

-   `options` **[PkgShiftOptions](#pkgshiftoptions)** 

**Meta**

-   **deprecated**: please use [cli](#cli)
    Main command line entry point


## Maintainers

[Ian Remmel](https://github.com/ianwremmel)

## Contribute

See [CONTRIBUTE](CONTRIBUTE.md)

## License

© [MIT](LICENSE)