alwz
Version:
Extendable library for typecasting
42 lines • 1.38 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const ErrorValue_js_1 = __importDefault(require("./ErrorValue.cjs"));
const types_js_1 = require("../constants/types.cjs");
exports.default = {
type: (type) => {
if (type in types_js_1.TypesEnum) {
return ((input) => typeof input === type);
}
else {
throw new ErrorValue_js_1.default('unknown type', type);
}
},
instance: (prototype) => {
if ((typeof prototype === 'object' && prototype !== null) || typeof prototype === 'function') {
return ((input) => input instanceof prototype);
}
else {
throw new ErrorValue_js_1.default('invalid prototype', prototype);
}
},
variant: (list) => {
if (Array.isArray(list)) {
return ((input) => list.includes(input));
}
else {
throw new ErrorValue_js_1.default('invalid variants list', list);
}
},
check: (guard) => {
if (typeof guard === 'function') {
return guard;
}
else {
throw new ErrorValue_js_1.default('invalid guard', guard);
}
},
};
//# sourceMappingURL=Is.cjs.map