ts-cast
Version:
Runtime typechecking
9 lines (8 loc) • 386 B
JavaScript
import { withName } from '../helpers/names';
import { isNotEmpty } from './guards';
import { throwTypeError } from './throw-type-error';
const map = (caster, transform) => withName((value, context, reportError = throwTypeError) => {
const casted = caster(value, context, reportError);
return isNotEmpty(casted) ? transform(casted) : casted;
}, caster.name);
export default map;