handle-cli-error
Version:
💣 Error handler for CLI applications 💥
25 lines (17 loc) • 582 B
JavaScript
import isPlainObj from"is-plain-obj";
import{removeUndefined}from"./default.js";
export const applyClassesOpts=(name,opts={})=>{
if(!isPlainObj(opts)){
throw new Error(`options must be a plain object: ${opts}`)
}
const{classes={},...optsA}=opts;
validateObject(classes,"classes");
const classesOpts=classes[name]||classes.default||{};
validateObject(classesOpts,`classes.${name}`);
return{...optsA,...removeUndefined(classesOpts)}
};
export const validateObject=(value,optName)=>{
if(!isPlainObj(value)){
throw new Error(`"${optName}" must be a plain object: ${value}`)
}
};