https://github.com/bartekleon/params-equal
Checks if two elements are really equal
https://github.com/bartekleon/params-equal
equal-objects fast is-equal isequal lib typescript
Last synced: 3 months ago
JSON representation
Checks if two elements are really equal
- Host: GitHub
- URL: https://github.com/bartekleon/params-equal
- Owner: bartekleon
- License: mit
- Created: 2018-09-07T19:16:10.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-03-03T21:44:27.000Z (about 3 years ago)
- Last Synced: 2024-12-31T00:42:35.088Z (5 months ago)
- Topics: equal-objects, fast, is-equal, isequal, lib, typescript
- Language: TypeScript
- Size: 115 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# param-type [](https://www.npmjs.com/package/params-equal)
Is function() {} = function() {}? Or {} = {}? "hello" = new String("hello")?
Now they are. **params-equal** checks if two given parameters are equal and works for cases, other programs do not check. Optimalised to be **as fast as it is possible** and **tested** to work as intended.## Install
Install with [npm](https://www.npmjs.com/):
```sh
$ npm install --save params-equal
``````js
import paramsEqual from 'params-equal';
or
const paramsEqual = require('params-equal').default;paramsEqual(NaN, NaN) //=> true
paramsEqual(NaN, 0 / 0) //=> true
paramsEqual(null, null) //=> true
paramsEqual(true, true) //=> true
paramsEqual(true, false) //=> false
paramsEqual("", "") //=> true
paramsEqual("", "hi") //=> false
paramsEqual(2, 2) //=> true
paramsEqual(2, 4) //=> false
paramsEqual(2, "4") //=> false
paramsEqual(-0, +0) // => false
paramsEqual(Infinity, Infinity) // => true
paramsEqual(Infinity, 1 / 0) // => true
paramsEqual(-0, -0)) // => true
paramsEqual(/a/g, /a/g) //=> true
paramsEqual(/a/g, /a/u) //=> false
paramsEqual(/b/g, /a/g) //=> false
paramsEqual(/a/g, new RegExp('a', 'g')) //=> true
paramsEqual(Symbol(12), Symbol(12)) //=> true
paramsEqual(Symbol(12), Symbol("12")) //=> true
paramsEqual(Symbol(12), Symbol(6)) //=> false
paramsEqual(new Boolean(true), new Boolean(true)) //=> true
paramsEqual(new Boolean(true), new Boolean(false)) //=> false
paramsEqual(new Object(), new Object()) //=> true
paramsEqual([], []) //=> true
paramsEqual([1], []) //=> false
paramsEqual({}, []) //=> false
paramsEqual(function() {}, function() {}) //=> true
paramsEqual(function hi() {}, function() {}) //=> false
paramsEqual(() => {}, function() {}) //=> false
paramsEqual(function() {}, function() {return false; }) //=> false
paramsEqual(async function() {}, function() {}) //=> false
paramsEqual(new Date(), new Date(1256252)) //=> false
paramsEqual({ hi: { hello: 1 } }, { hi: { hello: "1" } }) //=> false
paramsEqual([{ hi: "hello" }, "hi"], [{ hi: "hello" }, "hi"]) //=> true
paramsEqual({
log: [],
set yo(name: string) {
this.log.push(name);
},
get yo() {
return "this is set";
}
},
{
log: [],
get yo() {
return "this is set";
}
}) //=> falseparamsEqual({
log: [],
yo: "this is set"
},
{
log: [],
get yo() {
return "this is set";
}
}) //=> falseparamsEqual({
log: [],
set yo(name: string) {
this.log.push(name);
},
get yo() {
return "this is set";
}
},
{
log: [],
set yo(name: string) {
this.log.push(name);
},
get yo() {
return "this is set";
}
}) //=> trueconst a = { hi: "hello", s: {} };
const b = { hi: "hello", s: {} };
const c = { hi: "h", c: {} };c.c = c;
a.s = a;
b.s = c;
paramsEqual(a, b) //=> RangeError("You are not allowed to create infinite nest")
```## Test
- Unit tests:
```sh
$ npm install && npm test
```### Author
**kmdrGroch**
### License
Copyright © 2018, [kmdrGroch](https://github.com/kmdrgroch).
Released under the [MIT License](LICENSE).### Note
The code will work for node >= 8, although there is a possibility that development tools won't work for some versions.