Options
All
  • Public
  • Public/Protected
  • All
Menu

Module utils

Index

Type aliases

DefaultSettings

DefaultSettings<T>: {[ K in keyof T]: DefaultSettingValue<T[K]> }

Type parameters

  • T

Variables

Const ensure

ensure: { array: (defaultValue: any[]) => { merge: (incoming: any) => any[] }; boolean: (defaultValue: boolean) => { merge: (incoming: any) => boolean }; number: (defaultValue: number) => { merge: (incoming: any) => number }; object: <T>(defaultValue: T) => { merge: (incoming: any) => T }; string: (defaultValue: string) => { merge: (incoming: any) => string } } = ...

Sanitization methods for config settings. These can be used for simple type checking and overwriting config settings.

Plugins should use these methods together with mergeDefaults.

Type declaration

  • array: (defaultValue: any[]) => { merge: (incoming: any) => any[] }
      • (defaultValue: any[]): { merge: (incoming: any) => any[] }
      • Parameters

        • defaultValue: any[]

        Returns { merge: (incoming: any) => any[] }

        • merge: (incoming: any) => any[]
            • (incoming: any): any[]
            • Parameters

              • incoming: any

              Returns any[]

  • boolean: (defaultValue: boolean) => { merge: (incoming: any) => boolean }
      • (defaultValue: boolean): { merge: (incoming: any) => boolean }
      • Parameters

        • defaultValue: boolean

        Returns { merge: (incoming: any) => boolean }

        • merge: (incoming: any) => boolean
            • (incoming: any): boolean
            • Parameters

              • incoming: any

              Returns boolean

  • number: (defaultValue: number) => { merge: (incoming: any) => number }
      • (defaultValue: number): { merge: (incoming: any) => number }
      • Parameters

        • defaultValue: number

        Returns { merge: (incoming: any) => number }

        • merge: (incoming: any) => number
            • (incoming: any): number
            • Parameters

              • incoming: any

              Returns number

  • object: <T>(defaultValue: T) => { merge: (incoming: any) => T }
      • <T>(defaultValue: T): { merge: (incoming: any) => T }
      • Type parameters

        • T

        Parameters

        • defaultValue: T

        Returns { merge: (incoming: any) => T }

        • merge: (incoming: any) => T
            • (incoming: any): T
            • Parameters

              • incoming: any

              Returns T

  • string: (defaultValue: string) => { merge: (incoming: any) => string }
      • (defaultValue: string): { merge: (incoming: any) => string }
      • Parameters

        • defaultValue: string

        Returns { merge: (incoming: any) => string }

        • merge: (incoming: any) => string
            • (incoming: any): string
            • Parameters

              • incoming: any

              Returns string

Functions

Const addLineBreaks

  • addLineBreaks(str: string, measurePixelWidth: boolean, options: { applyRanges?: IRange[]; bold?: boolean; charactersInLine?: number; escapeAsHtmlEntities?: boolean; font?: string; fontSize?: number; lineBreak?: string; maxWidth?: number }): { lines: number; text: string }
  • Adds line breaks to a string every x pixels, using string-pixel-width for measuring the width.

    Returns an object containing the new string and the number of lines.

    Only fonts measured by the string-pixel-width library are supported.

    Parameters

    • str: string
    • measurePixelWidth: boolean
    • options: { applyRanges?: IRange[]; bold?: boolean; charactersInLine?: number; escapeAsHtmlEntities?: boolean; font?: string; fontSize?: number; lineBreak?: string; maxWidth?: number }
      • Optional applyRanges?: IRange[]
      • Optional bold?: boolean
      • Optional charactersInLine?: number
      • Optional escapeAsHtmlEntities?: boolean
      • Optional font?: string
      • Optional fontSize?: number
      • Optional lineBreak?: string
      • Optional maxWidth?: number

    Returns { lines: number; text: string }

    • lines: number
    • text: string

Const arrayIsEmpty

  • arrayIsEmpty(x: any): boolean

Const astToJsonString

  • astToJsonString(ast: IAstNode[]): string

Const astToString

Const escapeAsHtmlEntities

  • escapeAsHtmlEntities(s: string): string

Const escapeCSSWidthOrHeight

  • escapeCSSWidthOrHeight(str?: string): undefined | string
  • Parameters

    • Optional str: string

    Returns undefined | string

Const escapeHtml

  • escapeHtml(str?: string): undefined | string
  • Parameters

    • Optional str: string

    Returns undefined | string

Const getHtmlId

  • getHtmlId(type: string, title: string, htmlIdsSet?: {}): string
  • Parameters

    • type: string
    • title: string
    • Optional htmlIdsSet: {}
      • [id: string]: boolean

    Returns string

Const isFunction

  • isFunction(x: any): x is Function

Const isNumber

  • isNumber(x: any): x is number

Const isObject

  • isObject(x: any): x is object
  • Be careful: This check excludes arrays, even though they are objects in JavaScript.

    Parameters

    • x: any

    Returns x is object

Const isString

  • isString(x: any): x is string

Const mergeDefaults

  • mergeDefaults(settings: any, defaults: {}): any
  • Merge plugin default settings with incoming config settings.

    Any default setting can be set to an object with a 'merge' custom function. In that case this function is responsible for merging the incoming setting with default settings. The custom merge function will get the incoming setting as first parameter and should return the merged setting.

    Parameters

    • settings: any

      the incoming config settings

    • defaults: {}

      the default settings object, possible containing objects with custom merge functions

      • [key: string]: any

    Returns any

Const normalizeLink

  • normalizeLink(url: string): string

Const normalizeLinkText

  • normalizeLinkText(url: string): string

Const objectIsEmpty

  • objectIsEmpty(x: any): boolean

Const other

Const reduceToMap

  • reduceToMap<K, V>(a: V[], idProvider: (curr: V) => K): Map<K, V>
  • Type parameters

    • K

    • V: object

    Parameters

    • a: V[]
    • idProvider: (curr: V) => K
        • (curr: V): K
        • Parameters

          • curr: V

          Returns K

    Returns Map<K, V>

splitByCharactersInLine

  • splitByCharactersInLine(s: string, n: number, useSpaces: boolean, a?: string[]): string[]
  • Splits a string at least every x characters. If useSpaces is true,

    Returns an array of substrings.

    Parameters

    • s: string
    • n: number
    • useSpaces: boolean
    • Optional a: string[]

    Returns string[]

Const splitByLineWidth

  • splitByLineWidth(str: string, options: { bold?: boolean; font?: string; fontSize?: number; maxWidth?: number }): string[]
  • Splits a string every x pixels, using string-pixel-width for measuring the width of the current line.

    Returns an array of substrings with width <= maxWidth.

    Only fonts measured by the string-pixel-width library are supported.

    Parameters

    • str: string
    • options: { bold?: boolean; font?: string; fontSize?: number; maxWidth?: number }
      • Optional bold?: boolean
      • Optional font?: string
      • Optional fontSize?: number
      • Optional maxWidth?: number

    Returns string[]

Const stringIsEmpty

  • stringIsEmpty(x: any): boolean

Const stringToClassName

  • stringToClassName(str: string): string

Const stringToHtmlId

  • stringToHtmlId(str: string): string

Const tokenLocationsToString

  • tokenLocationsToString(tokens: IToken[]): string

Const tokensToString

  • tokensToString(tokens: IToken[]): string

Const validateColorString

  • validateColorString(str: string): boolean

Const validateLink

  • validateLink(url: string, allowFile: boolean): boolean
  • Parameters

    • url: string
    • allowFile: boolean

    Returns boolean

Generated using TypeDoc