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
Parameter | Type |
---|---|
string | string |
Returns
string
Defined in
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
Parameter | Type |
---|---|
string | string |
Returns
string
Defined in
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
Parameter | Type |
---|---|
string | string |
Returns
number
Defined in
hasDiacritic()
function hasDiacritic(string): boolean
Helper function to check if a string has one or more diacritics in it.
Parameters
Parameter | Type |
---|---|
string | string |
Returns
boolean
Defined in
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
Parameter | Type |
---|---|
string | string |
Returns
boolean
Defined in
hasWhitespace()
function hasWhitespace(string): boolean
From: https://stackoverflow.com/questions/1731190/check-if-a-string-has-white-space
Parameters
Parameter | Type |
---|---|
string | string |
Returns
boolean
Defined in
isFirstLetterCapitalized()
function isFirstLetterCapitalized(string): boolean
From: https://stackoverflow.com/questions/8334606/check-if-first-letter-of-word-is-a-capital-letter
Parameters
Parameter | Type |
---|---|
string | string |
Returns
boolean
Defined in
isKebabCase()
function isKebabCase(string): boolean
Kebab case is the naming style of using all lowercase and hyphens, like "foo-bar".
Parameters
Parameter | Type |
---|---|
string | string |
Returns
boolean
Defined in
isSemanticVersion()
function isSemanticVersion(versionString): boolean
Helper function to check if a given string is a valid Semantic Version.
Parameters
Parameter | Type |
---|---|
versionString | string |
Returns
boolean
See
Defined in
kebabCaseToCamelCase()
function kebabCaseToCamelCase(string): string
Helper function to convert a string from kebab-case to camel-case.
Parameters
Parameter | Type |
---|---|
string | string |
Returns
string
Defined in
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
Parameter | Type |
---|---|
string | string |
Returns
string
See
Defined in
parseSemanticVersion()
function parseSemanticVersion(versionString): {
majorVersion: number;
minorVersion: number;
patchVersion: number;
} | 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
Parameter | Type |
---|---|
versionString | string |
Returns
{
majorVersion
: number
;
minorVersion
: number
;
patchVersion
: number
;
} | undefined
See
Defined in
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
Parameter | Type |
---|---|
string | string |
marker | string |
Returns
string
Defined in
removeLinesMatching()
function removeLinesMatching(string, match): string
Helper function to remove lines from a multi-line string matching a certain other string.
Parameters
Parameter | Type |
---|---|
string | string |
match | string |
Returns
string
Defined in
removeNonPrintableCharacters()
function removeNonPrintableCharacters(string): string
Helper function to remove all non-printable characters from a string.
Parameters
Parameter | Type |
---|---|
string | string |
Returns
string
See
Defined in
removeWhitespace()
function removeWhitespace(string): string
Helper function to remove all whitespace characters from a string.
Parameters
Parameter | Type |
---|---|
string | string |
Returns
string
Defined in
trimPrefix()
function trimPrefix(
string,
prefix,
trimAll): string
Helper function to trim a prefix from a string, if it exists. Returns the trimmed string.
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
string
Defined in
trimSuffix()
function trimSuffix(string, prefix): string
Helper function to trim a suffix from a string, if it exists. Returns the trimmed string.
Parameters
Parameter | Type |
---|---|
string | string |
prefix | string |
Returns
string
Defined in
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
Parameter | Type |
---|---|
string | string |
maxLength | number |
Returns
string