Skip to content

Commit

Permalink
In the name of God
Browse files Browse the repository at this point in the history
  • Loading branch information
mirismaili committed Dec 9, 2020
0 parents commit abf8d59
Show file tree
Hide file tree
Showing 7 changed files with 3,821 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
@@ -0,0 +1,10 @@
root = true

[*]
charset = utf-8
indent_style = tab
indent_size = 3
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
ij_javascript_enforce_trailing_comma = whenmultiline
22 changes: 22 additions & 0 deletions .gitignore
@@ -0,0 +1,22 @@
# dependencies
node_modules/

# builds
build/
dist/
.rpt2_cache

# misc
.DS_Store
.env
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*

# IDEs:
.idea/
21 changes: 21 additions & 0 deletions LICENSE
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 S. Mahdi Mir-Ismaili

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
52 changes: 52 additions & 0 deletions README.md
@@ -0,0 +1,52 @@
# deep-equal

> **Compare javascript objects (`{}`) DEEPLY (recursively). It also compares other types regularly.**
<p dir="auto">
<a href="https://npmjs.com/package/@rahazad/deep-equal">
<img alt="npm (scoped)" src="https://img.shields.io/npm/v/@rahazad/deep-equal.svg">
</a>
<a href="https://packagephobia.now.sh/result?p=@rahazad/deep-equal">
<img src="https://packagephobia.now.sh/badge?p=@rahazad/deep-equal" alt="install size">
</a>
<a href="https://npmjs.com/package/@rahazad/deep-equal">
<img alt="npm" src="https://img.shields.io/npm/dt/@rahazad/deep-equal.svg">
</a>
<br>
<a href="https://david-dm.org/Rahazad/deep-equal.js">
<img src="https://david-dm.org/Rahazad/deep-equal.js.svg" alt="Dependencies Status">
</a>
<a href="https://david-dm.org/Rahazad/deep-equal.js?type=dev">
<img src="https://david-dm.org/Rahazad/deep-equal.js/dev-status.svg" alt="devDependencies Status">
</a>
<br>
<a href="https://github.com/Rahazad/deep-equal.js/blob/master/LICENSE">
<img alt="GitHub" src="https://img.shields.io/github/license/Rahazad/deep-equal.js.svg">
</a>
<a href="https://github.com/Rahazad/deep-equal.js/fork">
<img src="https://img.shields.io/github/forks/Rahazad/deep-equal.js.svg?style=social" alt="GitHub forks">
</a>
<a href="https://github.com/Rahazad/deep-equal.js">
<img src="https://img.shields.io/github/stars/Rahazad/deep-equal.js.svg?style=social" alt="GitHub stars">
</a>
</p>

## Installation

```bash
npm i @rahazad/deep-equal
```

or using `yarn`:

```bash
yarn add @rahazad/deep-equal
```

## Usage

Coming ...

## License

MIT © [Mir-Ismaili](https://github.com/mirismaili)
48 changes: 48 additions & 0 deletions package.json
@@ -0,0 +1,48 @@
{
"name": "@rahazad/deep-equal",
"version": "0.0.0",
"description": "Compare javascript objects (`{}`) DEEPLY (recursively). It also compares other types regularly.",
"keywords": [
"javascript",
"js",
"object",
"objects",
"{}",
"[object Object]",
"equality",
"deep-compare",
"deep-compare-objects",
"recursive-compare",
"recursive-compare-objects"
],
"homepage": "https://github.com/Rahazad/deep-equal.js#readme",
"bugs": {
"url": "https://github.com/Rahazad/deep-equal.js/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/Rahazad/deep-equal.js.git"
},
"license": "MIT",
"author": "S. M. Mir-Ismaili <s.m.mirismaili@gmail.com>",
"type": "module",
"main": "dist/index.js",
"module": "dist/index.modern.js",
"source": "src/index.js",
"files": [
"dist"
],
"scripts": {
"build": "microbundle-crl --no-compress --format modern,cjs",
"prepare": "run-s build",
"start": "microbundle-crl watch --no-compress --format modern,cjs"
},
"dependencies": {},
"devDependencies": {
"microbundle-crl": "^0.13.11",
"npm-run-all": "^4.1.5"
},
"engines": {
"node": ">=10"
}
}
38 changes: 38 additions & 0 deletions src/index.js
@@ -0,0 +1,38 @@
/**
* Created on 1399/9/19 (2020/12/9).
* @author {@link https://mirismaili.github.io S. Mahdi Mir-Ismaili}
*/

export const deepEqual = (var1, var2) => {
if (var1 === var2) return true

const prototype = Object.prototype.toString.call(var1)

if (prototype !== Object.prototype.toString.call(var2)) return false

if (prototype === '[object Object]') {
if (Object.keys(var1).length !== Object.keys(var2).length) return false

for (const key in var1) {
if (!(key in var2)) return false

// noinspection JSUnfilteredForInLoop
if (!deepEqual(var1[key], var2[key])) return false
}

return true
}

if (var1 instanceof Array) {
if (var1.length !== var2.length) return false

for (let i = 0; i < var1.length; i++)
if (!(deepEqual(var1[i], var2[i]))) return false

return true
}

return false
}

export default deepEqual

0 comments on commit abf8d59

Please sign in to comment.