1.0.8 • Published 5 months ago

equal-checker v1.0.8

Weekly downloads
-
License
ISC
Repository
github
Last release
5 months ago

Install

npm install equal-checker

Usage

const equalChecker = require('equal-checker');

let objectOne = {
    name : 'foo',
    note : 'bar',
    object: {a: 1, b: [1, {diff: 2}]},      // 2 as int
    array : [1, 2, 3],
};

let objectTwo = {
    name : 'foo',
    note : 'bar',
    object: {a: 1, b: [1, {diff: '2'}]},    // 2 as string
    array : [1, 2, 3]
};


let result;
// Type checking OFF
result = equalChecker(objectOne, objectTwo);
console.log(result);   // true

// Type checking ON
result = equalChecker(objectOne, objectTwo, true);
console.log(result);   // false

// Error-Message ON
result = equalChecker(objectOne, objectTwo, true , true);
console.log(result);   // [ false , '2 and 2 : different values or types'];

Infos

The equalChecker() function takes 4 arguments:

  • Value 1
  • Value 2
  • Boolean for type checking (optional - default = false)
  • Boolean for error messages (optional - default = false)

If third argument (typeCheck) is set to true:
  • will compare values AND data type.
If fourth argument (errMsg) is set to true & the check returns false:
  • will, instead of returning only a boolean, return an Array.
  • the array will contain 0 the false boolean and 1 an error message explaining the difference.
1.0.8

5 months ago

1.0.7

8 months ago

1.0.6

8 months ago

1.0.5

8 months ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago