Author: | rinxun |
---|---|
Views Total: | 14 views |
Official Page: | Go to website |
Last Update: | September 21, 2023 |
License: | MIT |
Preview:

Description:
check-equal is a JavaScript/TypeScript library to check if two values are equal, with configurable strict or loose equality checking.
This library meticulously checks for equality, including type, whether you’re inspecting arrays, strings, numbers, b0oleans, JSON, functions, or other objects.
By default, check-equal uses strict equality via triple equals (===) to compare values and type. But it also allows switching to loose equality (==) to ignore types.
How to use it:
1. Install and import the check-equal.
# Yarn $ yarn @rinxun/check-equal
# NPM
$ npm i @rinxun/check-equal
import { checkEqual } from '@rinxun/check-equal';
// require.js const { checkEqual } = require('@rinxun/check-equal')
2. The main checkEqual()
function in check-equal accepts two objects to compare and a strictMode parameter. The strictMode defaults to true for using === but can be set to false to use == instead.
// checkEqual(a, b, strictMode) // => true checkEqual(1, 1) // => false checkEqual(1, 2) // => true checkEqual('css', 'css') // => false checkEqual('css', 'script') // => true checkEqual('1', 1, false) // => false checkEqual('1', 1) // => true checkEqual(false, false) // => false checkEqual(false, true) // => true checkEqual(['css', 'script', 'com'], ['css', 'script', 'com']) // => false checkEqual(['css', 'script', 'com'], ['css', 'script', 'net']) // => true checkEqual( { a: 'css', b: 1, c: false, d: [1, 2, 3, 4] }, { a: 'css', b: 1, c: false, d: [1, 2, 3, 4] } ) // => false checkEqual( { a: 'css', b: 1, c: false, d: [1, 2, 3, 4] }, { a: 'css', b: 2, c: false, d: [1, 2, 3, 4] } )