Module: @lumjs/core/strings

String and locale related functions.

Source:

Methods

(static) getLocale() → {string}

Get the locale/language string.

  1. If navigator.language exists it will be used.
  2. If Intl exists it will be used.
  3. If neither of those exist, uses 'en-US' as a default.
Source:
Returns:
  • The locale/language string.
Type
string

(static) isReplacement(v) → {boolean}

Is the passed in value a valid String.replace replacement value.

Only strings and functions are valid.

Parameters:
Name Type Description
v *

Value to check.

Source:
Returns:
Type
boolean

(static) isSearch(v) → {boolean}

Is the passed in value a valid String.replace search value.

Only strings and RegExp objects are valid.

Parameters:
Name Type Description
v *

Value to check.

Source:
Returns:
Type
boolean

(static) replaceItems(string, replacements, useAllopt) → {string}

Apply multiple replacement rules to a string.

Parameters:
Name Type Attributes Description
string string

The input string.

replacements object

Replacement rules.

If this is an Array then each item in the array can be:

  • Another array with two items, [find, replace];
  • A boolean, will change the current useAll settting.

If this is any other kind of object then the enumerable property keys will be used as find strings, and the associated values will be used as the replacement values.

useAll boolean <optional>

Which replacement method will be used. If true we use replaceAll(), if false we use replace(). The default is false if value is an Array, or true otherwise.

Source:
Returns:

The output string with all replacements performed.

Type
string

(static) ucfirst(string, lcrestopt, localeopt) → {string}

Make the first character of a string uppercase.

Parameters:
Name Type Attributes Default Description
string string

The input string.

lcrest boolean <optional>
false

Make the rest of the string lowercase?

locale string <optional>
getLocale()

The locale/language of the string.

Source:
Returns:
  • The output string.
Type
string

(static) ucwords(string, unicodeopt, lcrestopt, localeopt) → {string}

Make the first character of each word in a string uppercase.

Parameters:
Name Type Attributes Default Description
string string

The input string.

unicode boolean <optional>
false

Use Unicode words? Only uses simple PCRE-style words (\w) otherwise.

lcrest boolean <optional>
false

Make the rest of each word lowercase?

locale string <optional>
getLocale()

The locale/language of the string.

Source:
Returns:
  • The output string.
Type
string

(async, inner) replaceAsync(string, regexp, replacerFunction) → {string}

Replace values in a string via an async function.

Parameters:
Name Type Description
string string

The input string.

regexp RegExp | string

The pattern to find.

If this is a RegExp, it must have the g flag set. If this is a string it will be converted into a RegExp, see the String#matchAll method for details.

replacerFunction function

An async function.

See String#replace for details on replacer functions.

Source:
Returns:
Type
string