UNPKG

zerobounce

Version:
29 lines (28 loc) 748 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.fromAnyWithMapping = exports.ResponseMapping = void 0; class ResponseMapping { constructor(field, setter) { this.field = field; this.setter = setter; } } exports.ResponseMapping = ResponseMapping; const fromAnyWithMapping = (object, result, mapping) => { if (typeof object !== 'object') { return null; } let counter = 0; for (const map of mapping) { if (!object.hasOwnProperty(map.field)) { continue; } map.setter(object, result); counter++; } if (counter === 0) { return null; } return result; }; exports.fromAnyWithMapping = fromAnyWithMapping;