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:62
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
selectorOptionKey()¶
selectorOptionKey(
label):string
Defined in: extension/data/util/data/string.ts:71
Derives the persisted value of a selector setting option from its display label:
lower-cased with whitespace replaced by underscores. Selector definitions list human
readable labels, but only this derived form is ever written to storage (the format is
shared with Toolbox 6.x), so label and stored value must be compared through this.
Parameters¶
label¶
string
The option label as written in the setting definition.
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'})