UNPKG

1.88 kBTypeScriptView Raw
1import { ReferenceWithTimezone, ParsingComponents, ParsingResult } from "./results.js";
2import { Component, ParsedResult, ParsingOption, ParsingReference } from "./types.js";
3import { AsyncDebugBlock, DebugHandler } from "./debugging.js";
4import ENDefaultConfiguration from "./locales/en/configuration.js";
5export interface Configuration {
6 parsers: Parser[];
7 refiners: Refiner[];
8}
9export interface Parser {
10 pattern(context: ParsingContext): RegExp;
11 extract(context: ParsingContext, match: RegExpMatchArray): ParsingComponents | ParsingResult | {
12 [c in Component]?: number;
13 } | null;
14}
15export interface Refiner {
16 refine: (context: ParsingContext, results: ParsingResult[]) => ParsingResult[];
17}
18export declare class Chrono {
19 parsers: Array<Parser>;
20 refiners: Array<Refiner>;
21 defaultConfig: ENDefaultConfiguration;
22 constructor(configuration?: Configuration);
23 clone(): Chrono;
24 parseDate(text: string, referenceDate?: ParsingReference | Date, option?: ParsingOption): Date | null;
25 parse(text: string, referenceDate?: ParsingReference | Date, option?: ParsingOption): ParsedResult[];
26 private static executeParser;
27}
28export declare class ParsingContext implements DebugHandler {
29 readonly text: string;
30 readonly option: ParsingOption;
31 readonly reference: ReferenceWithTimezone;
32 readonly refDate: Date;
33 constructor(text: string, refDate?: ParsingReference | Date, option?: ParsingOption);
34 createParsingComponents(components?: {
35 [c in Component]?: number;
36 } | ParsingComponents): ParsingComponents;
37 createParsingResult(index: number, textOrEndIndex: number | string, startComponents?: {
38 [c in Component]?: number;
39 } | ParsingComponents, endComponents?: {
40 [c in Component]?: number;
41 } | ParsingComponents): ParsingResult;
42 debug(block: AsyncDebugBlock): void;
43}