An open API service indexing awesome lists of open source software.

https://github.com/matschik/jeck

Lightweight utility to compare two values: string, boolean, number, array, objects, null and undefined.
https://github.com/matschik/jeck

comparison equality validator

Last synced: 7 months ago
JSON representation

Lightweight utility to compare two values: string, boolean, number, array, objects, null and undefined.

Awesome Lists containing this project

README

          

# Jeck

> Small utility to compare string, boolean, number, array, objects (including deep nested), null and undefined.


size


size


npm version


npm version


license

## Why ?
I was looking for a lightweight library just showing if two values are different or not.
To keep it small:
- It does not show the diff, it's only returning a `boolean`.
- It does not support values like "Function" or "Regex" values. When value(s) is not supported, it returns `null`.

## Installation

Jeck works in both node.js and browser environments. For node, install with npm:

```bash
npm i jeck
```

To use in browser, grab the [jeck.umd.js](https://unpkg.com/jeck/dist/jeck.umd.js) file and add it to your page:

```html

```

Available in ESM, CJS and UMD formats.

## Usage

These examples assume you're in node.js, or something similar:

```js
const jeck = require("jeck");

// Primitive values
jeck(42, 17); // false
jeck(["orange", "apple", "ananas"], ["mango"]); // false
jeck(null, null); // true
jeck(undefined, undefined); // true

// Without array order tolerancy
jeck(["mango", true, 42], [42, "mango", true]); // false
// With array order tolerancy
jeck(["mango", true, 42], [42, "mango", true], { orderTolerant: true }); // true

// Object with nested structure
const deepA = {
a: { lot: { of: { nested: { levels: { in: { this: "object" } } } } } }
};
const deepB = {
a: { lot: { of: { nested: { levels: { in: { this: { object: true } } } } } } }
};
jeck(deepA, deepB); // false

// Array with nested structures
const arrayA = [{ type: "shadow" }, { type: "grass", isStrong: true }];
const arrayB = [{ type: "fire" }, { type: "water", isWeak: false }];

jeck(arrayA, arrayB); // false
```

Checkout more examples in: `__tests__/jeck.js`

## License

MIT