@toreda/strong-types
Version:
Better TypeScript code in fewer lines.
22 lines (21 loc) • 688 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.typeValue = void 0;
/**
* Validate `value` a valid type_T and return it if valid, otherwise
* return `fallback`. Quick and easy way to validate configs, maps, and
* other objects with a guaranteed return type.
* @param typeName JavaScript type name for expected type.
* @param value Value to be validated as `typeName`.
* @param fallback Value returned when `value` is not a valid type_T.
* @returns
*
* @category Core
*/
function typeValue(typeName, value, fallback) {
if (typeof value !== typeName) {
return fallback;
}
return value;
}
exports.typeValue = typeValue;