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