recursive-comparator

Compare variables of any type with customizable parameters


Keywords
library, comparation, variables, objects, array, object, map, set, date, string, number, comparator, data-structures, javascript
License
ISC
Install
npm install recursive-comparator@1.2.0

Documentation

Recursive Comparator

Fast optimized algorithm to compare two variables of any type in JavaScript. The algorithm supports recursive comparison with nested items and performs the operations in a comparative way - so that in case of differences it automatically returns "false" instead of continuing to compare. The order of elements is taken into account in any operation. The function also supports comparison functions that will dictate the behavior the comparator will use to check the data.

Versions

Version Branch
development main
1.2.1 Hotfix v1.2.1
1.2.0 v1.2.0
1.1.6 v1.1.6

Installation/Usage

Via NPM:

npm install recursive-comparator-js

Manually:

To get the script just clone that repository (or get the version in "Releases" section) and import "compare" from "recursiveComparator.js"

Usage without conditional function parameter:

compare([{a: 1}], [{a: 1}]); //(May be equal) True
compare([[1]], [[3]]); //(May be equal) False

With conditional function parameter:

compare([{a: 1}], [{a: 1}], (a, b) => !compare(a, b)); //(May pass in the function parameters) False
compare([{a: 1}], [{a: 1}], (a, b) => compare(a, b)); //(May pass in the function parameters) True

Information

Changelog - Test Results