UNPKG

playwright-fluent

Version:
99 lines (98 loc) 3.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.areSameTypeOfObjects = exports.areSameValueType = exports.areBothFunctions = exports.isFunctionType = exports.isValueType = exports.areEquivalentArray = exports.areSameType = void 0; function areSameType(obj1, obj2) { if (obj1 === obj2) { return true; } if (isValueType(obj1)) { return areSameValueType(obj1, obj2); } if (isFunctionType(obj1)) { return areBothFunctions(obj1, obj2); } if (Array.isArray(obj1)) { return areEquivalentArray(obj1, obj2); } if (areSameTypeOfObjects(obj1, obj2)) { return true; } return false; } exports.areSameType = areSameType; function areEquivalentArray(obj1, obj2) { if (!Array.isArray(obj2)) { return false; } const length1 = obj1.length; const length2 = obj2.length; const length = Math.min(length1, length2); for (let i = 0; i < length; i++) { const isItemTypeFoundInSecondArray = obj2.some((item) => areSameType(obj1[i], item)); if (!isItemTypeFoundInSecondArray) { return false; } } return true; } exports.areEquivalentArray = areEquivalentArray; function isValueType(obj) { return (typeof obj === 'number' || typeof obj === 'string' || typeof obj === 'boolean' || obj === null || obj === undefined); } exports.isValueType = isValueType; function isFunctionType(obj) { return typeof obj === 'function'; } exports.isFunctionType = isFunctionType; function areBothFunctions(obj1, obj2) { return isFunctionType(obj1) && isFunctionType(obj2); } exports.areBothFunctions = areBothFunctions; function areSameValueType(value1, value2) { if (value1 === null && value2 === null) { return true; } if (value1 === undefined && value2 === undefined) { return true; } if (typeof value1 === 'string' && typeof value2 === 'string') { return true; } if (typeof value1 === 'number' && typeof value2 === 'number') { return true; } if (typeof value1 === 'boolean' && typeof value2 === 'boolean') { return true; } return false; } exports.areSameValueType = areSameValueType; function areSameTypeOfObjects(obj1, obj2) { if (typeof obj1 === 'object' && typeof obj2 !== 'object') { return false; } if (typeof obj1 !== 'object' && typeof obj2 === 'object') { return false; } const obj1Properties = Object.getOwnPropertyNames(obj1); const obj2Properties = Object.getOwnPropertyNames(obj2); if (obj1Properties.length !== obj2Properties.length) { return false; } for (let index = 0; index < obj1Properties.length; index++) { const key = obj1Properties[index]; // eslint-disable-next-line @typescript-eslint/no-explicit-any const child1 = obj1[key]; // eslint-disable-next-line @typescript-eslint/no-explicit-any const child2 = obj2[key]; if (!areSameType(child1, child2)) { return false; } } return true; } exports.areSameTypeOfObjects = areSameTypeOfObjects;