@sprucelabs/schema
Version:
Static and dynamic binding plus runtime validation and transformation to ensure your app is sound. 🤓
21 lines (20 loc) • 644 B
JavaScript
import get from 'just-safe-get';
import SpruceError from '../errors/SpruceError.js';
export default function assertOptions(options, toCheck, friendlyMessage) {
const missing = [];
for (const check of toCheck) {
const value = get(options !== null && options !== void 0 ? options : {}, check);
//@ts-ignore
if (value === null || typeof value === 'undefined') {
missing.push(check);
}
}
if (missing.length > 0) {
throw new SpruceError({
code: 'MISSING_PARAMETERS',
parameters: missing,
friendlyMessage,
});
}
return options;
}