alwz
Version:
Extendable library for typecasting
37 lines • 1.03 kB
JavaScript
import EV from './ErrorValue.mjs';
import { TypesEnum } from '../constants/types.mjs';
export default {
type: (type) => {
if (type in TypesEnum) {
return ((input) => typeof input === type);
}
else {
throw new EV('unknown type', type);
}
},
instance: (prototype) => {
if ((typeof prototype === 'object' && prototype !== null) || typeof prototype === 'function') {
return ((input) => input instanceof prototype);
}
else {
throw new EV('invalid prototype', prototype);
}
},
variant: (list) => {
if (Array.isArray(list)) {
return ((input) => list.includes(input));
}
else {
throw new EV('invalid variants list', list);
}
},
check: (guard) => {
if (typeof guard === 'function') {
return guard;
}
else {
throw new EV('invalid guard', guard);
}
},
};
//# sourceMappingURL=Is.mjs.map