Skip to main content

functions/string

Helper functions that have to do with strings.

Functions

capitalizeFirstLetter()

function capitalizeFirstLetter(string): string

Helper function to capitalize the first letter of a string.

Parameters

ParameterType
stringstring

Returns

string

Defined in

functions/string.ts:27


escapeHTMLCharacters()

function escapeHTMLCharacters(string): string

Helper function to replace all of the ampersands, less than signs, greater than signs, double quotes, and single quotes in a string with the escaped counterparts. For example, "<" will be replaced with "<".

Parameters

ParameterType
stringstring

Returns

string

Defined in

functions/string.ts:44


getNumConsecutiveDiacritics()

function getNumConsecutiveDiacritics(string): number

Helper function to get the number of consecutive diacritics in a string.

This is useful for sanitization purposes, since many subsequent diacritics can be a sign of a malicious string.

Parameters

ParameterType
stringstring

Returns

number

Defined in

functions/string.ts:59


hasDiacritic()

function hasDiacritic(string): boolean

Helper function to check if a string has one or more diacritics in it.

Parameters

ParameterType
stringstring

Returns

boolean

Defined in

functions/string.ts:83


hasEmoji()

function hasEmoji(string): boolean

Helper function to check if a string has one or more emoji in it.

Under the hood, this uses the same regex check as the Zod library.

Parameters

ParameterType
stringstring

Returns

boolean

Defined in

functions/string.ts:97


hasWhitespace()

function hasWhitespace(string): boolean

From: https://stackoverflow.com/questions/1731190/check-if-a-string-has-white-space

Parameters

ParameterType
stringstring

Returns

boolean

Defined in

functions/string.ts:102


isFirstLetterCapitalized()

function isFirstLetterCapitalized(string): boolean

From: https://stackoverflow.com/questions/8334606/check-if-first-letter-of-word-is-a-capital-letter

Parameters

ParameterType
stringstring

Returns

boolean

Defined in

functions/string.ts:110


isKebabCase()

function isKebabCase(string): boolean

Kebab case is the naming style of using all lowercase and hyphens, like "foo-bar".

Parameters

ParameterType
stringstring

Returns

boolean

Defined in

functions/string.ts:115


isSemanticVersion()

function isSemanticVersion(versionString): boolean

Helper function to check if a given string is a valid Semantic Version.

Parameters

ParameterType
versionStringstring

Returns

boolean

See

https://semver.org/

Defined in

functions/string.ts:124


kebabCaseToCamelCase()

function kebabCaseToCamelCase(string): string

Helper function to convert a string from kebab-case to camel-case.

Parameters

ParameterType
stringstring

Returns

string

Defined in

functions/string.ts:130


normalizeString()

function normalizeString(string): string

Helper function to normalize a string. Specifically, this performs the following steps:

  • Removes any non-printable characters, if any.
  • Normalizes all newlines to "\n".
  • Normalizes all spaces to " ".
  • Removes leading/trailing whitespace.

Parameters

ParameterType
stringstring

Returns

string

See

https://stackoverflow.com/questions/11598786/how-to-replace-non-printable-unicode-characters-javascript

Defined in

functions/string.ts:150


parseSemanticVersion()

function parseSemanticVersion(versionString): object | undefined

Helper function to parse a Semantic Versioning string into its individual constituents. Returns undefined if the submitted string was not a proper Semantic Version.

Parameters

ParameterType
versionStringstring

Returns

object | undefined

See

https://semver.org/

Defined in

functions/string.ts:175


removeLinesBetweenMarkers()

function removeLinesBetweenMarkers(string, marker): string

Helper function to remove lines from a multi-line string. This function looks for a "-start" and a "-end" suffix after the marker. Lines with markets will be completely removed from the output.

For example, by using a marker of "@foo":

line1
# @foo-start
line2
line3
# @foo-end
line4

Would return:

line1
line4

Parameters

ParameterType
stringstring
markerstring

Returns

string

Defined in

functions/string.ts:234


removeLinesMatching()

function removeLinesMatching(string, match): string

Helper function to remove lines from a multi-line string matching a certain other string.

Parameters

ParameterType
stringstring
matchstring

Returns

string

Defined in

functions/string.ts:263


removeNonPrintableCharacters()

function removeNonPrintableCharacters(string): string

Helper function to remove all non-printable characters from a string.

Parameters

ParameterType
stringstring

Returns

string

See

https://stackoverflow.com/questions/11598786/how-to-replace-non-printable-unicode-characters-javascript

Defined in

functions/string.ts:275


removeWhitespace()

function removeWhitespace(string): string

Helper function to remove all whitespace characters from a string.

Parameters

ParameterType
stringstring

Returns

string

Defined in

functions/string.ts:280


trimPrefix()

function trimPrefix(
string,
prefix,
trimAll): string

Helper function to trim a prefix from a string, if it exists. Returns the trimmed string.

Parameters

ParameterTypeDefault valueDescription
stringstringundefinedThe string to trim.
prefixstringundefinedThe prefix to trim.
trimAllbooleanfalseWhether to remove multiple instances of the prefix, if they exist. If this is set to true, the prefix must only be a single character.

Returns

string

Defined in

functions/string.ts:292


trimSuffix()

function trimSuffix(string, prefix): string

Helper function to trim a suffix from a string, if it exists. Returns the trimmed string.

Parameters

ParameterType
stringstring
prefixstring

Returns

string

Defined in

functions/string.ts:310


truncateString()

function truncateString(string, maxLength): string

Helper function to truncate a string to a maximum length. If the length of the string is less than or equal to the provided maximum length, the string will be returned unmodified.

Parameters

ParameterType
stringstring
maxLengthnumber

Returns

string

Defined in

functions/string.ts:323