UNPKG

@intuitionrobotics/thunderstorm

Version:
28 lines 1.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.assertProperty = void 0; const exceptions_1 = require("../exceptions"); const assertProperty = (instance, key, statusCode = 400, check) => { if (Array.isArray(key)) return key.forEach(k => (0, exports.assertProperty)(instance, k, statusCode, check)); const _key = key; const value = instance[_key]; if (!value) throw new exceptions_1.ApiException(statusCode, `Missing <strong>${String(key)}</strong>`); if (!check) return; if (typeof value === "number") return; if (typeof value === "string") { if (typeof check === "string") { if (value.match(check)) return; throw new exceptions_1.ApiException(statusCode, `Value <strong>${value}</strong> doesn't match with check: ${check}`); } return check(value); } if (typeof value === "object" && typeof check === "function") check(value); }; exports.assertProperty = assertProperty; //# sourceMappingURL=to-be-removed.js.map