@types/mustache

  • Version 4.2.5
  • Published
  • 15.2 kB
  • No dependencies
  • MIT license

Install

npm i @types/mustache
yarn add @types/mustache
pnpm add @types/mustache

Overview

TypeScript definitions for mustache

Index

Variables

variable escape

let escape: EscapeFunction;
  • HTML escaping by default, can be overridden by setting Mustache.escape explicitly or providing the options argument with an escape function when invoking .

    Escaping can be avoided when needed by using {{{ value }}} or {{& value }} in templates.

    Parameter value

    The value to escape into a string.

variable name

const name: string;
  • The name of the module.

variable tags

let tags: OpeningAndClosingTags;
  • The default opening and closing tags used while parsing the templates.

    Different default tags can be overridden by setting this field. They will have effect on all subsequent calls to or , unless custom tags are given as arguments to those functions.

    Default value is [ "{{", "}}" ].

variable templateCache

let templateCache: TemplateCache;
  • Customise the template caching behaviour by either:

    disable it completely by setting it to undefined

    -- or --

    provide a custom cache strategy that satisfies the interface

variable version

const version: string;
  • The version of the module.

Functions

function clearCache

clearCache: () => void;
  • Clears all cached templates in this writer.

function parse

parse: (template: string, tags?: OpeningAndClosingTags) => TemplateSpans;
  • Parses and caches the given template in the default writer and returns the array of tokens it contains.

    Doing this ahead of time avoids the need to parse templates on the fly as they are rendered.

    Parameter template

    The template to parse.

    Parameter tags

    The tags to use.

function render

render: (
template: string,
view: any | Context,
partials?: PartialsOrLookupFn,
tagsOrOptions?: OpeningAndClosingTags | RenderOptions
) => string;
  • Renders the with the given and using the default writer.

    Parameter template

    The template to render.

    Parameter view

    The view to render the template with.

    Parameter partials

    Either an object that contains the names and templates of partials that are used in a template

    -- or --

    A function that is used to load partial template on the fly that takes a single argument: the name of the partial.

    Parameter tagsOrOptions

    The delimiter tags to use or options overriding global defaults.

Classes

class Context

class Context {}
  • Represents a rendering context by wrapping a view object and maintaining a reference to the parent context.

constructor

constructor(view: any, parentContext?: Context);
  • Initializes a new instance of the class.

property parent

parent: Context;

    property view

    view: any;

      method lookup

      lookup: (name: string) => any;
      • Returns the value of the given name in this context, traversing up the context hierarchy if the value is absent in this context's view.

        Parameter name

        The name to look up.

      method push

      push: (view: any) => Context;
      • Creates a new context using the given view with this context as the parent.

        Parameter view

        The view to create the new context with.

      class Scanner

      class Scanner {}
      • A simple string scanner that is used by the template parser to find tokens in template strings.

      constructor

      constructor(string: string);
      • Initializes a new instance of the class.

      property pos

      pos: number;

        property string

        string: string;

          property tail

          tail: string;

            method eos

            eos: () => boolean;
            • Returns true if the tail is empty (end of string).

            method scan

            scan: (re: RegExp) => string;
            • Tries to match the given regular expression at the current position.

              Parameter re

              The regex-pattern to match.

              Returns

              The matched text if it can match, the empty string otherwise.

            method scanUntil

            scanUntil: (re: RegExp) => string;
            • Skips all text until the given regular expression can be matched.

              Parameter re

              The regex-pattern to match.

              Returns

              Returns the skipped string, which is the entire tail if no match can be made.

            class Writer

            class Writer {}
            • A Writer knows how to take a stream of tokens and render them to a , given a context.

              It also maintains a cache of templates to avoid the need to parse the same template twice.

            constructor

            constructor();
            • Initializes a new instance of the class.

            method clearCache

            clearCache: () => void;
            • Clears all cached templates in this writer.

            method escapedValue

            escapedValue: (
            token: string[],
            context: Context,
            config?: RenderOptions
            ) => string;
            • Renders an escaped value.

              Parameter token

              The token to render.

              Parameter context

              The context to use for rendering the token.

              Parameter config

              The options for the rendering process.

            method indentPartial

            indentPartial: (
            partial: string,
            indentation: string,
            lineHasNonSpace: boolean
            ) => string;
            • Adds indentation to each line of the given partial.

              Parameter partial

              The partial to indent.

              Parameter indentation

              String containing a combination of spaces and tabs to use as indentation.

              Parameter lineHasNonSpace

              Whether to indent lines that are empty.

            method parse

            parse: (template: string, tags?: OpeningAndClosingTags) => any;
            • Parses and caches the given and returns the array of tokens that is generated from the parse.

              Parameter template

              The template to parse.

              Parameter tags

              The tags to use.

            method rawValue

            rawValue: (token: string[]) => string;
            • Renders a raw token.

              Parameter token

              The token to render.

            method render

            render: (
            template: string,
            view: any | Context,
            partials?: PartialsOrLookupFn,
            config?: OpeningAndClosingTags | RenderOptions
            ) => string;
            • High-level method that is used to render the given with the given .

              Parameter template

              The template to render.

              Parameter view

              The view to render the template with.

              Parameter partials

              Either an object that contains the names and templates of partials that are used in a template

              -- or --

              A function that is used to load partial template on the fly that takes a single argument: the name of the partial.

              Parameter config

              The options for the rendering process.

            method renderInverted

            renderInverted: (
            token: string[],
            context: Context,
            partials?: PartialsOrLookupFn,
            originalTemplate?: string,
            config?: RenderOptions
            ) => string;
            • Renders an inverted section block.

              Parameter token

              The token to render.

              Parameter context

              The context to use for rendering the token.

              Parameter partials

              The partials to use for rendering the token.

              Parameter originalTemplate

              An object used to extract the portion of the original template that was contained in a higher-order section.

              Parameter config

              The options for the rendering process.

            method renderPartial

            renderPartial: (
            token: string[],
            context: Context,
            partials?: PartialsOrLookupFn,
            config?: OpeningAndClosingTags | RenderOptions
            ) => string;
            • Renders a partial.

              Parameter token

              The token to render.

              Parameter context

              The context to use for rendering the token.

              Parameter partials

              The partials to use for rendering the token.

              Parameter config

              The options for the rendering process.

            method renderSection

            renderSection: (
            token: string[],
            context: Context,
            partials?: PartialsOrLookupFn,
            originalTemplate?: string,
            config?: RenderOptions
            ) => string;
            • Renders a section block.

              Parameter token

              The token to render.

              Parameter context

              The context to use for rendering the token.

              Parameter partials

              The partials to use for rendering the token.

              Parameter originalTemplate

              An object used to extract the portion of the original template that was contained in a higher-order section.

              Parameter config

              The options for the rendering process.

            method renderTokens

            renderTokens: (
            tokens: string[][],
            context: Context,
            partials?: PartialsOrLookupFn,
            originalTemplate?: string,
            config?: RenderOptions
            ) => string;
            • Low-level method that renders the given array of using the given and .

              Parameter tokens

              The tokens to render.

              Parameter context

              The context to use for rendering the tokens.

              Parameter partials

              The partials to use for rendering the tokens.

              Parameter originalTemplate

              An object used to extract the portion of the original template that was contained in a higher-order section.

              If the template doesn't use higher-order sections, this argument may be omitted.

              Parameter config

              The options for the rendering process.

            method unescapedValue

            unescapedValue: (token: string[], context: Context) => string;
            • Renders an unescaped value.

              Parameter token

              The token to render.

              Parameter context

              The context to use for rendering the token.

            Interfaces

            interface RenderOptions

            interface RenderOptions {}

              property escape

              escape?: EscapeFunction | undefined;

                property tags

                tags?: OpeningAndClosingTags | undefined;

                  interface TemplateCache

                  interface TemplateCache {}

                    method clear

                    clear: () => void;

                      method get

                      get: (cacheKey: string) => string | undefined;

                        method set

                        set: (cacheKey: string, value: string) => void;

                          Type Aliases

                          type COMMENT

                          type COMMENT = '!';

                            type EQUAL

                            type EQUAL = '=';

                              type ESCAPED_VALUE

                              type ESCAPED_VALUE = 'name';

                                type EscapeFunction

                                type EscapeFunction = (value: any) => string;
                                • Function responsible for escaping values from the view into the rendered output when templates has {{ value }} in them.

                                type INVERTED

                                type INVERTED = '^';

                                  type OpeningAndClosingTags

                                  type OpeningAndClosingTags = [string, string];
                                  • An array of two strings, representing the opening and closing tags respectively, to be used in the templates being rendered.

                                  type PARTIAL

                                  type PARTIAL = '>';

                                    type PartialLookupFn

                                    type PartialLookupFn = (partialName: string) => string | undefined;

                                      type PartialsOrLookupFn

                                      type PartialsOrLookupFn = Record<string, string> | PartialLookupFn;
                                      • Whenever partials are provided, it can either be an object that contains the names and templates of partials that are used in templates

                                        -- or --

                                        A function that is used to load partial template on the fly that takes a single argument: the name of the partial.

                                      type RAW_VALUE

                                      type RAW_VALUE = 'text';

                                        type SECTION

                                        type SECTION = '#';

                                          type TemplateSpans

                                          type TemplateSpans = Array<
                                          | [TemplateSpanType, string, number, number]
                                          | [TemplateSpanType, string, number, number, TemplateSpans, number]
                                          | [TemplateSpanType, string, number, number, string, number, boolean]
                                          >;

                                            type TemplateSpanType

                                            type TemplateSpanType =
                                            | RAW_VALUE
                                            | ESCAPED_VALUE
                                            | SECTION
                                            | UNESCAPED_VALUE
                                            | INVERTED
                                            | COMMENT
                                            | PARTIAL
                                            | EQUAL;

                                              type UNESCAPED_VALUE

                                              type UNESCAPED_VALUE = '&';

                                                Package Files (1)

                                                Dependencies (0)

                                                No dependencies.

                                                Dev Dependencies (0)

                                                No dev dependencies.

                                                Peer Dependencies (0)

                                                No peer dependencies.

                                                Badge

                                                To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/mustache.

                                                • Markdown
                                                  [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@types/mustache)
                                                • HTML
                                                  <a href="https://www.jsdocs.io/package/@types/mustache"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>