yandex-cloud-functions-router
Version:
Node router for Yandex Cloud Functions
28 lines (27 loc) • 1.06 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.matchObjectPattern = void 0;
const matchObjectPattern = (data, pattern) => {
var _a;
for (const [patternPropName, patternPropValue] of Object.entries(pattern)) {
const dataEntries = Object.entries(data);
const [, dataPropValue] = (_a = dataEntries.find(([dataPropName, dataPropValue]) => dataPropName === patternPropName)) !== null && _a !== void 0 ? _a : [];
if (typeof patternPropValue === 'object' || typeof dataPropValue === 'object') {
if (typeof patternPropValue === 'object' && typeof dataPropValue === 'object') {
if (!matchObjectPattern(dataPropValue, patternPropValue)) {
return false;
}
}
else {
return false;
}
}
else {
if (dataPropValue !== patternPropValue) {
return false;
}
}
}
return true;
};
exports.matchObjectPattern = matchObjectPattern;