mwbot-ts - v1.2.7
    Preparing search index...

    Interface TemplateStatic

    This interface defines the static members of the Template class. For instance members, see Template (defined separately due to TypeScript limitations).

    Template is a class that serves to parse {{template}} markups into an object structure, which is accessible via Mwbot.Template. Note that {{#parserfunction:}} markups are treated differently by the ParserFunction class.

    const foo = new mwbot.Template('Foo');
    foo.insertParam('', 'bar').insertParam('user', 'baz');
    foo.stringify(); // {{Foo|bar|user=baz}}
    interface TemplateStatic {
        new TemplateStatic(
            title: string | Title,
            params?: NewTemplateParameter[],
            hierarchies?: TemplateParameterHierarchies,
        ): Template;
        is<T extends keyof TemplateTypeMap>(
            obj: unknown,
            type: T,
        ): obj is TemplateTypeMap[T];
        new(
            title: string | Title,
            params?: NewTemplateParameter[],
            hierarchies?: TemplateParameterHierarchies,
        ): null | Template;
    }

    Hierarchy

    Index

    Constructors

    Methods

    Constructors

    Methods

    • Checks if the given object is an instance of the specified template-related class.

      This method is an alternative of the instanceof operator, which cannot be used for non-exported classes.

      Example:

      const [foo] = new mwbot.Wikitext('{{Foo}}').parseTemplates();
      foo instanceof mwbot.Template; // true
      mwbot.Template.is(foo, 'ParsedTemplate'); // true
      mwbot.Template.is(foo, 'RawTemplate'); // false
      foo instanceof mwbot.ParserFunction; // false
      mwbot.Template.is(foo, 'ParsedParserFunction'); // false

      Be noted about the hierarchies of the template-related classes:

      Type Parameters

      • T extends keyof TemplateTypeMap

        The type of template to check for. Must be one of 'Template', 'ParsedTemplate', 'RawTemplate', 'ParserFunction', or 'ParsedParserFunction'.

      Parameters

      • obj: unknown

        The object to check.

      • type: T

        The template type to compare against.

      Returns obj is TemplateTypeMap[T]

      true if obj is an instance of the specified template class, otherwise false.

      If an invalid type is provided.