UNPKG

parjs

Version:

A parser-combinator library for JavaScript.

45 lines (44 loc) 1.18 kB
/** * @module parjs/internal * */ /** */ import { Parjser } from "./parjser"; /** * A {@link Parjser} or a literal value convertible to a {@link Parjser}. */ /** * @private * Should not be used from user code. Used to implement implicit parser literals. * @type {symbol} */ export declare const convertibleSymbol: unique symbol; /** * A literal type which is implicitly convertible to a parser. * This normally includes the `string` and `RegExp` types. */ export interface ConvertibleScalar<T> { [convertibleSymbol](): Parjser<T>; } declare global { interface String { [convertibleSymbol](): Parjser<string>; } interface RegExp { [convertibleSymbol](): Parjser<string[]>; } } /** * Either a Parjser or a scalar value convertible to one. * @module parjs */ export declare type ImplicitParjser<T> = Parjser<T> | ConvertibleScalar<T>; /** * A helper for working with implicit parsers. */ export declare namespace ScalarConverter { /** * Normalizes scalars and Parjsers into Parjsers. * @param scalarOrParjser The literal or parjser. */ function convert<V>(scalarOrParjser: ImplicitParjser<V>): Parjser<V>; }