Skip to content

String

Helper functions that have to do with strings.

function capitalizeFirstLetter(string): string;

Defined in: functions/string.ts:38

Helper function to capitalize the first letter of a string.

Parameter Type
string string

string


function escapeHTMLCharacters(string): string;

Defined in: functions/string.ts:55

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 &lt;.

Parameter Type
string string

string


function getNumConsecutiveDiacritics(string): number;

Defined in: functions/string.ts:70

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.

Parameter Type
string string

number


function hasDiacritic(string): boolean;

Defined in: functions/string.ts:94

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

Parameter Type
string string

boolean


function hasEmoji(string): boolean;

Defined in: functions/string.ts:108

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.

Parameter Type
string string

boolean


function hasWhitespace(string): boolean;

Defined in: functions/string.ts:113

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

Parameter Type
string string

boolean


function isASCII(str): boolean;

Defined in: functions/string.ts:118

Helper function to determine if a string only contains ASCII characters.

Parameter Type
str string

boolean


function isFirstLetterCapitalized(string): boolean;

Defined in: functions/string.ts:126

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

Parameter Type
string string

boolean


function isKebabCase(string): boolean;

Defined in: functions/string.ts:136

“kebab-case” is the naming style of using all lowercase and hyphens, like “foo-bar”.

An empty string is not considered to be kebab-case.

Parameter Type
string string

boolean


function isLowerCase(string): boolean;

Defined in: functions/string.ts:141

Helper function to test if a string contains only lowercase ASCII letters (a through z).

Parameter Type
string string

boolean


function isSemanticVersion(versionString): boolean;

Defined in: functions/string.ts:150

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

Parameter Type
versionString string

boolean

https://semver.org/


function isUpperCase(string): boolean;

Defined in: functions/string.ts:155

Helper function to test if a string contains only uppercase ASCII letters (A through Z).

Parameter Type
string string

boolean


function kebabCaseToCamelCase(string): string;

Defined in: functions/string.ts:160

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

Parameter Type
string string

string


function kebabCaseToPascalCase(string): string;

Defined in: functions/string.ts:170

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

Parameter Type
string string

string


function normalizeString(string): string;

Defined in: functions/string.ts:186

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.
Parameter Type
string string

string

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


function parseSemanticVersion(versionString): SemanticVersion | undefined;

Defined in: functions/string.ts:211

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

Parameter Type
versionString string

| SemanticVersion | undefined

https://semver.org/


function removeLinesBetweenMarkers(string, marker): string;

Defined in: functions/string.ts:265

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
Parameter Type
string string
marker string

string


function removeLinesMatching(string, match): string;

Defined in: functions/string.ts:294

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

Parameter Type
string string
match string

string


function removeNonPrintableCharacters(string): string;

Defined in: functions/string.ts:306

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

Parameter Type
string string

string

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


function removeWhitespace(string): string;

Defined in: functions/string.ts:311

Helper function to remove all whitespace characters from a string.

Parameter Type
string string

string


function satisfiesSemanticVersion(version, minimumVersion): boolean;

Defined in: functions/string.ts:321

Helper function to check if a semantic version is equal to or greater than a second semantic version.

Parameter Type
version string
minimumVersion string

boolean

If either the version or minimum version are not valid semantic versions.


function titleCaseToKebabCase(string): string;

Defined in: functions/string.ts:356

Helper function to convert a string from TitleCase (PascalCase) to kebab-case.

Parameter Type
string string

string


function trimPrefix(string, prefix, trimAll?): string;

Defined in: functions/string.ts:371

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

Parameter Type Default value Description
string string undefined The string to trim.
prefix string undefined The prefix to trim.
trimAll boolean false Whether to remove multiple instances of the prefix, if they exist. If this is set to true, the prefix must only be a single character.

string


function trimSuffix(string, prefix): string;

Defined in: functions/string.ts:389

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

Parameter Type
string string
prefix string

string


function truncateString(string, maxLength): string;

Defined in: functions/string.ts:402

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.

Parameter Type
string string
maxLength number

string