Module: string_helpers

Methods

(inner) alphabetize()

Alphabetize an array of strings

(inner) arrowed()

"foo" => ""

(inner) at()

"string" => "@string"

(inner) bracketed()

"string" => "[string]"

(inner) byteString(numBytes) → {string}

Returns a string representation of a number of bytes in bytes, kilobytes, or megabytes.
Parameters:
Name Type Description
numBytes number The number of bytes.
Returns:
Human-readable string representing the size.
Type
string

(inner) collapseWhitespace()

Collapse all whitespace in a string to single spaces.

(inner) compareStr()

for use with sort()

(inner) countInstances(str, substr) → {number}

Counts the number of occurrences of a substring within a string.
Parameters:
Name Type Description
str string The string to search within.
substr string The substring to count.
Returns:
The number of times substr appears in str.
Type
number

(inner) createRandomString(length) → {string}

Creates a random alphanumeric string of the given length.
Parameters:
Name Type Description
length number The desired length of the random string.
Returns:
The generated random string.
Type
string

(inner) determineMediaCategory(uri) → {MediaCategory|undefined}

Guesses the media category based on the file extension in the URI.
Parameters:
Name Type Description
uri string | null | undefined The URI to check.
Returns:
The detected media category, or undefined if not found.
Type
MediaCategory | undefined

(inner) extractDomain(inUrl) → {string}

Extracts the domain from a URL string. Examples: "http://www.mast.ai/foobar" => "mast.ai" "example.com/path" => "example.com" "localhost:3000" => "localhost"
Parameters:
Name Type Description
inUrl string The URL to extract the domain from.
Returns:
The extracted domain, or an empty string if not found.
Type
string

(inner) hashObject(obj) → {string}

Takes the MD5 hash of a JavaScript object, number, or string.
Parameters:
Name Type Description
obj object | number | string The object, number, or string to hash.
Returns:
The MD5 hash as a string.
Type
string

(inner) htmlToParagraphs(html) → {Array.<string>}

Breaks up an HTML string into paragraphs.
Parameters:
Name Type Description
html string The HTML string to split.
Returns:
Array of paragraph strings.
Type
Array.<string>

(inner) htmlToText(html) → {string}

Removes HTML tags and newlines from a string and decodes HTML entities.
Parameters:
Name Type Description
html string The HTML string to convert.
Returns:
The plain text string.
Type
string

(inner) isEmptyStr()

Check if it's empty (all whitespace or null or undefined)

(inner) optionalSuffix(obj, toSuffixopt, noSpaceopt) → {string}

If object is not null or undefined return the result of suffixFxn(obj) with a leading space.
Parameters:
Name Type Attributes Default Description
obj T Object to check.
toSuffix string | function <optional>
Function to generate the suffix from the object.
noSpace boolean <optional>
false If true, do not add a leading space to the suffix.
Returns:
Type
string

(inner) ordinalSuffix(n) → {string}

Returns the ordinal suffix for a given integer (e.g., 1 => "st", 2 => "nd").
Parameters:
Name Type Description
n number The number to get the ordinal suffix for.
Returns:
The ordinal suffix ("st", "nd", "rd", or "th").
Type
string

(inner) quoted()

'string' => '"string"'

(inner) removeDiacritics()

Remove diacritics ("ó" => "o", "é" => "e", etc.)

(inner) removeEmojis()

Remove any emojis from string.

Remove https links from string.

(inner) removeMentions()

Remove "@username@domain" style strings from string

(inner) removeTags()

Remove all hashtags ("#someHashtag") from string.

(inner) replaceEmojiShortcodesWithImgTags(html, emojis, fontSizeopt) → {string}

Replaces custom emoji shortcodes (e.g., :smile:) with tags in an HTML string.
Parameters:
Name Type Attributes Default Description
html string The HTML string containing emoji shortcodes.
emojis Array.<mastodon.v1.CustomEmoji> Array of custom emoji objects.
fontSize number <optional>
DEFAULT_FONT_SIZE Font size for the emoji images.
Returns:
The HTML string with emoji shortcodes replaced by tags.
Type
string

Replaces https links in a string with a [link to DOMAIN] format.
Parameters:
Name Type Description
input string The input string containing links.
Returns:
The string with links replaced by [domain] tags.
Type
string

(inner) suffixedInt()

1 => "1st", 2 => "2nd", 3 => "3rd", 4 => "4th", etc.

(inner) toLocaleInt(num) → {string}

Converts a number to a locale-formatted string, or returns NULL if the number is null.
Parameters:
Name Type Description
num number | null The number to format.
Returns:
The locale-formatted string or NULL.
Type
string

(inner) wordRegex(pattern) → {RegExp}

Creates a regex that matches a whole word, case-insensitive.
Parameters:
Name Type Description
pattern string The word pattern to match.
Returns:
The generated regular expression.
Type
RegExp

(inner) wordsRegex(patterns) → {RegExp}

Creates a regex that matches any of the given patterns as whole words, case-insensitive.
Parameters:
Name Type Description
patterns Array.<string> Array of word patterns to match.
Returns:
The generated regular expression.
Type
RegExp