isequal.es
Version:
check if two parameters are equal, support es6+.
7 lines (6 loc) • 1.09 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).isEqual=t()}(this,(function(){"use strict";
/*!
* Check if two parameters are equal
* Author: Tyler.Chao
* github: https://github.com/cz848/dateio
*/const e=e=>null!==e&&("object"==typeof e||"function"==typeof e),t=e=>toString.call(e).replace(/\[object (.+)\]/,"$1").toLowerCase();return function r(n,o){if(!e(n)||!e(o))return Object.is(n,o);if(n.constructor!==o.constructor)return!1;const c=t(n);if(c!==t(o))return!1;let i;switch(c){case"array":case"arraybuffer":return n.length===o.length&&n.every((e,t)=>r(e,o[t]));case"set":case"map":return n.size===o.size&&[...n.entries()].every(([e,t])=>o.has(e)&&("map"!==c||r(t,o.get(e))));default:return n.valueOf!==Object.prototype.valueOf?n.valueOf()===o.valueOf():n.toString!==Object.prototype.toString?n.toString()===o.toString():(i=Object.keys(n),i.length===Object.keys(o).length&&i.every(e=>hasOwnProperty.call(o,e)&&r(n[e],o[e])))}}}));