Skip to main content

Class: StringUtils

Defined in: core/src/StringUtils.ts:11

Utility functions for working with strings.

Constructors​

Constructor​

new StringUtils(): StringUtils

Returns​

StringUtils

Methods​

escapeRegExp()​

static escapeRegExp(str): string

Defined in: core/src/StringUtils.ts:19

Escapes all regular expression metacharacters in str so it can be safely embedded in a RegExp pattern and matched as a literal string.

Parameters​

str​

string

The string to escape.

Returns​

string

The escaped string.


findAndReplace()​

static findAndReplace(contents, variables): string

Defined in: core/src/StringUtils.ts:58

Performs a search and replace on the provided contents with the map of variable replacements. The contents must use Mustache formatted tokens such as {{toreplace}}.

Parameters​

contents​

string

The stringt to perform the find and replace on.

variables​

any

A map of key=>value pairs to search for and replace.

Returns​

string


getParameters()​

static getParameters(str): string[]

Defined in: core/src/StringUtils.ts:30

Returns a list of all parameters contained within the string. A parameter is a bracket delimited substring (e.g. /my/{key}/with/{id}).

Parameters​

str​

string

The string to search for parameters.

Returns​

string[]

A list of parameters contained in the provided string.


replaceAll()​

static replaceAll(str, match, prefix): string

Defined in: core/src/StringUtils.ts:115

Replaces all instances of the match regex pattern with the contents of the inner regular expression pattern for the given string.

Parameters​

str​

string

The string to perform replacement on.

match​

string | RegExp

The regular expression pattern to match containing an outer and inner pattern.

prefix​

string

The prefix to prepend the replacement text with.

Returns​

string

The fully replaced contents of the string.

Example​

let result = replaceAll('/my/path/{id}', new RegExp('\\{([^\\}]+)\\}'), ':');
console.log(result); // -> /my/path/:id

toCamelCase()​

static toCamelCase(str): string

Defined in: core/src/StringUtils.ts:149

Converts the first character in the given string to be lowercase (e.g. myVariable).

Parameters​

str​

string

The string to convert to camelCase.

Returns​

string

The string converted to camelCase.


toPascalCase()​

static toPascalCase(str): string

Defined in: core/src/StringUtils.ts:159

Converts the first character in the given string to be uppercase (e.g. MyVariable).

Parameters​

str​

string

The string to convert to PascalCase.

Returns​

string

The string converted to PascalCase.