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:
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.
- Source:
- See:
-
- module:linkifier-class.Linkifier#utilities for the short-cut to this module exposed on the Linkifier class.
- module:linkifier-class.Linkifier#util for the short-cut to this module exposed on the Linkifier class.
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
fbitoFBI,iostoiOS, etc..
- Source:
- See:
-
- module:defaults.speciallyCapitalisedWords for the default list of custom capitalisations.
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
doDebugis notfalse.
- Source:
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
msg |
string | * | the primary message, passed to |
|
extraArgs |
* |
<repeatable> |
additional arguments are passed through to |
(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 |
|
extraArgs |
* |
<repeatable> |
additional arguments are passed through to |
(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:
-
- module:defaults.speciallyCapitalisedWords for the default list of custom capitalisations.
- toTitleCase for the function used for the title-casing.
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 |
|
extraArgs |
* |
<repeatable> |
additional arguments are passed through to |
(static) info(msg, …extraArgs)
- Description:
Write an informational message to STDOUT.
- Source:
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
msg |
string | * | the primary message, passed to |
|
extraArgs |
* |
<repeatable> |
additional arguments are passed through to |
(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:
trueif the value can be used to instantiate aurijsinstance that defines a protocol and hostname,falseotherwise.
- 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 |
|
(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:
-
- module:defaults.speciallyCapitalisedWords for the default list of custom capitalisations.
- module:title-case for the Title Case module who's `titleCase()` function is used to convert to title case, and which has its own default list of small words that are preserved in lower case.
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 |
|
extraArgs |
* |
<repeatable> |
additional arguments are passed through to |