mockaton
Version:
HTTP Mock Server
9 lines (7 loc) • 311 B
JavaScript
export function validate(obj, shape) {
for (const [field, value] of Object.entries(obj))
if (!shape[field](value))
throw new TypeError(`${field}=${JSON.stringify(value)} is invalid`)
}
export const is = ctor => val => val.constructor === ctor
export const optional = tester => val => !val || tester(val)