moderator-toolbox-nxg-for-reddit / util/data/string

util/data/string

Functions

escapeHTML()

escapeHTML(html): string

Defined in: extension/data/util/data/string.ts:4

Escapes &, <, >, ", ', and / as HTML entities.

Parameters

html

string

Returns

string


literalRegExp()

literalRegExp(text, flags?): RegExp

Defined in: extension/data/util/data/string.ts:28

Builds a regular expression that matches the supplied string literally.

Parameters

text

string

flags?

string

Returns

RegExp


removeLastDirectoryPartOf()

removeLastDirectoryPartOf(url): string

Defined in: extension/data/util/data/string.ts:35

Drops the final path segment from a URL, e.g. /this/is/url/with/part/ becomes /this/is/url/with/.

Parameters

url

string

Returns

string


removeQuotes()

removeQuotes(string): string

Defined in: extension/data/util/data/string.ts:58

Strips ASCII single and double quote characters out of a string.

Parameters

string

string

Returns

string


replaceTokens()

replaceTokens(info, content): string

Defined in: extension/data/util/data/string.ts:46

Replaces {tokens} for the respective value in given content.

Parameters

info

Record<string, string>

content

string

Returns

string


template()

template(tpl, variables): string

Defined in: extension/data/util/data/string.ts:21

Replaces {{key}} placeholders in tpl with corresponding values from variables.

Parameters

tpl

string

variables

Record<string, unknown>

Returns

string

Example

template('/r/{{sub}}/comments/{{id}}/', {sub: 'toolbox', id: '2kwx2o'})