1//// [specedNoStackBlown.ts] 2// Type definitions for spected 0.7 3// Project: https://github.com/25th-floor/spected 4// Definitions by: Benjamin Makus <https://github.com/benneq> 5// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped 6// TypeScript Version: 2.8 7 8declare function spected<ROOTINPUT, SPEC extends SpecValue<ROOTINPUT, ROOTINPUT> = SpecValue<ROOTINPUT, ROOTINPUT>>(spec: SPEC, input: ROOTINPUT): Result<ROOTINPUT, SPEC>; 9 10type Predicate<INPUT, ROOTINPUT> = (value: INPUT, inputs: ROOTINPUT) => boolean; 11 12type ErrorMsg<INPUT> = 13 | (string | number | boolean | symbol | null | undefined | object) 14 | ((value: INPUT, field: string) => any); 15 16export type Spec<INPUT, ROOTINPUT = any> = [Predicate<INPUT, ROOTINPUT>, ErrorMsg<INPUT>]; 17 18export type SpecArray<INPUT, ROOTINPUT = any> = Array<Spec<INPUT, ROOTINPUT>>; 19 20export type SpecFunction<INPUT, ROOTINPUT = any> = [INPUT] extends [ReadonlyArray<infer U>] 21 ? (value: INPUT) => ReadonlyArray<SpecArray<U, ROOTINPUT>> 22 : [INPUT] extends [object] 23 ? (value: INPUT) => SpecObject<INPUT, ROOTINPUT> 24 : (value: INPUT) => SpecArray<INPUT, ROOTINPUT>; 25 26export type SpecObject<INPUT, ROOTINPUT = any> = Partial<{[key in keyof INPUT]: SpecValue<INPUT[key], ROOTINPUT>}>; 27 28export type SpecValue<INPUT, ROOTINPUT = any> = [INPUT] extends [ReadonlyArray<any>] 29 ? SpecArray<INPUT, ROOTINPUT> | SpecFunction<INPUT, ROOTINPUT> 30 : [INPUT] extends [object] 31 ? SpecArray<INPUT, ROOTINPUT> | SpecFunction<INPUT, ROOTINPUT> | SpecObject<INPUT, ROOTINPUT> 32 : SpecArray<INPUT, ROOTINPUT> | SpecFunction<INPUT, ROOTINPUT>; 33 34export type Result<INPUT, SPEC> = {[key in keyof INPUT]: true | any[] | Result<INPUT[key], any>}; 35 36export default spected; 37 38 39//// [specedNoStackBlown.js] 40"use strict"; 41// Type definitions for spected 0.7 42// Project: https://github.com/25th-floor/spected 43// Definitions by: Benjamin Makus <https://github.com/benneq> 44// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped 45// TypeScript Version: 2.8 46exports.__esModule = true; 47exports["default"] = spected; 48