UNPKG

@citrineos/base

Version:

The base module for OCPP v2.0.1 including all interfaces. This module is not intended to be used directly, but rather as a dependency for other modules.

56 lines 1.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.assert = assert; exports.notNull = notNull; exports.deepDirectionalEqual = deepDirectionalEqual; function assert(predicate, message) { switch (typeof predicate) { case 'boolean': { if (!predicate) { throw new Error(message); } break; } case 'function': { if (!predicate()) { throw new Error(message); } break; } default: { // eslint-disable-next-line @typescript-eslint/no-unused-vars const exhaustiveCheck = predicate; } } } function notNull(object) { return object !== undefined && object !== null; } /** * Ensures that obj2 contains all keys from obj1. * @param obj1 * @param obj2 * @returns */ function deepDirectionalEqual(obj1, obj2, seenObjects = new WeakSet()) { if (obj1 === obj2) return true; if (typeof obj1 !== 'object' || obj1 === null || typeof obj2 !== 'object' || obj2 === null) { return false; } // Check if obj1 has already been seen to avoid cycles if (seenObjects.has(obj1)) { return true; // If we've already seen obj1, we assume it's equivalent. } // Add obj1 to the seen set seenObjects.add(obj1); const keys1 = Object.keys(obj1); const keys2 = Object.keys(obj2); for (const key of keys1) { if (!keys2.includes(key) || !deepDirectionalEqual(obj1[key], obj2[key], seenObjects)) { return false; } } return true; } //# sourceMappingURL=assertion.js.map