String
Functions
capitalizeFirstLetter
▸ capitalizeFirstLetter(string): string
Parameters
| Name | Type |
|---|---|
string | string |
Returns
string
Defined in
packages/isaacscript-common/src/functions/string.ts:5
getMapPartialMatch
▸ getMapPartialMatch<T>(searchText, map): [string, T] | undefined
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
| Name |
|---|
T |
Parameters
| Name | Type |
|---|---|
searchText | string |
map | ReadonlyMap<string, T> |
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.
Defined in
packages/isaacscript-common/src/functions/string.ts:40
getObjectPartialMatch
▸ getObjectPartialMatch<T>(searchText, object): [string, T] | undefined
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
| Name |
|---|
T |
Parameters
| Name | Type |
|---|---|
searchText | string |
object | Readonly<Record<string, T>> |
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.
Defined in
packages/isaacscript-common/src/functions/string.ts:83
getPartialMatch
▸ getPartialMatch(searchText, array): string | undefined
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"
@returns If a match was found, returns the array element. If a match was not
found, returns undefined.
Parameters
| Name | Type |
|---|---|
searchText | string |
array | readonly string[] |
Returns
string | undefined
Defined in
packages/isaacscript-common/src/functions/string.ts:122
parseSemanticVersion
▸ parseSemanticVersion(versionString): { majorVersion: int ; minorVersion: int ; patchVersion: int } | 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 string.
Parameters
| Name | Type |
|---|---|
versionString | string |
Returns
{ majorVersion: int ; minorVersion: int ; patchVersion: int } | undefined
See
Defined in
packages/isaacscript-common/src/functions/string.ts:145
removeAllCharacters
▸ removeAllCharacters(string, character): string
Parameters
| Name | Type |
|---|---|
string | string |
character | string |
Returns
string
Defined in
packages/isaacscript-common/src/functions/string.ts:178
removeCharactersBefore
▸ removeCharactersBefore(string, substring): string
Helper function to remove all of the characters in a string before a given substring. Returns the modified string.
Parameters
| Name | Type |
|---|---|
string | string |
substring | string |
Returns
string
Defined in
packages/isaacscript-common/src/functions/string.ts:186
removeNonAlphanumericCharacters
▸ removeNonAlphanumericCharacters(str): string
Helper function to remove all characters from a string that are not letters or numbers.
Parameters
| Name | Type |
|---|---|
str | string |
Returns
string
Defined in
packages/isaacscript-common/src/functions/string.ts:195
removeSubstring
▸ removeSubstring(string, ...substrings): string
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
| Name | Type |
|---|---|
string | string |
...substrings | readonly string[] |
Returns
string
Defined in
packages/isaacscript-common/src/functions/string.ts:206
trimPrefix
▸ trimPrefix(string, prefix): string
Helper function to trim a prefix from a string, if it exists. Returns the trimmed string.
Parameters
| Name | Type |
|---|---|
string | string |
prefix | string |
Returns
string
Defined in
packages/isaacscript-common/src/functions/string.ts:218
trimSuffix
▸ trimSuffix(string, prefix): string
Helper function to trim a suffix from a string, if it exists. Returns the trimmed string.
Parameters
| Name | Type |
|---|---|
string | string |
prefix | string |
Returns
string
Defined in
packages/isaacscript-common/src/functions/string.ts:227
uncapitalizeFirstLetter
▸ uncapitalizeFirstLetter(string): string
Parameters
| Name | Type |
|---|---|
string | string |
Returns
string