# @kba/node-utils

> Utility methods on values I use all the time

Latest version **0.12.1** (published 2019-02-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install @kba/node-utils
pnpm add @kba/node-utils
yarn add @kba/node-utils
bun add @kba/node-utils
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.12.1 |
| Published | 2019-02-24 |
| First published | 2017-12-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 12.5 KB |
| Known vulnerabilities | 0 (+4 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | kba |
| Maintainers | kba |

## Links

- npm: https://www.npmjs.com/package/@kba/node-utils
- Repository: https://github.com/kba/js-utils
- Homepage: https://github.com/kba/js-utils#readme
- Issues: https://github.com/kba/js-utils/issues
- npm.io page: https://npm.io/package/@kba/node-utils

## Dependencies (6)

- [mkdirp](https://npm.io/package/mkdirp.md) 0.5.1
- [rimraf](https://npm.io/package/rimraf.md) 2.6.3
- [form-data](https://npm.io/package/form-data.md) 2.3.3
- [@kba/utils](https://npm.io/package/@kba/utils.md) ^0.12.1
- [node-fetch](https://npm.io/package/node-fetch.md) 2.3.0
- [https-proxy-agent](https://npm.io/package/https-proxy-agent.md) ^2.2.1

## Recent versions

- 0.12.1 (latest) — 2019-02-24
- 0.12.0 — 2019-02-24
- 0.11.0 — 2019-02-24
- 0.10.0 — 2019-01-25
- 0.9.0 — 2019-01-15
- 0.8.3 — 2018-11-13
- 0.8.2 — 2018-11-11
- 0.8.1 — 2018-11-11
- 0.8.0 — 2018-11-10
- 0.7.0 — 2018-11-10
- 0.6.1 — 2018-09-05
- 0.6.0 — 2018-09-05
- 0.5.0 — 2018-09-02
- 0.4.1 — 2018-07-05
- 0.3.1 — 2018-01-17
- … 18 more at https://npm.io/package/@kba/node-utils/versions

## README

# js-utils
<!-- BEGIN-MARKDOWN-TOC -->
* [`@kba/utils`](#kbautils)
	* [urlJoin(...args)](#urljoinargs)
	* [truthy(val)](#truthyval)
	* [jsonify(obj)](#jsonifyobj)
	* [randomInt(low, int)](#randomintlow-int)
	* [deansi(str)](#deansistr)
	* [verticalConcat(...strs)](#verticalconcatstrs)
	* [promisify(callback)](#promisifycallback)
	* [splitArray(arr, splitel=';')](#splitarrayarr-splitel----)
	* [promiseSerial(funcs)](#promiseserialfuncs)
	* [shortenOutput(data, max=10)](#shortenoutputdata-max-10)
	* [parseURL(...args)](#parseurlargs)
	* [lastUrlSegment(url, removeTrailing=false)](#lasturlsegmenturl-removetrailing-false)
	* [randomString({prefix='', template='', length=-1})](#randomstring-prefix----template----length--1-)
	* [uniq(arr)](#uniqarr)
	* [traverse](#traverse)
	* [deepmerge](#deepmerge)
	* [idiomaticFetch](#idiomaticfetch)
	* [splitOnce(str, sep, rightMost=false)](#splitoncestr-sep-rightmost-false)
	* [ensureArray(arg)](#ensurearrayarg)
	* [new StrictEventEmitter(events=, LOGEVENTS=false)](#new-stricteventemitterevents--logevents-false)
	* [new MultiIndex()](#new-multiindex)
	* [rexcape(str)](#rexcapestr)
* [`@kba/node-utils`](#kbanode-utils)
	* [inspect(obj)](#inspectobj)
	* [inspect.log(obj)](#inspectlogobj)
	* [relativizeFile(relPath, absPath](#relativizefilerelpath-abspath)
	* [mkdir(dir, opts)](#mkdirdir-opts)
	* [rmdir(dir, opts)](#rmdirdir-opts)
	* [uploadFile({filepath, endpoint, metadata})](#uploadfile-filepath-endpoint-metadata-)
	* [FormData](#formdata)
	* [fetch(...args)](#fetchargs)
	* [corsMiddleware(opts)](#corsmiddlewareopts)
	* [nedbCollectionRouteHandler(opts)](#nedbcollectionroutehandleropts)
	* [idiomaticFetch (node)](#idiomaticfetch-node)

<!-- END-MARKDOWN-TOC -->

## `@kba/utils`

<!-- BEGIN-RENDER ./utils/utils.js -->
### urlJoin(...args)

Join a base URI and possibly empty path segments
### truthy(val)

Return whether a value should be interpreted as boolean `true`.
### jsonify(obj)

Clone an object by serializing and deserializing to/from JSON
### randomInt(low, int)

A random integer between `low` and `high`
### deansi(str)

Remove ANSI color sequences from `str`.
### verticalConcat(...strs)
### promisify(callback)
### splitArray(arr, splitel=';')
Split an array into sub-arrays delimited by element splitel
### promiseSerial(funcs)

resolves Promises sequentially.
https://hackernoon.com/functional-javascript-resolving-promises-sequentially-7aac18c4431e
### shortenOutput(data, max=10)

Shorten `data` to a maximum of `max` characters.
### parseURL(...args)
### lastUrlSegment(url, removeTrailing=false)

Returns the last segment of a URL
### randomString({prefix='', template='', length=-1})
Generate a URL-friendly random string.
Template must have at least 3 `X` in a row
### uniq(arr)
Return unique literals in arr.
### traverse
See [substack/js-traverse](https://github.com/substack/js-traverse)
### deepmerge
See [KyleAMathews/deepmerge](https://github.com/KyleAMathews/deepmerge)
### idiomaticFetch

```js
idiomaticFetch(url, options={}, format='json')
idiomaticFetch(url, format='json')
### splitOnce(str, sep, rightMost=false)
Split `str` at the first occurence of `sep`.
### ensureArray(arg)
Ensure that arg is an array or a wrap it in one if it is not.
### new StrictEventEmitter(events=[], LOGEVENTS=false)
Strict eventemitter that allows only defined events and optionally logs emit/on calls
### new MultiIndex()
Index values by chains of keys. Useful to find object by key-value pairs
they contain.
### rexcape(str)
Escape regexp metacharacters

<!-- END-RENDER -->

## `@kba/node-utils`

All methods from [`@kba/utils`](#kbautils) and in addition:

<!-- BEGIN-RENDER ./node-utils/node-utils.js -->
### inspect(obj)

### inspect.log(obj)

### relativizeFile(relPath, absPath

### mkdir(dir, opts)

Recursively create `dir`.

@return promise
### rmdir(dir, opts)

Recursively remove `dir`.

@return promise
### uploadFile({filepath, endpoint, metadata})
### FormData
[form-data](https://github.com/form-data/form-data)
### fetch(...args)
[fetch-ponyfill](https://github.com/qubyte/fetch-ponyfill)
### corsMiddleware(opts)
@return middleware that adds `Access-Control` headers.
If `opts.allowOrigin` is `origin`, this will mirror the request header `Origin`.
### nedbCollectionRouteHandler(opts)

 Generate a handler suitable for a GET query on the root of a nedb collection.

```
@param {DataStore} opts.collection collection to query
@param {Promise} postProcess augment results
@param {Object} projection for query results
@param {String} defaultSort default sort. Default: `modified.desc`
@param {String} regexify whether to turn string regexes into real regexes for `$regex` query fields
@param {String} dateify whether to turn string ISO dates into Date objects
```

### idiomaticFetch (node)
Like browser idiomaticFetch but with proxy

<!-- END-RENDER -->

---
_Source: https://npm.io/package/@kba/node-utils · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
