sussy-util
Version:
Util package made by me
310 lines (309 loc) • 14.4 kB
TypeScript
export default class StringUtil {
private static dedupeChars;
private static safeCharset;
/**
* It takes a string, splits it into an array of characters, reverses the array, and joins the
* array back into a string
* @param {string} input - The string to be reversed.
* @returns The reverse of the input string.
*/
static reverse(input: string): string;
/**
* It takes a string of characters and returns a random character from that string.
* @param {string} [charset] - The characters to choose from. Defaults to all alphanumeric
* characters.
* @returns A random character from the charset.
*/
static randomCharacter(charset?: string): string;
/**
* Generate a random string of a given length, using a given character set.
* @param {number} length - number - The length of the string to generate
* @param {string} [characterset] - The characterset to use for the random string.
* @returns A string of random characters.
*/
static randomString(length: number, characterset?: string): string;
/**
* It generates a random string, checks if it's a valid discord username, if it's not, it generates
* another one, if it is, it returns it.
* @param [withSuffix=false] - boolean
* @returns A random string that is a valid discord username.
* @deprecated
*/
static randomDiscordUsername(withSuffix?: boolean): string;
/**
* It returns true if the username is a valid Discord username, and false if it isn't
* @param {string} username - The username to check.
* @returns A boolean value.
* @deprecated
*/
static isDiscordUsername(username: string): boolean;
/**
* If the value is a string, and the string contains only digits, then return true. Otherwise,
* return false
* @param {string} value - The value to be tested.
* @returns A boolean value.
*/
static isInteger(value: string): boolean;
/**
* It returns true if the value is a float, otherwise it returns false
* @param {string} value - string - The value to check
* @returns A boolean value.
*/
static isFloat(value: string): boolean;
/**
* The password must be at least eight characters long and contain at least one lowercase letter,
* one uppercase letter, one numeric digit, and one special character
* @param {string} value - string - The value to check
* @returns A boolean value.
*/
static isStrongPassword(value: string): boolean;
/**
* If the password is not strong, then it is weak.
* @param {string} value - string - The value to check.
* @returns The return value is a boolean.
*/
static isWeakPassword(value: string): boolean;
/**
* It checks if the value is a string, and if it is, it checks if the string is at least 4
* characters long, contains an @ symbol, and ends with a . followed by at least 2 characters
* @param {string} value - string - The value to be tested.
* @returns A boolean value.
*/
static isEmail(value: string): boolean;
/**
* It checks if the value is a valid HTTP URL.
* @param {string} value - The value to be tested.
* @returns A boolean value.
*/
static isHTTPUrl(value: string): boolean;
/**
* It checks if the value is a valid URL without the HTTP or HTTPS prefix
* @param {string} value - string - The value to be tested.
* @returns A boolean value.
*/
static isUrlWithoutHTTP(value: string): boolean;
/**
* If the string is a URL, return true, otherwise return false.
* @param {string} value - string
* @returns A boolean value.
*/
static isURL(value: string): boolean;
/**
* It takes a string, a length, and an ellipsis count, and returns a string that is the original
* string shortened to the length, with the ellipsis count number of ellipses appended to the end.
*
* @param {string} value - The string to shorten
* @param {number} length - The length of the string you want to return.
* @param {number} ellipsisCount - The number of dots to use in the ellipsis.
* @returns The value of the string is being returned.
*/
static shorten(value: string, length: number, ellipsisCount: number): string;
/**
* It takes a string, converts it to lowercase, trims it, removes all non-word characters, replaces
* all whitespace and underscores with a dash, and removes all leading and trailing dashes
* @param {string} str - string - The string to slugify
* @returns A string
*/
static slugify(str: string): string;
/**
* Capitalize the first letter of a string and lowercase the rest.
* @param {string} value - string - The string to be capitalized.
* @returns The first character of the string is being returned in uppercase and the rest of the
* string is being returned in lowercase.
*/
static capitalize(value: string): string;
/**
* It takes a string and returns the same string with the first letter lowercase.
* @param {string} value - string - The string to uncapitalize.
* @returns The first character of the string is converted to lowercase and then concatenated with
* the rest of the string.
*/
static uncapitalize(value: string): string;
/**
* It returns true if the value is a valid IPv4 address, otherwise it returns false.
* @param {string} value - The value to check.
* @returns A boolean value.
*/
static isIPv4(value: string): boolean;
/**
* It checks if the value is a valid IPv6 address.
* @param {string} value - The value to check.
* @returns A boolean value.
*/
static isIPv6(value: string): boolean;
/**
* If the value is an IPv4 address, return true. Otherwise, if the value is an IPv6 address,
* return true. Otherwise, return false.
* @param {string} value - string
* @returns A boolean value.
*/
static isIP(value: string): boolean;
/**
* It returns true if the value is a valid MAC address, otherwise it returns false
* @param {string} value - The value to check.
* @returns A boolean value.
*/
static isMacAddress(value: string): boolean;
/**
* If the value is a string that matches the regular expression, then return true, otherwise return
* false.
* @param {string} value - string - The value to be tested.
* @returns A boolean value.
*/
static isPhoneNumber(value: string): boolean;
/**
* It takes a string, gets the first character, makes it uppercase, and then adds the rest of the
* string to it
* @param {string} str - string - The string to be converted.
* @returns The first character of the string is being returned in uppercase, and the rest of the
* string is being returned in lowercase.
*/
static upperFirst(str: string): string;
/**
* It takes a string, and returns a new string with the first character lowercased
* @param {string} str - string - The string to be converted.
* @returns The first character of the string is being returned in lowercase, and the rest of the
* string is being returned in its original case.
*/
static lowerFirst(str: string): string;
/**
* It takes a string, splits it on non-word characters and underscores, capitalizes each word, and
* joins them together
* @param {string} str - string - The string to be converted to camelCase
* @returns The first letter of the string is being returned in lowercase.
*/
static camelCase(str: string): string;
/**
* It takes a string, trims it, splits it into an array of words, filters out any empty words, and
* then joins the array back into a string
* @param {string} str - string - The string to be collapsed.
* @returns A string
*/
static collaps(str: string): string;
/**
* It takes a string, trims it, splits it into an array of strings, and then joins it back together
* @param {string} str - string - The string to be trimmed.
* @returns The string with no spaces.
*/
static noSpaces(str: string): string;
/**
* It takes a string, splits it into an array of characters, maps each character to its charCode,
* and then joins the array of charCodes into a string
* @param {string} str - string - The string to convert to char codes.
* @returns The charCodeAt() method returns an integer between 0 and 65535 representing the UTF-16
* code unit at the given index.
*/
static toCharCode(str: string): string;
/**
* It takes a string, checks if it's an email, splits it in half, shortens the first half, and
* returns the result.
* @param {string} str - string - The string to protect
* @returns The email address with the first half of the email address shortened to 3 characters.
*/
static protectEmail(str: string): string;
/**
* It takes a string, and returns a string with the first letter of each word capitalized, and the
* rest of the letters lowercase.
* @param {string} str - string - The string to be swapped.
* @returns the string with the first letter of each word capitalized.
*/
static swapCase(str: string): string;
/**
* It generates a random string of a given length, using a given set of characters, and if the
* generated string is not strong enough, it generates another one
* @param {number} length - number - The length of the password to generate
* @param {string} [characters] - string =
* "ascdefghijklmnopqrstuvwxyzABCDEFGHIJLMOPRSTUVWXYZ1234567890!$$%&?#*+~'"
* @returns A string of length `length` that is a strong password.
*/
static generatePassword(length: number, characters?: string): string;
/**
* It returns a random color code in hexadecimal format.
* @returns A random color code.
*/
static randomColorCode(): string;
/**
* It returns the number of words in a string.
* @param {string} str - string - The string to count the words in.
* @returns The number of words in the string.
*/
static wordCount(str: string): number;
static getRatingString(rate: number): string;
/**
* It replaces all line breaks with the lineEnd parameter.
* @param {string} str - string - The string to normalize.
* @param {string} [lineEnd] - The line ending to normalize to (defaults to \n).
* @returns A string with all line breaks normalized to the specified lineEnd string, or the
* default lineEnd string.
*/
static normalizeLineBreaks(str: string, lineEnd?: string): string;
/**
* It returns true if the string contains the substring, otherwise it returns false
* @param {string} str - The string to search in.
* @param {string} substring - The substring to search for.
* @param {number} fromIndex - The index at which to begin searching the String object. If omitted,
* search starts at the beginning of the string.
* @returns The index of the first occurrence of the specified substring, or -1 if there is no such
* occurrence.
*/
static contains(str: string, substring: string, fromIndex: number): boolean;
/**
* @param {string} str - string - The string to pad.
* @param {number} minLen - The minimum length of the string.
* @param {string} [ch] - The character to pad the string with.
* @returns The string with the padding added to it.
*/
static rpad(str: string, minLen: number, ch?: string): string;
/**
* @param {string} str - string - The string to pad.
* @param {number} minLen - The minimum length of the string.
* @param {string} [ch] - The character to pad the string with.
* @returns The string with the padding.
*/
static lpad(str: string, minLen: number, ch?: string): string;
/**
* It takes a string, an offset, a removeCount, and a text, and returns a string.
* @param {string} str - string - The string to be spliced.
* @param {number} offset - The index of the string to start replacing at.
* @param {number | undefined} removeCount - The amount of characters to remove from the string.
* @param [text] - The text to insert into the string.
* @returns The string with the text inserted at the offset.
*/
static splice(str: string, offset: number, removeCount: number | undefined, text?: string): string;
/**
* If the string is null, empty, or equal to an empty string, then it is empty
* @param {string} str - string - The string to check if it's empty.
* @returns a boolean value.
*/
static isEmpty(str: string | null | undefined): boolean;
/**
* It removes all the leading white spaces from a string.
* @param {string} str - The string to be trimmed.
* @returns The string with the leading whitespace removed.
*/
static ltrim(str: string): string;
/**
* It replaces all the spaces at the end of the string with nothing
* @param {string} str - The string to trim.
* @returns The string with the whitespace removed from the end.
*/
static rtrim(str: string): string;
/**
* It takes a string and replaces any lowercase letter followed by an uppercase letter with the
* lowercase letter followed by a dash followed by the uppercase letter.
* @param {string} str - string - The string to convert
* @returns The string with the first letter lowercase.
*/
static camelToKebab(str: string): string;
/**
* We take a string, convert it to lowercase, split it into an array, reverse the array, join the
* array back into a string, and then compare the reversed string to the original string.
* @param {string} str - string - the string to check if it's a palindrome
* @returns A boolean value.
*/
static isPalindrome(str: string): boolean;
}
export declare const reverse: (s: string) => string;
export declare const isEmpty: (s?: string | null) => boolean;
export declare const randomString: (len: number, cs?: string) => string;
export declare const slugify: (s: string) => string;