UNPKG

ts-cast

Version:
7 lines (6 loc) 472 B
import { createCaster } from '../engine'; import { isAnObj } from '../engine/guards'; const prodTypeName = (schema) => schema.map(caster => caster.name).join(' & '); const mergeStructs = (schema) => (value, context, reportError) => schema.reduce((obj, caster) => Object.assign(obj, caster(value, context, reportError)), Object.create(null)); export const allOf = (...schema) => createCaster(prodTypeName(schema), isAnObj, mergeStructs(schema)); export const prod = allOf;