@servicenow/sdk - v4.4.1
    Preparing search index...

    Code writer that assists with formatting and visualizing blocks of JavaScript or TypeScript code.

    Index

    Constructors

    Methods

    • Writes a blank line.

      Returns this

    • Writes a blank line if the last written text was not a blank line.

      Returns this

    • Writes a block using braces.

      Parameters

      • Optionalblock: () => void

        Write using the writer within this block.

      Returns this

    • Writes text to exit a comment if in a comment.

      Returns this

    • Writes a blank line if the condition is true.

      Parameters

      • condition: boolean | undefined

        Condition to evaluate.

      Returns this

    • Writes a newline if the condition is true.

      Parameters

      • condition: boolean | undefined

        Condition to evaluate.

      Returns this

    • Conditionally writes text.

      Parameters

      • condition: boolean | undefined

        Condition to evaluate.

      • textFunc: () => string

        A function that returns a string to write if the condition is true.

      Returns this

    • Conditionally writes text.

      Parameters

      • condition: boolean | undefined

        Condition to evaluate.

      • text: string

        Text to write if the condition is true.

      Returns this

    • Conditionally writes a line of text.

      Parameters

      • condition: boolean | undefined

        Condition to evaluate.

      • textFunc: () => string

        A function that returns a string to write if the condition is true.

      Returns this

    • Conditionally writes a line of text.

      Parameters

      • condition: boolean | undefined

        Condition to evaluate.

      • text: string

        Text to write if the condition is true.

      Returns this

    • Gets if the writer ends with the provided text.

      Parameters

      • text: string

        Text to check if the writer ends with the provided text.

      Returns boolean

    • Gets the current indentation level.

      Returns number

    • Gets the last char written.

      Returns string | undefined

    • Gets the length of the string in the writer.

      Returns number

    • Writes the text within the provided action with hanging indentation.

      Parameters

      • action: () => void

        Action to perform with hanging indentation.

      Returns this

    • Writes the text within the provided action with hanging indentation unless writing a block.

      Parameters

      • action: () => void

        Action to perform with hanging indentation unless a block is written.

      Returns this

    • Indents the code one level for the current line.

      Parameters

      • Optionaltimes: number

      Returns this

    • Indents a block of code.

      Parameters

      • block: () => void

        Block to indent.

      Returns this

    • Writes an inline block with braces.

      Parameters

      • Optionalblock: () => void

        Write using the writer within this block.

      Returns this

    • Gets if the writer is currently at the start of the first line of the text, block, or indentation block.

      Returns boolean

    • Gets if the writer is currently in a comment.

      Returns boolean

    • Gets if the writer is currently in a string.

      Returns boolean

    • Gets if the last chars written were for a blank line.

      Returns boolean

    • Gets if the last chars written were for a newline.

      Returns boolean

    • Gets if the last char written was a space.

      Returns boolean

    • Gets if the last char written was a tab.

      Returns boolean

    • Gets if the writer is currently on the first line of the text, block, or indentation block.

      Returns boolean

    • Iterates over the writer character char codes in reverse order. The iteration stops when a non-null or undefined value is returned from the action. The returned value is then returned by the method.

      Type Parameters

      • T

      Parameters

      • action: (charCode: number, index: number) => T | undefined

      Returns T | undefined

      It is much more efficient to use this method rather than #toString() since #toString() will combine the internal array into a string. Additionally, this is slightly more efficient that iterateLastChars as this won't allocate a string per character.

    • Iterates over the writer characters in reverse order. The iteration stops when a non-null or undefined value is returned from the action. The returned value is then returned by the method.

      Type Parameters

      • T

      Parameters

      • action: (char: string, index: number) => T | undefined

      Returns T | undefined

      It is much more efficient to use this method rather than #toString() since #toString() will combine the internal array into a string.

    • Writes a newline.

      Returns this

    • Writes a newline if the last line was not a newline.

      Returns this

    • Queues the indentation level for the next lines written.

      Parameters

      • indentationLevel: number

        Indentation level to queue.

      Returns this

    • Queues the indentation level for the next lines written using the provided indentation text.

      Parameters

      • whitespaceText: string

        Gets the indentation level from the indentation text.

      Returns this

    • Writes a quote character.

      Returns this

    • Writes text surrounded in quotes.

      Parameters

      • text: string

        Text to write.

      Returns this

    • Sets the current indentation level.

      Parameters

      • indentationLevel: number

        Indentation level to be at.

      Returns this

    • Sets the current indentation using the provided indentation text.

      Parameters

      • whitespaceText: string

        Gets the indentation level from the indentation text.

      Returns this

    • Writes a space.

      Parameters

      • Optionaltimes: number

        Number of times to write a space.

      Returns this

    • Writes a space if the last character was not a space.

      Returns this

    • Writes a tab.

      Parameters

      • Optionaltimes: number

        Number of times to write a tab.

      Returns this

    • Writes a tab if the last character was not a tab.

      Returns this

    • Gets the writer's text.

      Returns string

    • Inserts text at the provided position.

      This method is "unsafe" because it won't update the state of the writer unless inserting at the end position. It is biased towards being fast at inserting closer to the start or end, but slower to insert in the middle. Only use this if absolutely necessary.

      Parameters

      • pos: number

        Position to insert at.

      • text: string

        Text to insert.

      Returns this

    • Sets the indentation level within the provided action and restores the writer's indentation state afterwards.

      Parameters

      • indentationLevel: number

        Indentation level to set.

      • action: () => void

        Action to perform with the indentation.

      Returns this

      Restores the writer's state after the action.

    • Sets the indentation level with the provided indentation text within the provided action and restores the writer's indentation state afterwards.

      Parameters

      • whitespaceText: string

        Gets the indentation level from the indentation text.

      • action: () => void

        Action to perform with the indentation.

      Returns this

    • Writes the provided text.

      Parameters

      • text: string

        Text to write.

      Returns this

    • Writes a line of text.

      Parameters

      • text: string

        String to write.

      Returns this