UNPKG

statement-parser-fab

Version:

Parse bank and credit card statements. Updated fork with FAB (First Abu Dhabi Bank) support and maintained dependencies.

25 lines (24 loc) 2.44 kB
import { IfEquals } from 'augment-vir'; import { InitOutput, ParsedOutput } from './parsed-output'; import { SharedParserFunctionInputs } from './parser-function'; import { BaseParserOptions, CombineWithBaseParserOptions } from './parser-options'; export type performParseActionFunction<StateType, OutputType extends ParsedOutput, ParserOptions extends object | undefined = undefined> = (currentState: StateType, input: string, lastOutput: OutputType, parserOptions: CombineWithBaseParserOptions<ParserOptions>) => OutputType; export type nextParseStateFunction<StateType, ParserOptions extends object | undefined = undefined> = (currentState: StateType, input: string, parserOptions: CombineWithBaseParserOptions<ParserOptions>) => StateType; export type ParserInitInput<StateType, OutputType extends ParsedOutput, ParserOptions extends object | undefined = undefined> = { action: performParseActionFunction<StateType, OutputType, ParserOptions>; next: nextParseStateFunction<StateType, ParserOptions>; endState: StateType; initialState: StateType; initOutput?: Readonly<InitOutput<OutputType>>; defaultParserOptions?: IfEquals<ParserOptions, BaseParserOptions, undefined, Readonly<Required<ParserOptions>>>; }; export type CreateStateMachineInput<StateType, OutputType extends ParsedOutput, ParserOptions extends object | undefined = undefined> = ParserInitInput<StateType, OutputType, ParserOptions> & SharedParserFunctionInputs<ParserOptions>; export type StateMachineParserFunction<OutputType extends ParsedOutput> = (inputs: Readonly<string[]>) => Readonly<OutputType>; /** * This creates a state machine. The state machine is a Mealy machine but outputs are generated * independent of the state transition. As you can see in the arguments, the "action" function * (which generates outputs) is distinct from the "next" function, which calculates the next state. * The implementation of "action" is of course left to you though, so you can totally just ignore * the current value and make this a Moore machine. */ export declare function createParserStateMachine<StateType, OutputType extends ParsedOutput, ParserOptions extends object | undefined = undefined>({ action, next, initialState, endState, name, initOutput, parserOptions: inputParserOptions, defaultParserOptions, debug, }: Readonly<CreateStateMachineInput<StateType, OutputType, ParserOptions>>): StateMachineParserFunction<OutputType>;