1.0.1 • Published 1 year ago

json-eq v1.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

json-eq

use in ts

import equal from "json-eq";

// the same object

const obj1 = {
  key1: "Hello",
  key2: false,
};

const obj2 = {
  key1: "Hello",
  key2: false,
};

equal(obj1, obj2); // returns true

// not the same value

const obj1 = {
  key1: "Hello",
  key2: false,
};

const obj2 = {
  key1: "World",
  key2: 2,
};

equal(obj1, obj2); // returns false

use in js

import equal from "json-eq";

// the same object

const obj1 = {
  key1: "Hello",
  key2: false,
};

const obj2 = {
  key1: "Hello",
  key2: false,
};

equal(obj1, obj2); // returns true

// not the same value

const obj1 = {
  key1: "Hello",
  key2: false,
};

const obj2 = {
  key1: "World",
  key2: 2,
};

equal(obj1, obj2); // returns false

install

npm i json-eq

Code

ts

export default function equal<T1, T2>(obj1: T1, obj2: T2) {
  return JSON.stringify(obj1) === JSON.stringify(obj2);
}

js

export default function equal(obj1, obj2) {
    return JSON.stringify(obj1) === JSON.stringify(obj2)
}
1.0.1

1 year ago

1.0.0

1 year ago