Skip to main content

String

Helper functions that have to do with strings.

Functions

capitalizeFirstLetter()

function capitalizeFirstLetter(string): string;

Defined in: functions/string.ts:31

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:48

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


getNumConsecutiveDiacritics()

function getNumConsecutiveDiacritics(string): number;

Defined in: functions/string.ts:63

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:87

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:101

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:106

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:111

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:119

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:128

"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:133

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:142

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:147

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:152

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:162

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:178

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): 
| {
majorVersion: number;
minorVersion: number;
patchVersion: number;
}
| undefined;

Defined in: functions/string.ts:203

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

{
majorVersion: number;
minorVersion: number;
patchVersion: number;
}
NameTypeDescriptionDefined in
majorVersionnumberThe first number inside of the semantic version.functions/string.ts:206
minorVersionnumberThe second number inside of the semantic version.functions/string.ts:209
patchVersionnumberThe third number inside of the semantic version.functions/string.ts:212

undefined

See

https://semver.org/


removeLinesBetweenMarkers()

function removeLinesBetweenMarkers(string, marker): string;

Defined in: functions/string.ts:264

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:293

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:305

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:310

Helper function to remove all whitespace characters from a string.

Parameters

ParameterType
stringstring

Returns

string


trimPrefix()

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

Defined in: functions/string.ts:322

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:340

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:353

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