UNPKG

ts-cast

Version:
15 lines (14 loc) 765 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var names_1 = require("../helpers/names"); var throw_type_error_1 = require("./throw-type-error"); var required = function (typeName, typeGuard, transform) { return (0, names_1.withName)(function (value, context, reportError) { if (reportError === void 0) { reportError = throw_type_error_1.throwTypeError; } if (value === undefined || !typeGuard(value)) { return reportError("".concat(typeName, " is expected").concat(context ? " in ".concat(context) : '', " but \"").concat(value, "\" received."), context); } return (typeof transform === 'function' ? transform(value, context, reportError) : value); }, typeName); }; exports.default = required;