# @taharactrl/utils

> nodejs custom utility library

Latest version **0.3.1** (published 2022-06-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install @taharactrl/utils
pnpm add @taharactrl/utils
yarn add @taharactrl/utils
bun add @taharactrl/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.3.1 |
| Published | 2022-06-04 |
| First published | 2022-05-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 9.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Kohei Tahara |
| Maintainers | taharactrl |
| Keywords | util, json |

## Links

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

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.3.1 (latest) — 2022-06-04
- 0.3.0 — 2022-06-04
- 0.1.0 — 2022-05-29
- 0.0.1 — 2022-05-28

## README

# node-utils

This node library is utility function package, especially JSON object access.

## Install

```
$ npm install --save @taharactrl/utils
```

## Usage

## Subtract JSON (`subtractJSON`)

```
const _utils = require('@taharactrl/utils');

const jsonA = {
  a1: "hoge",
  a2: "foo",
  a3: [123],
};

const jsonB = {
  a1: "hoge",
  a2: "foo",
};

const ret1 = _utils.subtractJSON(jsonA, jsonB)
console.log(ret1)
// => ['a3']

const ret2 = _utils.subtractJSON(jsonB, jsonA)
console.log(ret2)
// => []

```

## Difference JSON (`differenceJSON`)

```
const _utils = require('@taharactrl/utils');

const jsonA = {
  a1: "hoge",
  a2: "foo",
  a3: [123],
  a5: [1]
};

const jsonB = {
  a1: "hoge",
  a2: "foo",
  a4: [234],
  a5: [2]
};

const ret = _utils.differenceJSON(jsonA, jsonB)
console.log(ret1)
// => ["a3", "a5.0", "a4"]
```

## Detect recursive object (`detectRecursiveObject`)

```
const _utils = require('@taharactrl/utils');

class A {
  constructor(){
    this.a = {b: this}
    this.c = this;
    this.d = [this];
  }
}

const a = new A();

const ret = _utils.detectRecursiveObject(a);
console.log(ret)
// => ['a.b', 'c', 'd.0']

```

## Include JSON (`includeJSON`)

```
const _utils = require('@taharactrl/utils');

const jsonA = {
  a1: "hoge",
  a2: "foo",
  a3: [123],
};

const jsonB = {
  a1: "hoge",
  a2: "foo",
};

const ret1 = _utils.includeJSON(jsonA, jsonB)
console.log(ret1)
// => true

const ret2 = _utils.includeJSON(jsonB, jsonA)
console.log(ret2)
// => false
```

## Equal JSON (`equalJSON`)

```
const _utils = require('@taharactrl/utils');

const jsonA = {
  a1: "hoge",
  a2: "foo",
  a3: [123],
};

const jsonB = {
  a1: "hoge",
  a2: "foo",
};

const jsonC = {
  a1: "hoge",
  a2: "foo",
  a3: [123],
};

const ret1 = _utils.equalJSON(jsonA, jsonB)
console.log(ret1)
// => false

const ret2 = _utils.equalJSON(jsonA, jsonC)
console.log(ret2)
// => true
```

## Merge objects (`mergeObjects`)

```
const _utils = require('@taharactrl/utils');

let jsonA = {
  a1: "hoge",
  a2: "foo",
  a3: [123],
};

const jsonB = {
  a1: "hoge",
  a2: "hei",
  a4: [234],
};

const mergedObject = _utils.equalJSON(jsonA, jsonB)
console.log(mergedObject);
// => { "a1": "hoge", "a2": "hei", "a3": [123], "a4": [234]}

// if you want to apply the results to the original object.
jsonA = _utils.equalJSON(jsonA, jsonB)
```

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