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.
The string to calculate its v-length
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.
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.
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
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).
Two things that will be stored in a WrapResult:
wrappedText: string (probably you want this)markers: number[]Generated using TypeDoc
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).
S. Mahdi Mir-Ismaili
The constructor
wrap()