Class: RichString

RichString()

A wrapper around a string that provides useful utility functions not present in the standard library.

Constructor

new RichString()

Prefer fromString

Source:
Example
const string = RichString.fromString(element.textContent)
element.textContent = string.humanize().toString()

Methods

camelize()

Returns a RichString with the string converted from snake or kebab case into camel case.

Source:

capitalize()

Returns a RichString with the string capitalized.

Source:

decamlize(parameters)

Returns a RichString with the string converted from camel case to snake or kebab case.

Parameters:
Name Type Description
parameters Object
Properties
Name Type Description
spacer string

["_"] - a string to use when joining words together.

Source:

decapitalize()

Returns a RichString with the string un-capitalized.

Source:

humanize()

Returns a 'humanized' RichString, which is basically a de-camelized version with the first letter capitalized.

Source:

toString()

Return the underlying String value

Source:

toStringOrNull()

Return the underlying String value or null if the string is blank

Source:

(static) fromString(possiblyDefinedStringOrRichString)

Prefer this over the constructor, as this will wrap possiblyDefinedStringOrRichString only if necessary as well as handle null.

Parameters:
Name Type Description
possiblyDefinedStringOrRichString null | undefined | String | RichString

if null, undefined, or otherwise falsey, this method returns null. If a String, returns a new RichString wrapping it. If a RichString, returns the RichString unchanged.

Source: