Utils

Utils

A collection of generic utilities.

Constructor

new Utils()

Source:

Methods

(static) copyRegExp(expression, injectFlagsopt) → {RegExp}

Source:

Copies a regular expression and, if specified, inject extra flags.

Parameters:
Name Type Attributes Default Description
expression RegExp

The expression to copy.

injectFlags string <optional>
''

Extra flags to add to the new expression. For example 'ig'.

Returns:
Type
RegExp

(static) ensureArray(target) → {Array.<T>}

Source:

Ensures a given value is wrapped on an array.

Parameters:
Name Type Description
target T | Array.<T>

The target to validate and, if necessary, wrap.

Returns:
Type
Array.<T>

(static) escapeForRegExp(text) → {string}

Source:

Escapes a string to be used on new RegExp(...).

Parameters:
Name Type Description
text string

The text to escape.

Returns:
Type
string

(static) execRegExp(expression, text) → (nullable) {Array}

Source:

This is a simple wrapper for RegExp.exec. The reason for this wrapper is that it allows me to mock it on the tests and add support for named groups, something that is not yet available on the target version this project is for.

Parameters:
Name Type Description
expression RegExp

The regular expression to execute.

text string

The target text where the expression will be executed.

Returns:
Type
Array

(static) getRandomString(length) → {string}

Source:

Generates a unique random string.

Parameters:
Name Type Description
length number

The required length of the string.

Returns:
Type
string

(static) isObject(target) → {boolean}

Source:

Checks whether a target is a literal object or not.

Parameters:
Name Type Description
target *

The target to validate.

Returns:
Type
boolean