String
Functions
Section titled “Functions”capitalizeFirstLetter()
Section titled “capitalizeFirstLetter()”capitalizeFirstLetter(
string):string
Defined in: packages/isaacscript-common/src/functions/string.ts:5
Parameters
Section titled “Parameters”string
Section titled “string”string
Returns
Section titled “Returns”string
getMapPartialMatch()
Section titled “getMapPartialMatch()”getMapPartialMatch<
T>(searchText,map): [string,T] |undefined
Defined in: packages/isaacscript-common/src/functions/string.ts:40
Helper function to get the closest key from a map based on partial search text. (It only searches through the keys, not the values.)
Note that:
- Spaces are automatically removed from the search text.
- Both the search text and the strings to search through are converted to lowercase before attempting to find a match.
For example:
const map = new <string, number>Map([ ["foo", 123], ["bar", 456],]);const searchText = "f";const match = getMapPartialMatch(map, searchText); // match is now equal to ["foo", 123]Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”searchText
Section titled “searchText”string
ReadonlyMap<string, T>
Returns
Section titled “Returns”[string, T] | undefined
If a match was found, returns a tuple of the map key and value. If a match was not found, returns undefined.
getObjectPartialMatch()
Section titled “getObjectPartialMatch()”getObjectPartialMatch<
T>(searchText,object): [string,T] |undefined
Defined in: packages/isaacscript-common/src/functions/string.ts:83
Helper function to get the closest key from an object based on partial search text. (It only searches through the keys, not the values.)
Note that:
- Spaces are automatically removed from the search text.
- Both the search text and the strings to search through are converted to lowercase before attempting to find a match.
For example:
const object = { foo: 123, bar: 456,};const searchText = "f";const match = getObjectPartialMatch(object, searchText); // match is now equal to ["foo", 123]Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”searchText
Section titled “searchText”string
object
Section titled “object”ReadonlyRecord<string, T>
Returns
Section titled “Returns”[string, T] | undefined
If a match was found, returns a tuple of the map key and value. If a match was not found, returns undefined.
getPartialMatch()
Section titled “getPartialMatch()”getPartialMatch(
searchText,array):string|undefined
Defined in: packages/isaacscript-common/src/functions/string.ts:122
Helper function to get the closest value from an array of strings based on partial search text.
Note that:
- Spaces are automatically removed from the search text.
- Both the search text and the strings to search through are converted to lowercase before attempting to find a match.
For example:
const array = ["foo", "bar"];const searchText = "f";const match = getPartialMatch(array, searchText); // match is now equal to "foo"Parameters
Section titled “Parameters”searchText
Section titled “searchText”string
readonly string[]
Returns
Section titled “Returns”string | undefined
If a match was found, returns the array element. If a match was not found, returns undefined.
parseSemanticVersion()
Section titled “parseSemanticVersion()”parseSemanticVersion(
versionString): {majorVersion:int;minorVersion:int;patchVersion:int; } |undefined
Defined in: packages/isaacscript-common/src/functions/string.ts:145
Helper function to parse a Semantic Versioning string into its individual constituents. Returns undefined if the submitted string was not a proper Semantic Version string.
Parameters
Section titled “Parameters”versionString
Section titled “versionString”string
Returns
Section titled “Returns”{ majorVersion: int; minorVersion: int; patchVersion: int; } | undefined
removeAllCharacters()
Section titled “removeAllCharacters()”removeAllCharacters(
string,character):string
Defined in: packages/isaacscript-common/src/functions/string.ts:182
Parameters
Section titled “Parameters”string
Section titled “string”string
character
Section titled “character”string
Returns
Section titled “Returns”string
removeCharactersBefore()
Section titled “removeCharactersBefore()”removeCharactersBefore(
string,substring):string
Defined in: packages/isaacscript-common/src/functions/string.ts:190
Helper function to remove all of the characters in a string before a given substring. Returns the modified string.
Parameters
Section titled “Parameters”string
Section titled “string”string
substring
Section titled “substring”string
Returns
Section titled “Returns”string
removeNonAlphanumericCharacters()
Section titled “removeNonAlphanumericCharacters()”removeNonAlphanumericCharacters(
str):string
Defined in: packages/isaacscript-common/src/functions/string.ts:199
Helper function to remove all characters from a string that are not letters or numbers.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”string
removeSubstring()
Section titled “removeSubstring()”removeSubstring(
string, …substrings):string
Defined in: packages/isaacscript-common/src/functions/string.ts:210
Helper function to remove one or more substrings from a string, if they exist. Returns the modified string.
This function is variadic, meaning that you can pass as many substrings as you want to remove.
Parameters
Section titled “Parameters”string
Section titled “string”string
substrings
Section titled “substrings”…readonly string[]
Returns
Section titled “Returns”string
trimPrefix()
Section titled “trimPrefix()”trimPrefix(
string,prefix):string
Defined in: packages/isaacscript-common/src/functions/string.ts:222
Helper function to trim a prefix from a string, if it exists. Returns the trimmed string.
Parameters
Section titled “Parameters”string
Section titled “string”string
prefix
Section titled “prefix”string
Returns
Section titled “Returns”string
trimSuffix()
Section titled “trimSuffix()”trimSuffix(
string,prefix):string
Defined in: packages/isaacscript-common/src/functions/string.ts:231
Helper function to trim a suffix from a string, if it exists. Returns the trimmed string.
Parameters
Section titled “Parameters”string
Section titled “string”string
prefix
Section titled “prefix”string
Returns
Section titled “Returns”string
uncapitalizeFirstLetter()
Section titled “uncapitalizeFirstLetter()”uncapitalizeFirstLetter(
string):string
Defined in: packages/isaacscript-common/src/functions/string.ts:240
Parameters
Section titled “Parameters”string
Section titled “string”string
Returns
Section titled “Returns”string
