Class: UrlTransformer

UrlTransformer

Utility for transforming URLs according to the configured replacement rules.


new UrlTransformer()

Initializes the URL transformer.

Members


_rules :Object.<string, string>

Type:
  • Object.<string, string>

Methods


addRule(pattern, replacement)

Adds the provided replacement rule to the rules used by this URL transformer.

Parameters:
Name Type Description
pattern string

Regexp patter to look for (must be escaped as if for use in the Regexp constructor).

replacement string

The replacement of the matched patter in any matched URL.

Returns:

This transformer.

Type
UrlTransformer

clear()

Clears all rules.

Returns:

This transformer.

Type
UrlTransformer

transform(str)

Applies all rules registered with this URL transformer to the provided URL and returns the result. The rules will be applied in the order they were registered.

Parameters:
Name Type Description
str string

The URL for transformation.

Returns:

Transformed URL.

Type
string