Skip to content

dominikj111/simple-comparator

Repository files navigation

GitHub version Coverage Status dependency status contributions welcome

What is it?

The JS/TS utility to confirm deep equality of two simple objects, arrays or simple data type, to be used in Deno and Node.js.

The bahaviour match the toEqual() matcher function of the Jest library.

The orignal inspiration went from the issue in React.js application I had, where the useEffect triggered change to the global context of changed variable, but with same content.

Ready to be used in Deno and Node.js. To see more details how to use it, please check related unit tests in ./src/*.spec.ts and tests in ./tests folder.

Deno example

deno test https://raw.githubusercontent.com/dominikj111/simple-comparator/main/tests/deno.test.ts or

deno test https://raw.githubusercontent.com/dominikj111/simple-comparator/main/tests/deno.test.js

How to get it on Node.js or Bun

npm i simple-comparator, bun add simple-comparator

bun test doesn't work as expected with this library as there are Deno tests included and bun can't resolve the assert_equals module.

Problems to solve

As a develoer, I want:

  • To deeply compare two objects, arrays or simple data type.
import { same, diff, compare } from "simple-comparator/index";

...

React.useEffect(() => {
    if (diff(state.var_1, state.var_2)) {
        // do some action
    }
}, [ state.var_1, state.var_2 ]);

...

Possible improvements when requested

🔲 Add bundling to import from CDN (vanilla js) -> umd, esm

🔲 Improve Continuous Integration (automatic build, linting and testing)

🔲 Add Changelog, Code of Conduct

About

The JS/TS utility to compare two simple objects, arrays or simple data type.

Resources

License

Stars

Watchers

Forks

Packages

No packages published