ts-time-format/TemporalFormatter
Consumption
import TemporalFormatter, {TemporalFormatComponent, LiteralFormatComponent, CompiledFormatComponent} from "ts-time-format/TemporalFormatter";
Default export#
Hierarchy#
Description#
T Type to format.
Date/time-related type string formatter. The result equals to concatenation of
write method call results on all
components. You may specify components explicitly by using 'of' method of a respective subclass, or implicitly
by using 'ofPattern' method of a respective subclass to parse a string pattern.
Constructor#
new TemporalFormatter<T> (components: TemporalFormatComponent <T >[])
components Sequence of components representing the formatter.
Methods#
format#
(value: T , context?: any): string
value Value to format.
context Context object (see TemporalCompiler ).
returns Formatted string.
Formats
value to a string as concatenation of
write method call results on all components.
TemporalFormatComponent#
Hierarchy#
Description#
T Type to format.
A single component of
TemporalFormatter . May represent a fixed literal (
LiteralFormatComponent ) or a
value-dependent part (
CompiledFormatComponent ).
Methods#
write#
(value: T , context: any): string
value Value to format.
context Context object (see TemporalCompiler ).
returns Formatted part.
Formats
value to a string based on concrete implementation.
LiteralFormatComponent#
Hierarchy#
Description#
T Type to format.
Implementation of
TemporalFormatComponent that returns a fixed literal.
Constructor#
new LiteralFormatComponent<T> (literal: string)
literal Literal to return.
Methods#
(value: T , context: any): string
value Value to format.
context Context object (see TemporalCompiler ).
returns Formatted part.
Formats
value to a string based on concrete implementation.
CompiledFormatComponent#
Hierarchy#
Description#
T Type to format.
Implementation of
TemporalFormatComponent that uses
TemporalCompiler to compile the result.
Constructor#
new CompiledFormatComponent<T> (compiler: TemporalCompiler <T >, length: number)
compiler Compiler to use.
length Length to use during compilation (see TemporalCompiler ).
Methods#
(value: T , context: any): string
value Value to format.
context Context object (see TemporalCompiler ).
returns Formatted part.
Formats
value to a string based on concrete implementation.
© Copyright: Egor Nepomnyaschih