isaacscript-common
Version:
Helper functions and features for IsaacScript mods.
102 lines • 4.18 kB
TypeScript
import type { ReadonlyRecord } from "../types/ReadonlyRecord";
export declare function capitalizeFirstLetter(string: string): string;
/**
* 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:
*
* ```ts
* 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]
* ```
*
* @returns If a match was found, returns a tuple of the map key and value. If a match was not
* found, returns undefined.
*/
export declare function getMapPartialMatch<T>(searchText: string, map: ReadonlyMap<string, T>): [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:
*
* ```ts
* const object = {
* foo: 123,
* bar: 456,
* };
* const searchText = "f";
* const match = getObjectPartialMatch(object, searchText); // match is now equal to ["foo", 123]
* ```
*
* @returns If a match was found, returns a tuple of the map key and value. If a match was not
* found, returns undefined.
*/
export declare function getObjectPartialMatch<T>(searchText: string, object: ReadonlyRecord<string, T>): [string, T] | 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:
*
* ```ts
* 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.
*/
export declare function getPartialMatch(searchText: string, array: readonly string[]): string | 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.
*
* @see https://semver.org/
*/
export declare function parseSemanticVersion(versionString: string): {
majorVersion: int;
minorVersion: int;
patchVersion: int;
} | undefined;
export declare function removeAllCharacters(string: string, character: string): string;
/**
* Helper function to remove all of the characters in a string before a given substring. Returns the
* modified string.
*/
export declare function removeCharactersBefore(string: string, substring: string): string;
/** Helper function to remove all characters from a string that are not letters or numbers. */
export declare function removeNonAlphanumericCharacters(str: string): 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.
*/
export declare function removeSubstring(string: string, ...substrings: readonly string[]): string;
/** Helper function to trim a prefix from a string, if it exists. Returns the trimmed string. */
export declare function trimPrefix(string: string, prefix: string): string;
/** Helper function to trim a suffix from a string, if it exists. Returns the trimmed string. */
export declare function trimSuffix(string: string, prefix: string): string;
export declare function uncapitalizeFirstLetter(string: string): string;
//# sourceMappingURL=string.d.ts.map