UNPKG

@intuitionrobotics/thunderstorm

Version:
24 lines 909 B
import { ApiException } from "../exceptions.js"; export const assertProperty = (instance, key, statusCode = 400, check) => { if (Array.isArray(key)) return key.forEach(k => assertProperty(instance, k, statusCode, check)); const _key = key; const value = instance[_key]; if (!value) throw new 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 ApiException(statusCode, `Value <strong>${value}</strong> doesn't match with check: ${check}`); } return check(value); } if (typeof value === "object" && typeof check === "function") check(value); }; //# sourceMappingURL=to-be-removed.js.map