Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Text

Hierarchy

  • Text

Index

Properties

Private _dictionaries

_dictionaries: object

Type declaration

Private _dictionary

_dictionary: string = Dictionary.DEFAULT

Private _functions

_functions: object

Type declaration

  • [key: string]: function
      • (...args: any[]): string
      • Parameters

        • Rest ...args: any[]

        Returns string

Private _mode

_mode: TMode = "dev"

Methods

Private _warn

  • _warn(message: any, ...optionalParams: any[]): void
  • Parameters

    • message: any
    • Rest ...optionalParams: any[]

    Returns void

addDictionary

  • addDictionary(key: string | object, dictionary?: object): this
  • Adds the new dictionary.

    Parameters

    • key: string | object

      Key with which is the dictionary accessible to format texts. If it's an object, the key is default.

    • Optional dictionary: object

      Key-value object for mapping the texts.

      • [key: string]: string

    Returns this

    Instance of the Text class.

addFunction

  • addFunction(name: string, fn: function): this
  • Adds the function.

    Parameters

    • name: string

      Name of the function.

    • fn: function

      Function to execute.

        • (...args: any[]): string
        • Parameters

          • Rest ...args: any[]

          Returns string

    Returns this

    Instance of the Text class.

format

  • format(text: string, ...args: any[]): string
  • Formats the text. Data to format must be in braces. If there's a number in braces the value to replace is searched in the args by order in array. If it's a function in the braces the function is called. First parameter accepts number and it's searched in the args. It it's a string in the braces the value to replace is searched in the set dictionary.

    example
    Text.format('{0}', 'one'); // returns one
    Text.format('{0} {1} {2}', 'one', 'two', 'three'); // returns one two three
    example
    Text.format('{count(0, script, scripts, scripts)}', 5); // returns 5 scripts
    example
    Text.format('{gender(0, He, She, He/She)} codes', 'female'); //returns She codes

    Parameters

    • text: string

      Text to format.

    • Rest ...args: any[]

      Arguments to pass in the text by index.

    Returns string

    Formatted text.

get

  • get<T>(key: keyof T, ...args: any[]): string
  • Formats the text from the set dictionary. The text is searched as a value in the dictionary by defined key. If the key is not found in set dictionary it tries to find the text in default dictionary.

    typeparam

    Type of the dictionary object -> typeof { key: 'value' }.

    Type parameters

    • T

    Parameters

    • key: keyof T

      Key of the text in the dictionary.

    • Rest ...args: any[]

      Arguments to pass in format method.

    Returns string

    Formatted text.

getDictionary

  • Gets the dictionary by the key.

    Parameters

    • Default value key: string = this._dictionary

      Key of the dictionary.

    Returns Dictionary

    Dictionary instance or null.

getFromDictionary

  • getFromDictionary<T>(dictionaryKey: string, key: keyof T, ...args: any[]): string
  • Formats the text from the defined dictionary. The text is not searched in the default dictionary if not found.

    typeparam

    Type of the dictionary object -> typeof { key: 'value' }.

    Type parameters

    • T

    Parameters

    • dictionaryKey: string

      Dictionary key.

    • key: keyof T

      Key of the text in the dictionary.

    • Rest ...args: any[]

      Arguments to pass in format method.

    Returns string

    Formatted text.

getMode

  • Gets the current mode of the Text class.

    Returns TMode

    The current mode of the Text class.

key

  • key<T>(...fragments: any[]): keyof T
  • Creates the key from fragments.

    Joins the fragments with _ char.

    typeparam

    Type of the dictionary object -> typeof { key: 'value' }.

    Type parameters

    • T

    Parameters

    • Rest ...fragments: any[]

      The fragments to join.

    Returns keyof T

    Joined key.

setDictionary

  • setDictionary(key: string): this
  • Sets the actual dictionary.

    Parameters

    • key: string

      Key fo the dictionary.

    Returns this

    Instance of the Text class.

setMode

  • setMode(mode: TMode): this
  • Sets the mode of the module.

    If the app is in dev mode, warnings are logged to console and not-existing texts are returned as the key. Otherwise in production mode no logs are printed and non-existing texts are returned as empty string.

    Parameters

    • mode: TMode

      The mode to set one of dev or production. Default is dev.

    Returns this

    Instance of the Text class.

Generated using TypeDoc