open-index/open-npm huggingface dataset:
npm package: @reggi/command
Description: Wrapper for functions dependent on global process variable
Author: Thomas Reggi
Latest version: 0.0.193

# `@reggi/command`

```bash
npm i @reggi/command
```

# Why

I struggled with writing unit tests for my CLI tools. I tried to build out ways of mocking the process variable completley. I have tried every npm module that attempts to mock `stido` correctly, (the only one that does a good job is [TylorS/stdio-mock](https://github.com/TylorS/stdio-mock). But even when `stdio` is mocked jest still had issues when an actual `process.exit` would be called. The main way to mock that is to overwrite process. Rather then doing that I've gone in the opposite direction with this:

```js
const command = (m, fn) => {
  if (require.main === m) {
    return fn(process)
  } else {
    return fn
  }
}
```

This is a simple way to wrap any function that uses process. What this conditional does is this:

* if it is required / imported the function is returned 
* if it is run through the command line the function is executed and `process` is passed in.

This allows for this:

```js
export default command(module, ({stdout, exit}) => {
  stdout.write('hello world' + '\n')
  return exit(0)
})
```

Writing a simple test for this is easy because you can pass in stub / spy functions for the process properties you use (sinon rocks for this).

```js
import {spy} from 'sinon'
import simpleCli from './index'

test('simpleCli', () => {
  const p = {stdout: {write: spy()}, exit: spy()}
  simpleCli(p)
  expect(p.stdout.write.called).toBeTruthy()
  expect(p.exit.called).toBeTruthy()
})
```
npm package: @reggi/command-plus
Description: ``` npm i @reggi/command-plus --save ```
Author: Thomas Reggi
Latest version: 0.0.184

# `@reggi/command-plus`

```
npm i @reggi/command-plus --save
```

## Why

This project is a wrapper around the [`@reggi/command`](https://github.com/reggi/abide/tree/master/packages/command) module that allows functions that return "normal" values to be handled in unix terminal in a consistent way.

* A returned `boolean` of `true` will return with an exit code of `0`
* A returned `boolean` of `false` will return with an exit code of `1`
* A returned `string` will be written to `stdout` with an exit code `0`
* Anything else returned will be `json` stringified with an exit code `0`
* Any thrown error will be caught, the message will be written to `stderr` with an exit code of `1`

## Examples

### `boolean` `false`

```js
import commandPlus from '@reggi/command-plus'

export default commandPlus(module, async () => {
  return false // return with an exit code of `1`
})
```

### `boolean` `true`

```js
import commandPlus from '@reggi/command-plus'

export default commandPlus(module, async () => {
  return true // return with an exit code of `0`
})
```

### `strings`

```js
import commandPlus from '@reggi/command-plus'

export default commandPlus(module, async () => {
  return 'Hello World' // will be written to `stdout` with an exit code `0` 
})
```

### `object`

```js
import commandPlus from '@reggi/command-plus'

export default commandPlus(module, async () => {
  return {greeting: 'Hi'} // will be `json` stringified with an exit code `0`
})
```

### thrown `Error`

```js
import commandPlus from '@reggi/command-plus'

export default commandPlus(module, async () => {
  throw new Error('Not good') // message will be written to `stderr` with an exit code of `1`
})
```
npm package: @reggi/dep-merge
Description: Merges devDeps into deps
Author: Thomas Reggi
Latest version: 0.0.192

# `@reggi/dep-merge`

```
npm i @reggi/dep-merge --save
```

## Why 

Built for the CLI tool [`@reggi/dep-merge-cli`](https://github.com/reggi/abide/tree/master/packages/dep-merge-cli), `dep-merge` takes all the dev-dependencies in a `package.json` file and merges them intto dependencies. This can be useful in monorepo setups where nested dev-dependencies aren't installed. 

## Examples

Given a path to a module, the functions below will merge / unmerge dependencies. 

```js
import {depMerge, unDepMerge} from 'dep-merge'

// merges dependencies in module
const depMergeResults = depMerge('./my-module')
  .then(console.log)
  .catch(console.log)

// unmerges dependencies in module
const unDepMergeResults = unDepMerge('./my-module')
  .then(console.log)
  .catch(console.log)
```
npm package: @reggi/dep-merge-cli
Description: Merges devDeps into deps for a given package.json
Author: Thomas Reggi
Latest version: 0.0.190

# `dep-merge-cli`

## Install

`npm i @reggi/dep-merge-cli -g`

## What

This module has two features.

1. `--merge` updates package.json to include all `devDependencies` in `dependencies`
2. `--unmerge` reverts changes made by the `--merge command.

## Why

This module was created in direct response to [this feature request](https://github.com/npm/npm/issues/20160) to `npm`.

## Usage

```bash
$ dep-merge --help

Usage: dep-merge

  Tool for merging devDependencies into dependencies

  Options:

    --merge                merges devDependencies into dependencies
    --unmerge              unmerges devDependencies from dependencies
    --path, -C <path>      path to node module directory
    --help, -h             generate this output
    --version, -v          show version number
    --silent, -s           log no output
```
npm package: @reggi/dep-pointer
Description: ## Summary
Author: Thomas Reggi
Latest version: 0.0.185

# `@reggi/dep-pointer`

## Summary

> This is a two-part-module [@reggi/dep-pointer-cli](https://github.com/reggi/abide/tree/master/packages/dep-pointer-cli).

> This is a CLI tool / Node.js function built to be used with monorepos using [`lerna`](https://github.com/lerna/lerna).

[`lerna`](https://github.com/lerna/lerna) has an undocumented feature where it converts a `package.json` file where `dependencies` with a file-specifiers (`file://../my-package`) are swapped for the version that the actual package reference is set to.

For instance this line in `package.json`:

```
"@reggi/journey": "file:../journey"
```

Would be switched to something like this right before the module was published:

```
"@reggi/journey": "2.18.23"
```

# How

This module will search for the directory where a lerna configuration file exists, and use that as a point of reference, then it creates a backup of the `package.json` and changes all the specifiers in all the pacakges. The function is async. Below are some examples.

```js
import depPointer from '@reggi/dep-pointer'

depPointer({workingDir}) // with no arguments but in directory with package
depPointer({workingDir, backupLocal: false}) // with no arguments but in directory with package (no backup)
depPointer({workingDir, packageName: 'module-three'}) // in parent dir with passed in updatePackage
depPointer({workingDir, all: true}) // updateAll
depPointer({workingDir, changed: true}) // updateChanged
```
npm package: @reggi/dep-pointer-cli
Description: Tool for assigning version from file references
Author: Thomas Reggi
Latest version: 0.0.185

# `@reggi/dep-pointer-cli`

## Summary

> This is a two-part-module [@reggi/dep-pointer](https://github.com/reggi/abide/tree/master/packages/dep-pointer).

> This is a CLI tool / Node.js function built to be used with monorepos using [`lerna`](https://github.com/lerna/lerna).

[`lerna`](https://github.com/lerna/lerna) has an undocumented feature where it converts a `package.json` file where `dependencies` with a file-specifiers (`file://../my-package`) are swapped for the version that the actual package reference is set to.

For instance this line in `package.json`:

```
"@reggi/journey": "file:../journey"
```

Would be switched to something like this right before the module was published:

```
"@reggi/journey": "2.18.23"
```
npm package: @reggi/gitpkg.traverse-up
Description: ``` npm i @reggi/gitpkg.traverse-up ```
Author: Thomas Reggi
Latest version: 0.0.184

# `@reggi/gitpkg.traverse-up`

```
npm i @reggi/gitpkg.traverse-up
```

## Why

Given a file name and a working directory, `traverseUp` will look traverse up the file hierarchy for a given file. This is good to find a folder like `node_modules`, a file like `package.json`, or a `lerna.json` config.

```js
import traverseUp from '@reggi/gitpkg.traverse-up'

;(async () => {
  const packagePath = await traverseUp({
    findPathPattern: 'package.json',
    findTypePattren: 'file',
    workingDir: './c',
    cwd: '/example-alpha/a/b'
  })
})();
```
npm package: @reggi/gitpkg.upsert
Description: Appends or updates object based on given query
Author: Thomas Reggi
Latest version: 0.0.189

# `@reggi/gitpkg.upsert`

```
npm i @reggi/gitpkg.upsert
```

# Why

> "An operation that inserts rows into a ~~database table~~ [JavaScript object] if they do not already exist, or updates them if they do." -[wiki](https://en.wiktionary.org/wiki/upsert)

# How

```js
import upsert from '@reggi/gitpkg.upsert'

// ----- upsert example ----- 

const resultsOne = upsert([
  {name: 'dolphin', job: 'waffle maker'},
  {name: 'brooke', job: 'youtube watcher'},
  {name: 'birdman', job: 'cellist'}
], {name: 'brooke', job: 'streamer'}, 'name')

// `resultsOne` now equals:

// [
//   {name: 'dolphin', job: 'waffle maker'},
//   {name: 'brooke', job: 'streamer'},
//   {name: 'birdman', job: 'cellist'}
// ]

// ----- insert example ----- 

const resultsTwo = upsert([
  {name: 'dolphin', job: 'waffle maker'},
  {name: 'brooke', job: 'youtube watcher'},
  {name: 'birdman', job: 'cellist'}
], {name: 'sallymae', job: 'banker', cust: true}, 'name'))
  
// `resultsTwo` now equals:

// [
//   {name: 'dolphin', job: 'waffle maker'},
//   {name: 'brooke', job: 'youtube watcher'},
//   {name: 'birdman', job: 'cellist'},
//   {name: 'sallymae', job: 'banker', cust: true}
// ]

```
npm package: @reggi/help
Description: Command line interface help string generator and argv parser
Author: Thomas Reggi
Latest version: 0.0.193

# `@reggi/help`

```
npm i @reggi/help --save
```

## Summary

A `process.argv` parser and `--help` generator heavily inspired by `minimist` and `commander`.

## Example

Uses the [`help.parse-argv`](https://github.com/reggi/abide/tree/master/packages/help.parse-argv) module to parse argument variables

```js
import help from '@reggi/help'

const cli = help()
  .name('pizza-cli')
  .description('The best pizza command-line-interface.')
  .option('-h, --help', 'output usage information', 'help')
  .option('-s, --size <size>', 'size of pizza', [
    choices('large', 'medium', 'small'),
    rename('size', 'small')
  ])
  .option('-v, --veggie [veggie]', 'veggie toppings')
  .option('-m, --meat [meat]', 'meat toppings', [
    choices('pepperoni', 'sausage'),
    rename('meat')
  ])
  .option('-p, --peppers', 'Add peppers')
  .option('-P, --pineapple', 'Add pineapple')
  .option('-b, --bbq-sauce', 'Add bbq sauce')
  .option('-c, --cheese [type]', 'Add the specified type of cheese [marble]')
  .parse(process.argv)

console.log(cli.flags)
```
npm package: @reggi/help.filter-until
Description: Filter an array until a match is made
Author: Thomas Reggi
Latest version: 0.0.194

# `@reggi/help.filter-until`

## Why

Function that takes an array and filters using a function, until that function is not met.

## Example

```js
import filterUntil from '@reggi/help.filter-until'
const fn = (value) => value !== 'a'
const d = filterUntil(['a', 'a', 'a', 'a', 'b', 'a', 'a'], fn) // ['a', 'a', 'a', 'a']
```
npm package: @reggi/help.parse-argv
Description: Modular unopinionated process.argv parser
Author: Thomas Reggi
Latest version: 0.0.194

# `@reggi/help.parse-argv`

```
npm i @reggi/help.parse-argv --save
```

## Summary

Unopiniotated and modular alternative to [minimist](https://github.com/substack/minimist).

## Example

Default behavior: 

```js
import parseArgv from '@reggi/help.parse-argv'

parseArgv('-h') // {'-h': true, '_': []}
parseArgv('-max') // {'-m': true, '-a': true, '-x': true, '_': []}}
parseArgv('-max=thomas') // {'-m': true, '-a': true, '-x': true, '_': []}}
```

## Why

This is a modular approach to tools like `minimist` takes in `process.argv` returns object of parsed key values based on unix flag conventions.

Other argv parsers are opinionated. For instance does you're application need to handle `-h`, `--h`, `-H`, and `--H` all differently? `minimist` does not allow this level of granularity, and does absorb the original values in a case like this. `help.parse-argv` is different in that it allows ANY possible combination of flag discovery and any convention. The main difference is that rather then returning an object of flags resovled as `{help: "value"}` it includes the dashes `{"--help": "value"}` offering greater control to remove the dashes later.

For instance:

* `npm run -- {capture}` esque support with the `child.rest` modifier.
* `nodemon --exec {capture}` esque support with the `doubleDash.until` modifier.
* Resolve `-max` as `[{'-m': true, '-a': true, '-x': true}]` accessable booleans with the `multiDash.spread` modifier.

It is also fully extensible and accepts any plugin functions!

This module also allows you to declare specific ways of handling a given regular express match, so you can handle a given flag differently then the others.

Here's a list of default modifiers:

```json
[
  "child.rest",
  "doubleDash.no",
  "doubleDash.equal",
  "doubleDash.next",
  "doubleDash.bool",
  "onlyDash.bool",
  "multiDash.spread"
]
```

Here's a list of all the modifiers:

```js
[
  'anyDash.bool'
  'anyDash.equal'
  'anyDash.next'
  'anyDash.until'
  'onlyDash.bool'
  'onlyDash.equal'
  'onlyDash.next'
  'onlyDash.until'
  'multiDash.bool'
  'multiDash.equal'
  'multiDash.next'
  'multiDash.until'
  'multiDash.spread'
  'dash.bool'
  'dash.equal'
  'dash.next'
  'dash.until'
  'doubleDash.bool'
  'doubleDash.equal'
  'doubleDash.next'
  'doubleDash.until'
  'doubleDash.no'
  'child.rest'
]
```
npm package: @reggi/help.set-entire
Description: Expand a shallow object with deep keys
Author: Thomas Reggi
Latest version: 0.0.194

# `@reggi/help.set-entire`

```
npm i @reggi/help.set-entire --save
```

## Why

Takes a flat object where the keys contain periods (`.`) and creates a nested object with those properties.

## Example

```js
  const d = setEntire({
    'example': true,
    'person.firstName': 'Thomas',
    'person.lastName': 'Reggi',
    'person.age': 28
  })

console.log(d.example) // => true
console.log(d.person.firstName) // => 'Thomas'
console.log(d.person.lastName) // => 'Reggi'
console.log(d.person.age) // => 28
```
npm package: @reggi/help.string-argv
Description: Convert a string of argv input to array
Author: Thomas Reggi
Latest version: 0.0.194

# `@reggi/help.string-argv`

```
npm i @reggi/help.string-argv --save
```

# Why

Takes a string and uses a child process to stdout the results of `process.argv` as JSON. Uses child process to spawn a Node.js instance so it is very accurate to how node splits it's `argv` string.

```js
import stringArgv from 'help.string-argv'
stringArgv('--name thomas').then(res => console.log) // => ['--name', 'thomas']
```
npm package: @reggi/here
Description: ``` npm i @reggi/here -g ```
Author: Thomas Reggi
Latest version: 0.0.184

# `@reggi/here`

```
npm i @reggi/here -g
```

## Summary 

A CLI tool to create an interface for bash shell commands, auto generates a `--help` list of all available functions, allows for cascading shell function dependency.

## Why

Do you have a lot of shell scripts associated with a project? Is npm scripts and `package.json` overflowing? Do you want an easy way to document all of the bash scripts associated with a project?

## How

Create a folder in a directory called `scripts`.

```bash
mkdir ./scripts
```

Then create a shell command.

```bash
touch ./scripts/0500-hello-world.sh
```

```sh
USAGE='--helloWorld (echo hello world)'
function helloWorld () {
  echo 'hello world'
}
```

Then run `here` in the directory with the `scripts` folder.

You should see this:

```
$ here
Usage: --function <args> [--function <args>]

	--helloWorld (echo hello world)
	--help (shows this help output)
```

Then you can execute the command using the flag:

```
$ here --helloWorld
hello world
```
npm package: @reggi/journey.coerce-to-array
Description: Coerce a string to an array
Author: Thomas Reggi
Latest version: 0.0.194

# `@reggi/journey.coerce-to-array`

```
npm i @reggi/journey.coerce-to-array --save
```

## How

This module simply coerces any value to an array, if it's an array already it returns the entered value, not nesting it in another array.

```js
import coerceToArray from '@reggi/journey.coerce-to-array'

coerceToArray(1) // => [1]
coerceToArray([1]) // => [1]
coerceToArray('A') // => ['A']
coerceToArray({}) // => [{}]
```
npm package: @reggi/journey.coerce-to-plain-object
Description: Convert variable to empty object or preserve provided
Author: Thomas Reggi
Latest version: 0.0.194

# `@reggi/journey.coerce-to-plain-object`

```
npm i @reggi/journey.coerce-to-plain-object --save
```

## How

This module coverts anything into an object.

```js
import coerceToPlainObject from 'journey.coerce-to-plain-object'

coerceToPlainObject({}) // => {}
coerceToPlainObject({'a': 'a'}) // => {'a': 'a'}
coerceToPlainObject([]) // => {}
coerceToPlainObject(1) // => {}
```
npm package: @reggi/journey.fn-free
Description: Wraps a function abstrating and preserving  original return value
Author: Thomas Reggi
Latest version: 0.0.193

# `@reggi/journey.fn-free`

```
npm i @reggi/journey.fn-free --save
```

## Why

This module takes a `function` and a `resolver`, and passes the value of the function into the resolver. The result of the function is a function that returns the result of the `resolver`. However you can pass in an array of strings that will map to methods attached to the returned function that have the ability to return the un-resolved value of the original function. This is named `fn-free` because it allows the ability to wrap a function but still have access to it's original value.

This is a convoluted concept, but was designed for the [`journey` module](https://github.com/reggi/abide/tree/master/packages/journey) where access to the variables defined is available, but the intended return value is also available. This is a programming concept that is not very established, or at least I haven't really found it in my research.

```js
const animal = () => 'tiger'
const result = fnFree(animal, (animal) => `bengal ${animal}`, ['journey'])
expect(result()).toBe('bengal tiger')
expect(result.journey()).toBe('tiger')
 ```
npm package: @reggi/journey.fn-reduce
Description: Reduce a series of functions that return objects to one obect
Author: Thomas Reggi
Latest version: 0.0.193

# `@reggi/journey.fn-reduce`

```
npm i journey.fn-reduce --save
```

# Why

This module is designed to reduce an array of functions that return objects, the returned objects are merged into one object, this allows for the abilty to have access to any variables defined in a stack.

# Examples

```js
import fnReduce from 'journey.fn-reduce'

const results = fnReduce([
  () => ({name: 'thomas'}),
  () => ({age: '29'}),
  ({name, age}) => ({return: name + age})
]) 

console.log(results()) // => { name: 'Thomas', age: '29', return: 'Thomas29' }
```

This also works with a promise in the stack:

```js
import fnReduce from 'journey.fn-reduce'

const results = fnReduce([
  () => ({name: 'thomas'}),
  async () => ({age: '29'}),
  ({name, age}) => ({return: name + age})
])

results().then(console.log) // => { name: 'Thomas', age: '29', return: 'Thomas29' }
```
npm package: @reggi/journey.is-promise
Description: Check if a variable is a promise
Author: Thomas Reggi
Latest version: 0.0.194

# `@reggi/journey.is-promise`

```
npm i @reggi/journey.is-promise --save
```

## How

This module checks if a function is a un-resolved promise and returns `true` and `false`.

```js
import isPromise from '@reggi/journey.is-promise'

const promA = async () => true
const promB = () => Promise.resolve(true)
isPromise(true) // => false
isPromise(() => {})) // => false
isPromise(promA())) // => true
isPromise(promB())) // => true
```
npm package: @reggi/lerna.utils
Description: Within a `monorepo` you have many packages and those packages can tend to use the same dependencies and devDependencies. The issue is when `packages/a` and `packages/b` use different versions of a shared dependency for instance one uses `^4.5.0` and the o
Author: Thomas Reggi
Latest version: 0.0.184

# `monorepo.dep-lint`

Within a `monorepo` you have many packages and those packages can tend to use the same dependencies and devDependencies. The issue is when `packages/a` and `packages/b` use different versions of a shared dependency for instance one uses `^4.5.0` and the other `^4.5.2` this spit is often unnecessay. This tool is used to check for these type of inconsistancies and provide a list of issues to fix. Another very important feature of this tool is the ability to check if all the `devDependencies` in your packages are included in the root package.json.

# Example output

Here's an example output

```
packages using multiple versions of the devDep jest found ^22.4.2, ^22.4.3
root contains devDep jest at version 9.9.9 needs ^22.4.2, ^22.4.3
packages using multiple versions of the devDep sinon found ^4.5.0, ^5.0.8
root is missing devDep babel-cli
packages using multiple versions of the devDep babel-eslint found ^8.2.2, ^8.2.3
root contains devDep babel-eslint at version 9.0.0 needs ^8.2.2, ^8.2.3
packages using multiple versions of the devDep fs-extra found ^5.0.0, ^6.0.1
packages using multiple versions of the dep fs-extra found ^5.0.0, ^6.0.1
packages using multiple versions of the dep @reggi/help.set-entire found file:../help.set-entire, 0.0.8
```
npm package: @reggi/pkg-cli
Description: Plugin based package.json generation
Author: Thomas Reggi
Latest version: 0.0.190

# `pkg-cli`

## Install

`npm i @reggi/pkg-cli -g`

## Why

Create dynamic package.json files.

## what

The `pkg` command line tool uses a plugin system similar to babel to help generate dynamic `package.json` files.

## Example plugin that uses other plugins

Plugins are fully extensible, meaning you can have a plugin that consumes and uses other plugins to chain them all together. 

Here's an example of plugin `pkg-plugin-cobalt` a preset I made for myself.

```js
import prop from '@reggi/pkg-plugin-prop'
import nameScope from '@reggi/pkg-plugin-name-scope'
import nameDir from '@reggi/pkg-plugin-name-dir'
import babel from '@reggi/pkg-plugin-babel-6-to-node-4'
import jest from '@reggi/pkg-plugin-jest'
import standard from '@reggi/pkg-plugin-standard'
import sort from '@reggi/pkg-plugin-sort'

export default [
  [prop, {
    'author': 'Thomas Reggi',
    'main': './index.build.js',
    'version': '0.0.1',
    'publishConfig': {
      'access': 'public'
    }
  }],
  nameDir,
  [nameScope, '@reggi'],
  babel,
  [jest, {'addBabelJest': true, 'hunderedPercent': true}],
  [standard, {'jest': true, 'babel': true, 'ignore': '*.build.js'}],
  [prop, {'scripts.test': 'npm run standard && npm run jest'}],
  [prop, {'scripts.build': 'npm run babel'}],
  sort
]
```

With this plugin published I can now run and get a `package.json` instantly generated for a specific directory.

```bash
$ pkg --plugin pkg-plugin-cobalt -w
```

## Usage

```bash
$ pkg --help
Usage: pkg

  Generate a package.json based on plugins

  Options:

    --write, -w          writes output to package.json file
    --output, -o         writes output to stdout
    --plugin <module>    path to pkg plugin
    --version, -v        shows the version
    --help, -h           shows this usage output
    --dir, -C <path>     path to use as working directory
    --silent, -s         silent the command
```