Namespace RapidContext.Text

Text

Provides functions for basic text processing.

Field Summary
(static)
Converts a string to camel-case, i.e.
(static)
Capitalizes the first character of a string and converts the rest to lower case.
(static)
Escapes HTML/XML special characters to their entities.
(static)
Converts a string to kebab-case, i.e.
(static)
Converts a string to lower case, similar to String.toLowerCase(), but handles null and undefined values.
(static)
Converts a string to space separated lower case words.
(static)
Converts the first character of a string to lower case.
(static)
Converts a string to snake_case, i.e.
(static)
Converts a string to Start Case, i.e.
(static)
str
Converts a value to a string, similar to String(), but handles null and undefined values.
(static)
Unescapes some HTML/XML entities to their original characters.
(static)
Converts a string to upper case, similar to String.toUpperCase(), but handles null and undefined values.
(static)
Converts a string to space separated upper case words.
(static)
Converts the first character of a string to upper case.
(static)
Splits a string into an array of words.

Members

(static) camelCase

Converts a string to camel-case, i.e. each word (except the first) is capitalized and connected without spaces.

Parameters:
Name Type Description
val {*} the value to convert
Returns:
{string} the camel-case string
Example:
camelCase('Foo Bar') //==> 'fooBar'
camelCase('--foo-bar--') //==> 'fooBar'
camelCase('__FOO_BAR__') //==> 'fooBar'
Source:
rapidcontext/text.mjs, line 176

(static) capitalize

Capitalizes the first character of a string and converts the rest to lower case.

Parameters:
Name Type Description
val {*} the value to convert
Returns:
{string} the capitalized string
Example:
capitalize('aBC') //==> 'Abc'
Source:
rapidcontext/text.mjs, line 102

(static) escape

Escapes HTML/XML special characters to their entities. Only encodes the '&', '<', '>', '"' and "'" characters.

Parameters:
Name Type Description
val {*} the value to escape
Returns:
{string} the escaped string
Example:
escape('foo & bar') //==> 'foo &amp; bar'
Source:
rapidcontext/text.mjs, line 264

(static) kebabCase

Converts a string to kebab-case, i.e. each word is connected with a hyphen.

Parameters:
Name Type Description
val {*} the value to convert
Returns:
{string} the kebab-case string
Example:
kebabCase('foo bar') //==> 'foo-bar'
kebabCase('--foo-bar--') //==> 'foo-bar'
kebabCase('__foo_bar__') //==> 'foo-bar'
Source:
rapidcontext/text.mjs, line 194

(static) lower

Converts a string to lower case, similar to String.toLowerCase(), but handles null and undefined values.

Parameters:
Name Type Description
val {*} the value to convert
Returns:
{string} the lower case string
Example:
lower('AbC') //==> 'abc'
Source:
rapidcontext/text.mjs, line 38

(static) lowerCase

Converts a string to space separated lower case words.

Parameters:
Name Type Description
val {*} the value to convert
Returns:
{string} the lower case string
Example:
lowerCase('foo bar') //==> 'foo bar'
lowerCase('--foo-bar--') //==> 'foo bar'
lowerCase('__foo_bar__') //==> 'foo bar'
Source:
rapidcontext/text.mjs, line 142

(static) lowerFirst

Converts the first character of a string to lower case.

Parameters:
Name Type Description
val {*} the value to convert
Returns:
{string} the converted string
Example:
lowerFirst('ABC') //==> 'aBC'
Source:
rapidcontext/text.mjs, line 70

(static) snakeCase

Converts a string to snake_case, i.e. each word is connected with an underscore.

Parameters:
Name Type Description
val {*} the value to convert
Returns:
{string} the snake_case string
Example:
snakeCase('foo bar') //==> 'foo_bar'
snakeCase('--foo-bar--') //==> 'foo_bar'
snakeCase('__foo_bar__') //==> 'foo_bar'
Source:
rapidcontext/text.mjs, line 212

(static) startCase

Converts a string to Start Case, i.e. each word is capitalized and connected with a single space.

Parameters:
Name Type Description
val {*} the value to convert
Returns:
{string} the Start Case string
Example:
startCase('foo bar') //==> 'Foo Bar'
startCase('--foo-bar--') //==> 'Foo Bar'
startCase('__foo_bar__') //==> 'Foo Bar'
Source:
rapidcontext/text.mjs, line 230

(static) str

Converts a value to a string, similar to String(), but handles null and undefined values.

Parameters:
Name Type Description
val {*} the value to convert
Returns:
{string} the string representation
Example:
str(null) //==> ''
str(undefined) //==> ''
str(123) //==> '123'
Source:
rapidcontext/text.mjs, line 20

(static) unescape

Unescapes some HTML/XML entities to their original characters. Only decodes the '&', '<', '>', '"' and "'" characters, as well as numerical entities.

Parameters:
Name Type Description
val {*} the value to unescape
Returns:
{string} the unescaped string
Example:
unescape('foo &amp; bar') //==> 'foo & bar'
unescape('&#39;') //==> "'"
Source:
rapidcontext/text.mjs, line 281

(static) upper

Converts a string to upper case, similar to String.toUpperCase(), but handles null and undefined values.

Parameters:
Name Type Description
val {*} the value to convert
Returns:
{string} the upper case string
Example:
upper('Abc') //==> 'ABC'
Source:
rapidcontext/text.mjs, line 54

(static) upperCase

Converts a string to space separated upper case words.

Parameters:
Name Type Description
val {*} the value to convert
Returns:
{string} the upper case string
Example:
upperCase('foo bar') //==> 'FOO BAR'
upperCase('--foo-bar--') //==> 'FOO BAR'
upperCase('__foo_bar__') //==> 'FOO BAR'
Source:
rapidcontext/text.mjs, line 159

(static) upperFirst

Converts the first character of a string to upper case.

Parameters:
Name Type Description
val {*} the value to convert
Returns:
{string} the converted string
Example:
upperFirst('abc') //==> 'Abc'
Source:
rapidcontext/text.mjs, line 86

(static) words

Splits a string into an array of words. It handles whitespace, punctuation, and CamelCase boundaries.

Parameters:
Name Type Description
val {*} the value to split
Returns:
{Array} the array of words
Example:
words('hello world') //==> ['hello', 'world']
words('helloWorld') //==> ['hello', 'World']
words('XMLHttpRequest') //==> ['XML', 'Http', 'Request']
Source:
rapidcontext/text.mjs, line 119