Options
All
  • Public
  • Public/Protected
  • All
Menu

The main class of this library.

Create an instance (with or without options) and then use wrap() method to do the task.

Created at 1398/2/6 (2019/4/26).

author

S. Mahdi Mir-Ismaili

see

The constructor

see

wrap()

Hierarchy

  • TextWrapper

Implements

Index

Constructors

constructor

Properties

allowedExceedingCharacters

allowedExceedingCharacters: RegExp

breakableCharacters

breakableCharacters: RegExp

continuationIndent

continuationIndent: string

tabLength

tabLength: number

Private tabLength_1

tabLength_1: number

wrapOn

wrapOn: number

Methods

vLen

  • vLen(s: string, vOffset?: number): number
  • Calculate visual (or virtual) length of a string and returns it. V-length is the same as regular length, but when the string contains tab-characters can be different. So it's depended on tab-length and also the position of tab-characters. Example: When tabLength === 4 then vLen('\tA') === 5, but vLen('A\t') === vLen('AB\t') === vLen('ABC\t') === 4 and vLen('ABCD\t') === 8.

    Parameters

    • s: string

      The string to calculate its v-length

    • Default value vOffset: number = 0

      This is an offset from the beginning of the line that s (param) supposed to be started from it. But note that this is NOT a regular offset! In other words:
      s === line.slice(offset) and vOffset === vLen(line.slice(0, offset)).
      Example: When tabLength === 4 then vLen('\t', 1) === 3.

    Returns number

wrap

  • wrap(text: string, alreadyPresentIndentation?: string): WrapResult
  • The main process of this library is done by this method. Gets a string and wraps illegal-too-long-lines of it. To configure and customize its operation pass a WrapOptions to the class constructor}. Note: This is an instance method and needs to a an object instantiation first.

    see

    WrapResult

    see

    class constructor

    Parameters

    • text: string

      The string that probably has long lines and must be wrapped (broken to limited-length lines) based on WrapOptions that has been passed to the class constructor

    • Default value alreadyPresentIndentation: string = ""

      If your input text has a fixed indentation in the leading of its lines already, pass it (as a string) to this parameter.
      Important note: The library doesn't check this indentation actually presents or not. It just appends this to the WrapOptions.continuationIndent (that you passed to the class constructor). In other words, (for a single run of this method per an instantiation) there is no difference whether you pass:
      s1 to WrapOptions.continuationIndent and s2 to this parameter
      or:
      s3 to WrapOptions.continuationIndent and s4 to this parameter
      while (s1 + s2 === s3 + s4). The library works with the whole always. In these cases, this is just a logical separation (and maybe usable in the future).

    Returns WrapResult

    Two things that will be stored in a WrapResult:

    1. wrappedText: string (probably you want this)
    2. markers: number[]

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc