Skip to main content

String

Helper functions that have to do with strings.

Functions

capitalizeFirstLetter()

function capitalizeFirstLetter(string): string;

Defined in: functions/string.ts:38

Helper function to capitalize the first letter of a string.

Parameters

ParameterType
stringstring

Returns

string


escapeHTMLCharacters()

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

Parameters

ParameterType
stringstring

Returns

string


getNumConsecutiveDiacritics()

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.

Parameters

ParameterType
stringstring

Returns

number


hasDiacritic()

function hasDiacritic(string): boolean;

Defined in: functions/string.ts:94

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

Parameters

ParameterType
stringstring

Returns

boolean


hasEmoji()

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.

Parameters

ParameterType
stringstring

Returns

boolean


hasWhitespace()

function hasWhitespace(string): boolean;

Defined in: functions/string.ts:113

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

Parameters

ParameterType
stringstring

Returns

boolean


isASCII()

function isASCII(str): boolean;

Defined in: functions/string.ts:118

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

Parameters

ParameterType
strstring

Returns

boolean


isFirstLetterCapitalized()

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

Parameters

ParameterType
stringstring

Returns

boolean


isKebabCase()

function isKebabCase(string): boolean;

Defined in: functions/string.ts:135

"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.

Parameters

ParameterType
stringstring

Returns

boolean


isLowerCase()

function isLowerCase(string): boolean;

Defined in: functions/string.ts:140

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

Parameters

ParameterType
stringstring

Returns

boolean


isSemanticVersion()

function isSemanticVersion(versionString): boolean;

Defined in: functions/string.ts:149

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

Parameters

ParameterType
versionStringstring

Returns

boolean

See

https://semver.org/


isUpperCase()

function isUpperCase(string): boolean;

Defined in: functions/string.ts:154

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

Parameters

ParameterType
stringstring

Returns

boolean


kebabCaseToCamelCase()

function kebabCaseToCamelCase(string): string;

Defined in: functions/string.ts:159

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

Parameters

ParameterType
stringstring

Returns

string


kebabCaseToPascalCase()

function kebabCaseToPascalCase(string): string;

Defined in: functions/string.ts:169

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

Parameters

ParameterType
stringstring

Returns

string


normalizeString()

function normalizeString(string): string;

Defined in: functions/string.ts:185

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


parseSemanticVersion()

function parseSemanticVersion(versionString): 
| SemanticVersion
| undefined;

Defined in: functions/string.ts:210

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

| SemanticVersion | undefined

See

https://semver.org/


removeLinesBetweenMarkers()

function removeLinesBetweenMarkers(string, marker): string;

Defined in: functions/string.ts:262

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


removeLinesMatching()

function removeLinesMatching(string, match): string;

Defined in: functions/string.ts:291

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

Parameters

ParameterType
stringstring
matchstring

Returns

string


removeNonPrintableCharacters()

function removeNonPrintableCharacters(string): string;

Defined in: functions/string.ts:303

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


removeWhitespace()

function removeWhitespace(string): string;

Defined in: functions/string.ts:308

Helper function to remove all whitespace characters from a string.

Parameters

ParameterType
stringstring

Returns

string


satisfiesSemanticVersion()

function satisfiesSemanticVersion(version, minimumVersion): boolean;

Defined in: functions/string.ts:318

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

Parameters

ParameterType
versionstring
minimumVersionstring

Returns

boolean

Throws

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


titleCaseToKebabCase()

function titleCaseToKebabCase(string): string;

Defined in: functions/string.ts:353

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

Parameters

ParameterType
stringstring

Returns

string


trimPrefix()

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

Defined in: functions/string.ts:368

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


trimSuffix()

function trimSuffix(string, prefix): string;

Defined in: functions/string.ts:386

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

Parameters

ParameterType
stringstring
prefixstring

Returns

string


truncateString()

function truncateString(string, maxLength): string;

Defined in: functions/string.ts:399

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