@types/common-tags

  • Version 1.8.1
  • Published
  • 11.2 kB
  • No dependencies
  • MIT license

Install

npm i @types/common-tags
yarn add @types/common-tags
pnpm add @types/common-tags

Overview

TypeScript definitions for common-tags

Index

Variables

variable codeBlock

const codeBlock: TemplateTag;
  • alias for html

variable commaLists

const commaLists: TemplateTag;
  • Allows you to inline an array substitution as a comma-separated list.

variable commaListsAnd

const commaListsAnd: TemplateTag;
  • Allows you to inline an array substitution as a comma-separated list, the last of which is preceded by the word "and".

variable commaListsOr

const commaListsOr: TemplateTag;
  • Allows you to inline an array substitution as a comma-separated list, the last of which is preceded by the word "or".

variable html

const html: TemplateTag;
  • You'll often find that you might want to include an array in a template. Typically, doing something like ${array.join(', ')} would work - but what if you're printing a list of items in an HTML template and want to maintain the indentation? You'd have to count the spaces manually and include them in the .join() call - which is a bit ugly for my taste. This tag properly indents arrays, as well as newline characters in string substitutions, by converting them to an array split by newline and re-using the same array inclusion logic.

variable id

const id: TemplateTag;
  • A no-op tag that might come in useful in some scenarios, e.g. mocking.

variable inlineLists

const inlineLists: TemplateTag;
  • Allows you to inline an array substitution as a list.

variable oneLine

const oneLine: TemplateTag;
  • Allows you to keep your single-line strings under 80 characters without resorting to crazy string concatenation.

variable oneLineCommaLists

const oneLineCommaLists: TemplateTag;
  • Allows you to inline an array substitution as a comma-separated list, and is rendered out on to a single line.

variable oneLineCommaListsAnd

const oneLineCommaListsAnd: TemplateTag;
  • Allows you to inline an array substitution as a comma-separated list, the last of which is preceded by the word "and", and is rendered out on to a single line.

variable oneLineCommaListsOr

const oneLineCommaListsOr: TemplateTag;
  • Allows you to inline an array substitution as a comma-separated list, the last of which is preceded by the word "or", and is rendered out on to a single line.

variable oneLineInlineLists

const oneLineInlineLists: TemplateTag;
  • Allows you to inline an array substitution as a list, rendered out on a single line.

variable oneLineTrim

const oneLineTrim: TemplateTag;
  • Allows you to keep your single-line strings under 80 characters while trimming the new lines.

variable safeHtml

const safeHtml: TemplateTag;
  • A tag very similar to html but it does safe HTML escaping for strings coming from substitutions. When combined with regular html tag, you can do basic HTML templating that is safe from XSS (Cross-Site Scripting) attacks.

variable source

const source: TemplateTag;
  • alias for html

variable stripIndent

const stripIndent: TemplateTag;
  • If you want to strip the initial indentation from the beginning of each line in a multiline string. Important note: this tag will not indent multiline strings coming from the substitutions. If you want that behavior, use the html tag (aliases: source, codeBlock).

variable stripIndents

const stripIndents: TemplateTag;
  • If you want to strip *all* of the indentation from the beginning of each line in a multiline string.

variable TemplateTag

const TemplateTag: {
new (transformers?: Array<TemplateTransformer<any>>): TemplateTag;
new (...transformers: Array<TemplateTransformer<any>>): TemplateTag;
new (...pluginFunctions: PluginFunction[]): TemplateTag;
};

    Functions

    function createTag

    createTag: {
    (transformers?: Array<TemplateTransformer<any>>): TemplateTag;
    (...transformers: TemplateTransformer<any>[]): TemplateTag;
    (...pluginFunctions: PluginFunction[]): TemplateTag;
    };
    • New Tag factory

    function inlineArrayTransformer

    inlineArrayTransformer: (opts?: {
    separator?: string | undefined;
    conjunction?: string | undefined;
    serial?: boolean | undefined;
    }) => TemplateTransformer;
    • Converts an array substitution to a string containing a list

      Parameter

      [opts.separator=''] what to separate each item with (always followed by a space)

      Parameter

      [opts.conjunction=''] replace the last separator with this value

      Parameter

      [opts.serial=false] should the separator be included before the conjunction? As in the case of serial/oxford commas a TemplateTag transformer

    function replaceResultTransformer

    replaceResultTransformer: (
    replaceWhat: string | RegExp,
    replaceWith: string | ((substring: string, ...args: any[]) => string)
    ) => TemplateTransformer;
    • Replaces a value or pattern in the end result with a new value.

      Parameter replaceWhat

      the value or pattern that should be replaced

      Parameter replaceWith

      the replacement value a TemplateTag transformer

    function replaceStringTransformer

    replaceStringTransformer: (
    replaceWhat: string | RegExp,
    replaceWith: string | ((substring: string, ...args: any[]) => string)
    ) => TemplateTransformer;
    • Replaces the result of all strings (what's not in ${ ... }) with a new value. Same as for replaceResultTransformer, replaceWhat can be a string or regular expression and replaceWith is the new value.

    function replaceSubstitutionTransformer

    replaceSubstitutionTransformer: (
    replaceWhat: string | RegExp,
    replaceWith: string | ((substring: string, ...args: any[]) => string)
    ) => TemplateTransformer;
    • Replaces the result of all substitutions (results of calling ${ ... }) with a new value. Same as for replaceResultTransformer, replaceWhat can be a string or regular expression and replaceWith is the new value.

    function splitStringTransformer

    splitStringTransformer: (splitBy: string) => TemplateTransformer;
    • Splits a string substitution into an array by the provided splitBy substring, only if the string contains the splitBy substring.

    function stripIndentTransformer

    stripIndentTransformer: (type?: 'initial' | 'all') => TemplateTransformer;
    • strips indentation from a template literal

      Parameter type

      whether to remove all indentation or just leading indentation. can be 'all' or 'initial' a TemplateTag transformer

    function trimResultTransformer

    trimResultTransformer: (
    side?: 'start' | 'end' | 'left' | 'right' | ''
    ) => TemplateTransformer;
    • TemplateTag transformer that trims whitespace on the end result of a tagged template

      Parameter side

      The side of the string to trim. Can be 'start' or 'end' (alternatively 'left' or 'right') a TemplateTag transformer

    Interfaces

    interface TemplateTag

    interface TemplateTag {}

      call signature

      (str: string): string;

        call signature

        (tag: JSTag): TemplateTag;

          call signature

          (literals: TemplateStringsArray, ...placeholders: any[]): string;

            interface TemplateTransformer

            interface TemplateTransformer<TCtx = { [key: string]: any }> {}

              property getInitialContext

              getInitialContext?: (() => TCtx) | undefined;
              • Called before everything else. The result of this hook will be passed to other hooks as context. If omitted, context will be an empty object.

              property onEndResult

              onEndResult?: ((endResult: string, context: TCtx) => string) | undefined;
              • Called when all substitutions have been parsed endResult is the final value.

              property onString

              onString?: ((str: string, context: TCtx) => string) | undefined;
              • Called when the tag encounters a string. (a string is whatever's not inside "${}" in your template literal) str is the value of the current string

              property onSubstitution

              onSubstitution?:
              | ((substitution: string, resultSoFar: string, context: TCtx) => string)
              | undefined;
              • Called when the tag encounters a substitution. (a substitution is whatever's inside "${}" in your template literal) substitution is the value of the current substitution resultSoFar is the end result up to the point of this substitution

              Type Aliases

              type JSTag

              type JSTag = (literals: TemplateStringsArray, ...placeholders: any[]) => string;

                type PluginFunction

                type PluginFunction = (
                oldValue: string,
                newValue: string
                ) => TemplateTransformer<any>;

                  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/common-tags.

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