# lutils

> A few reliable utils.

Latest version **2.4.0** (published 2017-06-06) · 0 weekly downloads

## Install

```sh
npm install lutils
pnpm add lutils
yarn add lutils
bun add lutils
```

## Health

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

Positive: has types; high quality score.

Warnings: low downloads; no esm support; has vulnerabilities.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.4.0 |
| Published | 2017-06-06 |
| First published | 2015-04-20 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 1 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | nfour |
| Maintainers | nfour |
| Keywords | merge, extend, clone, type, recursive, assign, deep, immutable, mutate, typeof, type, guard |

## Links

- npm: https://www.npmjs.com/package/lutils
- Repository: https://github.com/nfour/lutils
- Homepage: https://github.com/nfour/lutils#readme
- Issues: https://github.com/nfour/lutils/issues
- npm.io page: https://npm.io/package/lutils

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 2.4.0 (latest) — 2017-06-06
- 2.3.1 — 2017-05-24
- 2.3.0 — 2017-05-17
- 2.2.0 — 2017-05-12
- 2.1.7 — 2017-05-12
- 2.1.6 — 2017-05-12
- 2.1.5 — 2017-05-12
- 1.2.5 — 2017-01-10
- 1.2.4 — 2017-01-10
- 1.2.3 — 2017-01-10
- 1.2.2 — 2016-09-30
- 1.2.1 — 2016-08-07
- 1.2.0 — 2016-08-07
- 1.1.2 — 2016-07-01
- 1.1.1 — 2016-07-01
- … 13 more at https://npm.io/package/lutils/versions

## README

<a href="https://travis-ci.org/nfour/lutils">
  <img src="https://travis-ci.org/nfour/lutils.svg?branch=master" />
</a>
&nbsp;
<a href="https://david-dm.org/nfour/lutils" title="dependencies status"><img src="https://david-dm.org/nfour/lutils/status.svg"/></a>

# `lutils`

✓ _TypesSript documented_

- [merge](#merge) for deep merging of objects
- [clone](#clone) for deep cloning of objects & arrays
- [typeOf](#typeof) for consistant type checking


```ts
import { typeOf, merge, clone } from 'lutils'
```

- See: [**CHANGELOG.md**](./CHANGELOG.md)

--------------------------------

## merge

Merge objects together, traversing objects & arrays recursively

- `merge(subject, ...sources[])` => `subject`
- Default **depth**: `10`

```ts
import { merge } from 'lutils'

merge({ aa: { cc: 1 }, }, { aa: { cc: 2 } }, { bb: 3 })
=== { aa: { cc: 2 }, bb: 3 }
```

--------------------------------

Construct & configure your own `Merge` instance

- `new Merge(config).merge`
- See: [**config**](./src/merge/merge.ts#L31)

```ts
import { Merge } from 'lutils'

const merge = new Merge({ depth: Infinity }).merge

merge(megaDeep, ultraDeep)
```

--------------------------------

Merge, but with two common behaviours, whitelisting and blacklisting

- `merge.white(subject, ...sources[])` => `subject`
- `merge.black(subject, ...sources[])` => `subject`

```ts
import { merge } from 'lutils'

merge.white({ aa: { bb: 1, cc: 1 } }, { aa: { xx: 2, cc: 2 } })
=== { aa: { bb: 1, cc: 2 } }

merge.black({ aa: { bb: 1, cc: 1 } }, { aa: { xx: 2, cc: 2 } })
=== { aa: { bb: 1, cc: 1, xx: 2 } }
```

--------------------------------

## clone

Clones objects & arrays recursively

- `clone(subject)` => `clonedSubject`
- Default **depth**: `10`

```ts
import { clone } from 'lutils'

const cloned = clone({ my: { little: { foo: 'bar' } } })
```

- `new Clone(config).clone`
- See: [**config**](./src/clone/clone.ts#L12)

```ts
import { Clone } from 'lutils'

const clone = new Clone({ depth: Infinity }).clone

const cloned = clone({ my: { little: { foo: 'bar' } } })
```

--------------------------------

## typeOf

Gets the type of a value as a lowercase string. \
Like the built-in `typeof`, but works for all primitives.

- `typeOf(value)` => `string`

```ts
import { typeOf } from 'lutils'

typeOf(null)
=== 'null'

typeOf(NaN)
=== 'nan'

typeOf([])
=== 'array'
```

--------------------------------

Specific type checkers are also exported and attached to `typeOf` \
These checkers also supply typescript with type information, meaning
they can act a **type guards**.

- `isBoolean(value)` => `boolean`
- `is<type>(value)` => `boolean`
- See: [**ITypeOf**](./src/typeOf/typeOf.ts#L3)

```ts
import { typeOf, isBoolean, isString } from 'lutils'

typeOf.isNull(null)
=== true

isString(undefined)
=== false

typeOf.isString('')
=== true

isBoolean(false)
=== true

// Type guarding...

function blah (aa: number|string) {
  if (isString(aa)) {
    // string
    aa += '!!!!'
  } else {
    // number
    ++aa 
  }

  return aa
}
```

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