utilities

Utility functions, intended both for use within the core link generation code, and, by users defining their own custom templates, transformer functions, and filter functions.

This module is exposed to end-users as module:linkifier-class.Linkifier#utilities and module:linkifier-class.Linkifier#util.

Description:
Source:
See:

Requires

Members

(static, readonly) doDebug :boolean

Description:
  • Whether or not to print debug messages.

Source:
Default Value:
  • false

Whether or not to print debug messages.

Type:
  • boolean

Methods

(static) batchFixCustomWordCases(str, customCapWordsopt) → {string}

Description:
  • Batch-fix words with special capitalisations in a string. E.g. force fbi to FBI, ios to iOS, etc..

Source:
See:
Parameters:
Name Type Attributes Description
str string

the string to apply the capitalisation corrections to.

customCapWords Iterable.<string> <optional>

the list of words with special capitalisations. Defaults to the default list module:defaults.speciallyCapitalisedWords.

Returns:

the original string with all occurrences of the words in the list capitalised as per the word list. All other capitatlisations will be left un-changed.

Type
string

(static) debug(msg, …extraArgs)

Description:
  • Write a debug message to STDOUT if doDebug is not false.

Source:
Parameters:
Name Type Attributes Description
msg string | *

the primary message, passed to console.debug as the first argument.

extraArgs * <repeatable>

additional arguments are passed through to console.debug.

(static) disableDebugMessages()

Description:
  • Disable the printing of debug messages.

Source:

(static) enableDebugMessages()

Description:
  • Enable the printing of debug messages.

Source:

(static) error(msg, …extraArgs)

Description:
  • Write an error message to STDERR.

Source:
Parameters:
Name Type Attributes Description
msg string | *

the primary message, passed to console.error as the first argument.

extraArgs * <repeatable>

additional arguments are passed through to console.error.

(static) escapeRegex(str) → {string}

Description:
  • Escape a string for use in regular expressions.

    Note: this is not a standard Javascript feature as of April 2026, though it is coming in future versions of Javascript.

Source:
See:
Parameters:
Name Type Description
str string

the string to escape.

Returns:

the escaped string, ready for use in a regular expression.

Type
string

(static) extractSlug(url, customCapWordsopt, smallWordsopt) → {string}

Description:
  • Extract the slug from a URL and convert it to a title-case string.

Source:
See:
Parameters:
Name Type Attributes Description
url string

the URL to extract the slug from. The slug is taken to be the last segment of the path, with any file extension removed, and with the query string and fragment ignored.

customCapWords Iterable.<string> <optional>

a list of words with custom capitalisations to correct after title-casing. Defaults to module:defaults.speciallyCapitalisedWords.

smallWords Iterable.<string> <optional>

a list of small words to preserve in lower case during title-casing to override the default behaviour in the title-casing utility function.

Returns:

the slug extracted from the URL, converted to title case, with the custom capitalisations applied.

Type
string

(static) fatal(msg, …extraArgs)

Description:
  • Terminate with fatal error to STDERR.

Source:
Parameters:
Name Type Attributes Description
msg string | *

the primary message, passed to console.error as the first argument.

extraArgs * <repeatable>

additional arguments are passed through to console.error.

(static) info(msg, …extraArgs)

Description:
  • Write an informational message to STDOUT.

Source:
Parameters:
Name Type Attributes Description
msg string | *

the primary message, passed to console.log as the first argument.

extraArgs * <repeatable>

additional arguments are passed through to console.log.

(static) isURL(url) → {boolean}

Description:
  • Check if a value can be used as a URL.

    This is a minimal check, it simply instantiates a URI object and verifies it has a protcol and hostname.

Source:
See:
Parameters:
Name Type Description
url string

the URL to validate

Returns:
  • true if the value can be used to instantiate a urijs instance that defines a protocol and hostname, false otherwise.
Type
boolean

(static) regulariseWhitespace(text) → {string}

Description:
  • Regularise white space by replacing all sequences of whitespace characters with a single space and trimming leading and trailing whitespace.

Source:
Parameters:
Name Type Description
text string
Returns:
Type
string

(static) setDebugStatus(debugStatus)

Description:
  • Set whether or not debug messages will be printed.

Source:
Parameters:
Name Type Description
debugStatus boolean

true to enable the printing of debug messages, false to disable it.

(static) stripQueryString(url) → {string}

Description:
  • Strip the query string from a URL, if present.

Source:
Parameters:
Name Type Description
url string

a URL with our without a query string.

Returns:

the original URL with the query string removed, if it was present.

Type
string

(static) stripUTMParameters(url) → {string}

Description:
  • Remove UTM parameters from the query string in a URL, if present.

Source:
See:
Parameters:
Name Type Description
url string

a URL with or without UTM parameters in the query string.

Returns:

the original URL with the UTM parameters removed, if they were present, but with any other query parameters preserved.

Type
string

(static) toTitleCase(str, customCapWordsopt, smallWordsopt) → {string}

Description:
  • Convert a string to title case, with some custom capitalisations.

    This functions uses the module:title-case to perform the initial title-caseing, and then applies the custom capitalisations to fix any words with unusual capitalisation requirements. All words this mododule defies as being so-called small words (e.g., "the", "a" & "an") are preserved in lower case, as well as the additional words defined in module:defaults.smallWords.

Source:
See:
Parameters:
Name Type Attributes Description
str string

the string to convert to title case.

customCapWords Iterable.<string> <optional>

a list of words with custom capitalisations to correct after title-casing. Defaults to module:defaults.speciallyCapitalisedWords.

smallWords Iterable.<string> <optional>

a list of small words to preserve in lower case during title-casing. Defaults to the set used by module:title-case.

Returns:

the original string converted to title case, with the custom capitalisations applied.

Type
string

(static) warn(msg, …extraArgs)

Description:
  • Write a warning message to STDERR.

Source:
Parameters:
Name Type Attributes Description
msg string | *

the primary message, passed to console.error as the first argument.

extraArgs * <repeatable>

additional arguments are passed through to console.error.