Skip to main content Link Search Menu Expand Document (external link)

TemplateParser overview

This module implements a CVTemplateParser, i.e. an object that is capable of converting a string to a record of values according to the CVTemplate that was used to construct it. If you don’t want to build a CVTemplate beforehand, you can also construct a CVTemplateParser directly from CVTemplatePart’s


Table of contents


Constructors

fromTemplate

Constructor of a CVTemplateParser from a CVTemplate

Signature

export declare const fromTemplate: typeof Type.fromTemplate

fromTemplateParts

Constructor of a CVTemplateParser directly from CVTemplateParts

Signature

export declare const fromTemplateParts: typeof Type.fromTemplateParts

Models

Type (class)

Type that represents a CVTemplateParser

Signature

export declare class Type<PlaceholderTypes> {
  private constructor({ description, parse, parseOrThrow }: MTypes.Data<Type<PlaceholderTypes>>)
}

make (static method)

Class constructor

Signature

private static make({
    syntheticDescription,
    placeholderDescription,
    templateParts,
  }: {
    readonly syntheticDescription: string;
    readonly placeholderDescription: string;
    readonly templateParts: CVTemplateParts.Type;
  }): Type<never>

fromTemplate (static method)

Constructor of a CVTemplateParser from a template

Signature

static fromTemplate<PlaceholderTypes extends MTypes.Object>(
    template: CVTemplate.Type<PlaceholderTypes>,
  ): Type<PlaceholderTypes>

fromTemplateParts (static method)

Constructor of a CVTemplateParser directly from CVTemplateParts

Signature

static fromTemplateParts<const PS extends CVTemplateParts.Type>(
    ...templateParts: PS
  ): Type<CVTemplateParts.ToPlaceHolderTypes<PS>>

[MData.idSymbol] (method)

Returns the id of this

Signature

[MData.idSymbol](): string | (() => string)

description (property)

Description of this CVTemplateParser

Signature

readonly description: string

parse (property)

Function that tries to parse a text according to the template passed to build this parser

Signature

readonly parse: MTypes.OneArgFunction<string, Result.Result<PlaceholderTypes, MInputError.Type>>

parseOrThrow (property)

Same as parse but throws in case of failure

Signature

readonly parseOrThrow: MTypes.OneArgFunction<string, PlaceholderTypes>

Module markers

moduleTag

Module tag

Signature

export declare const moduleTag: "@parischap/conversions/formatting/template/TemplateParser/"

Parsing

parse

Returns the parser property of self.

Signature

export declare const parse: <PlaceholderTypes extends MTypes.Object>(
  self: Type<PlaceholderTypes>
) => Type<PlaceholderTypes>["parse"]

parseOrThrow

Returns the parseOrThrow property of self.

Signature

export declare const parseOrThrow: <PlaceholderTypes extends MTypes.Object>(
  self: Type<PlaceholderTypes>
) => Type<PlaceholderTypes>["parseOrThrow"]