Skip to content
/ jeck Public

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

Notifications You must be signed in to change notification settings

matschik/jeck

Repository files navigation

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:

npm i jeck

To use in browser, grab the jeck.umd.js file and add it to your page:

<script src="https://unpkg.com/jeck/dist/jeck.umd.js"></script>

Available in ESM, CJS and UMD formats.

Usage

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

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

About

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

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published