Skip to content

Instantly share code, notes, and snippets.

@behnammodi
Created November 24, 2019 14:39
Show Gist options
  • Save behnammodi/3135758c12c47a240c5bf89fe6d053c6 to your computer and use it in GitHub Desktop.
Save behnammodi/3135758c12c47a240c5bf89fe6d053c6 to your computer and use it in GitHub Desktop.
import is from "is";
function ptf(fun, configs) {
if (is.array(configs))
return (...args) => {
configs.forEach((_, index) => {
if (configs[index](args[index]) === false)
throw new Error(
`${index} argument type is error, ${index} value is ${args[index]}`
);
});
return fun(...args);
};
else {
return args => {
Object.keys(args).forEach(key => {
if (configs[key](args[key]) === false)
throw new Error(`${key} type error, b value is ${args[key]}`);
});
return fun(args);
};
}
}
ptf.Number = is.number;
ptf.String = is.string;
export default ptf;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment