String
Helper functions that have to do with strings.
Functions
Section titled “Functions”capitalizeFirstLetter()
Section titled “capitalizeFirstLetter()”function capitalizeFirstLetter(string): string;Defined in: functions/string.ts:38
Helper function to capitalize the first letter of a string.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
string |
string |
Returns
Section titled “Returns”string
escapeHTMLCharacters()
Section titled “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 <.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
string |
string |
Returns
Section titled “Returns”string
getNumConsecutiveDiacritics()
Section titled “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
Section titled “Parameters”| Parameter | Type |
|---|---|
string |
string |
Returns
Section titled “Returns”number
hasDiacritic()
Section titled “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
Section titled “Parameters”| Parameter | Type |
|---|---|
string |
string |
Returns
Section titled “Returns”boolean
hasEmoji()
Section titled “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
Section titled “Parameters”| Parameter | Type |
|---|---|
string |
string |
Returns
Section titled “Returns”boolean
hasWhitespace()
Section titled “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
Section titled “Parameters”| Parameter | Type |
|---|---|
string |
string |
Returns
Section titled “Returns”boolean
isASCII()
Section titled “isASCII()”function isASCII(str): boolean;Defined in: functions/string.ts:118
Helper function to determine if a string only contains ASCII characters.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
str |
string |
Returns
Section titled “Returns”boolean
isFirstLetterCapitalized()
Section titled “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
Section titled “Parameters”| Parameter | Type |
|---|---|
string |
string |
Returns
Section titled “Returns”boolean
isKebabCase()
Section titled “isKebabCase()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
string |
string |
Returns
Section titled “Returns”boolean
isLowerCase()
Section titled “isLowerCase()”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).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
string |
string |
Returns
Section titled “Returns”boolean
isSemanticVersion()
Section titled “isSemanticVersion()”function isSemanticVersion(versionString): boolean;Defined in: functions/string.ts:150
Helper function to check if a given string is a valid Semantic Version.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
versionString |
string |
Returns
Section titled “Returns”boolean
isUpperCase()
Section titled “isUpperCase()”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).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
string |
string |
Returns
Section titled “Returns”boolean
kebabCaseToCamelCase()
Section titled “kebabCaseToCamelCase()”function kebabCaseToCamelCase(string): string;Defined in: functions/string.ts:160
Helper function to convert a string from kebab-case to camelCase.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
string |
string |
Returns
Section titled “Returns”string
kebabCaseToPascalCase()
Section titled “kebabCaseToPascalCase()”function kebabCaseToPascalCase(string): string;Defined in: functions/string.ts:170
Helper function to convert a string from kebab-case to PascalCase.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
string |
string |
Returns
Section titled “Returns”string
normalizeString()
Section titled “normalizeString()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
string |
string |
Returns
Section titled “Returns”string
parseSemanticVersion()
Section titled “parseSemanticVersion()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
versionString |
string |
Returns
Section titled “Returns”|
SemanticVersion
| undefined
removeLinesBetweenMarkers()
Section titled “removeLinesBetweenMarkers()”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-startline2line3# @foo-endline4Would return:
line1line4Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
string |
string |
marker |
string |
Returns
Section titled “Returns”string
removeLinesMatching()
Section titled “removeLinesMatching()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
string |
string |
match |
string |
Returns
Section titled “Returns”string
removeNonPrintableCharacters()
Section titled “removeNonPrintableCharacters()”function removeNonPrintableCharacters(string): string;Defined in: functions/string.ts:306
Helper function to remove all non-printable characters from a string.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
string |
string |
Returns
Section titled “Returns”string
removeWhitespace()
Section titled “removeWhitespace()”function removeWhitespace(string): string;Defined in: functions/string.ts:311
Helper function to remove all whitespace characters from a string.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
string |
string |
Returns
Section titled “Returns”string
satisfiesSemanticVersion()
Section titled “satisfiesSemanticVersion()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
version |
string |
minimumVersion |
string |
Returns
Section titled “Returns”boolean
Throws
Section titled “Throws”If either the version or minimum version are not valid semantic versions.
titleCaseToKebabCase()
Section titled “titleCaseToKebabCase()”function titleCaseToKebabCase(string): string;Defined in: functions/string.ts:356
Helper function to convert a string from TitleCase (PascalCase) to kebab-case.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
string |
string |
Returns
Section titled “Returns”string
trimPrefix()
Section titled “trimPrefix()”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.
Parameters
Section titled “Parameters”| 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. |
Returns
Section titled “Returns”string
trimSuffix()
Section titled “trimSuffix()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
string |
string |
prefix |
string |
Returns
Section titled “Returns”string
truncateString()
Section titled “truncateString()”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.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
string |
string |
maxLength |
number |
Returns
Section titled “Returns”string
