import { any, arrayOf, boolean, deferred, dictionary, every, guard, instanceOf, isFunction, literal, literals, natural, number, object, Parser, partial, recursive, regex, shape, some, string, tuple, ValidatorError } from "./parsers/index"; import { parserName } from "./parsers/named"; import { unknown } from "./parsers/simple-parsers"; export type { IParser, ParserNames } from "./parsers/interfaces"; export { Parser as Validator }; export type { ValidatorError }; export type Fn = (a: A) => B; export type ValueOrFunction = ((a: In) => Out) | Out; export type ParserOrLiteral = ExtendsSimple | Parser; export type Primative = string | number | boolean | null | undefined; export type ExtendsSimple = A extends string | number | boolean | null | undefined ? A : never; export type WhenArgsExclude = A extends [ValueOrFunction] ? T extends unknown ? any : T : A extends ([ ...ParserOrLiteral[], ValueOrFunction ]) ? In : never; type _ = A; type ExcludePrimative = Exclude>>; export type WhenArgs = [ValueOrFunction] | [...ParserOrLiteral[], ValueOrFunction]; interface _WhenFn { (...args: WhenArgs): _, Out | B>>; } export type WhenFn = [In] extends [never] ? never : _WhenFn; export type WhenArgsOutput = A extends [ValueOrFunction] ? V : A extends ([ ...ParserOrLiteral[], ValueOrFunction ]) ? Out : never; export type UnwrapFn = [ In ] extends [never] ? () => OutcomeType : never; export interface ChainMatches { when: WhenFn; defaultTo(value: B): B | OutcomeType; defaultToLazy(getValue: () => B): B | OutcomeType; unwrap: UnwrapFn; } declare class MatchMore implements ChainMatches { private a; constructor(a: unknown); when: WhenFn; defaultTo(value: B): B; defaultToLazy(getValue: () => B): B; unwrap: UnwrapFn; } declare const array: typeof arrayOf & Parser; /** * Want to be able to bring in the declarative nature that a functional programming * language feature of the pattern matching and the switch statement. With the destructors * the only thing left was to find the correct structure then move move forward. * Using a structure in chainable fashion allows for a syntax that works with typescript * while looking similar to matches statements in other languages * * Use: matches('a value').when(matches.isNumber, (aNumber) => aNumber + 4).defaultTo('fallback value') */ export declare const matches: ((value: Ins) => MatchMore) & { array: typeof arrayOf & Parser; arrayOf: typeof arrayOf; some: typeof some; tuple: typeof tuple; regex: (tester: RegExp) => Parser; number: Parser; natural: Parser; isFunction: Parser; object: typeof shape & Parser; string: Parser; shape: typeof shape; partial: (testShape: { [key in keyof A]: Parser; }) => Parser>; literal: typeof literal; every: typeof every; guard: typeof guard; unknown: Parser; any: Parser; boolean: Parser; dictionary: , Parser][]>(...parsers: ParserSets) => Parser>>; literals: typeof literals; nill: Parser; instanceOf: (classCreator: { new (...args: any[]): C; }) => Parser; Parse: typeof Parser; parserName: typeof parserName; recursive: typeof recursive; deferred: typeof deferred; }; declare const nill: Parser; declare const Parse: typeof Parser; declare const oneOf: typeof some; declare const anyOf: typeof some; declare const allOf: typeof every; export { allOf, any, anyOf, array, arrayOf, boolean, deferred, dictionary, every, guard, instanceOf, isFunction, literal, literals, natural, nill, number, object, oneOf, Parse, Parser, parserName, partial, recursive, regex, shape, some, string, tuple, unknown, }; export default matches;