Text prototype extensions


_ <- fat.type.Text


Name Signature Brief
Text (val: Any) Coerces value to text, same as .toText

Prototype members

Name Signature Brief
isEmpty (): Boolean Return true if length is zero
nonEmpty (): Boolean Return true if non-zero length
size (): Number Return text length
toText (): Text Force text interpolation
replace (old: Text, new: Text): Text Replace old with new (all)
indexOf (frag: Text): Number Get fragment index, -1 if absent
contains (frag: Text): Boolean Check if text contains fragment
count (frag: Text): Number Get repetition count for fragment
startsWith (frag: Text): Boolean Check if starts with fragment
endsWith (frag: Text): Boolean Check if ends with fragment
split (sep: Text): List/Text Split text by sep into list
toLower (): Text Return lowercase version of text
toUpper (): Text Return uppercase version of text
trim (): Text Return trimmed version of text
match (regex: Text): Boolean Return text is match for regex
repeat (n: Number): Text Return text repeated n times
overlay (base: Text, align: Text): Text Return text overlaid on base


_ <- fat.type.Text
x = 'banana'
x.size                       # yields 6
x.replace('nana', 'nquet');  # yields 'banquet'


When defining regular expressions, prefer to use raw texts and remember to escape backslashes as needed, ensuring that the regular expressions are interpreted correctly.

At the moment, regex support is limited to matching only:

alphaOnly = "^[[:alpha:]]+$"
'abc'.match(alphaOnly)  # output: true

the implemented dialect is POSIX regex extended


The default align value (if not provided) is 'left'. Other possible values are 'center' and 'right':

'x'.overlay('___')            # 'x__'
'x'.overlay('___', 'left')    # 'x__'
'x'.overlay('___', 'center')  # '_x_'
'x'.overlay('___', 'right')   # '__x'

the outcome is always the same size as base parameter, the text will be cut if it is longer

See also

results matching ""

    No results matching ""