UNPKG

ts-cast

Version:
9 lines (8 loc) 386 B
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;