@resk/core
Version:
An innovative TypeScript framework that empowers developers to build applications with a fully decorator-based architecture for efficient resource management. By combining the power of decorators with a resource-oriented design, DecorRes enhances code cla
166 lines (165 loc) • 7.5 kB
TypeScript
/**
* Removes all occurrences of the specified string from the left side of the current string.
*
* This function takes two parameters: the current string and the string to remove.
* If the string to remove is not provided, it defaults to an empty string and the function simply trims the current string.
*
* @param {string} current The string to modify.
* @param {string} [str=""] The string to remove from the left side of the current string.
* @returns {string} The modified string with all occurrences of the specified string removed from the left side.
* @example
* ```typescript
* console.log(ltrim(" hello world", " ")); // Output: "hello world"
* console.log(ltrim("hello world", " ")); // Output: "hello world"
* console.log(ltrim(" hello world")); // Output: "hello world"
* ```
*/
export declare const ltrim: (current: string, str?: string) => string;
/**
* Removes all occurrences of the specified string from the right side of the current string.
*
* This function takes two parameters: the current string and the string to remove.
* If the string to remove is not provided, it defaults to an empty string and the function simply trims the current string.
*
* @param {string} current The string to modify.
* @param {string} [str=""] The string to remove from the right side of the current string.
* @returns {string} The modified string with all occurrences of the specified string removed from the right side.
* @example
* ```typescript
* console.log(rtrim("test heee", "e")); // Output: "test h"
* console.log(rtrim("hello world", " ")); // Output: "hello world"
* console.log(rtrim(" hello world")); // Output: " hello world"
* ```
*/
export declare const rtrim: (current: string, str?: string) => string;
/**
* Checks if the provided string consists only of numbers.
*
* This function takes two parameters: the string to check and an optional flag to indicate whether to consider decimal points.
*
* @param {string} str The string to check.
* @param {boolean} [withDecimal=true] Whether to consider decimal points in the check.
* @returns {boolean} True if the string consists only of numbers, false otherwise.
* @example
* ```typescript
* console.log(isStringNumber("123")); // Output: true
* console.log(isStringNumber("123.45")); // Output: true
* console.log(isStringNumber("123.45", false)); // Output: false
* console.log(isStringNumber("abc")); // Output: false
* ```
*/
export declare const isStringNumber: (str: string, withDecimal?: boolean) => boolean;
/**
* Extends the String interface with additional methods for string manipulation.
*/
declare global {
interface String {
/**
* Removes all occurrences of the specified string from the left side of the string.
* @param {string} [str=""] The string to remove from the left side.
* @returns {string} The modified string with all occurrences of the specified string removed from the left side.
*/
ltrim(str?: string): string;
/**
* Removes all occurrences of the specified string from the right side of the string.
* @param {string} [str=""] The string to remove from the right side.
* @returns {string} The modified string with all occurrences of the specified string removed from the right side.
*/
rtrim(str?: string): string;
/**
* Checks if the string consists only of numbers.
* @param {boolean} [withDecimal=true] Whether to consider decimal points in the check.
* @returns {boolean} True if the string consists only of numbers, false otherwise.
*/
isNumber(withDecimal?: boolean): boolean;
/**
* Converts the string to snake case (e.g. "hello world" becomes "hello_world").
* @returns {string} The string in snake case.
*/
toSnakeCase(): string;
/**
* Converts the string to camel case (e.g. "hello world" becomes "helloWorld").
* @returns {string} The string in camel case.
*/
toCamelCase(): string;
/**
* Converts the first character of the string to uppercase.
* @returns {string} The string with the first character in uppercase.
*/
upperFirst(): string;
/**
* Converts the first character of the string to lowercase.
* @returns {string} The string with the first character in lowercase.
*/
lowerFirst(): string;
/**
* Replaces all occurrences of the specified string with another string.
* @param {string} find The string to replace.
* @param {string} replace The string to replace with.
* @returns {string} The string with all occurrences replaced.
*/
replaceAll(find: string, replace: string): string;
}
}
/**
* Converts a string from camel case to snake case (e.g. "addElementComponent" becomes "ADD_ELEMENT_COMPONENT").
*
* This function takes a string as input, trims it, and then replaces all occurrences of camel case with underscores.
* The resulting string is then converted to uppercase.
*
* @param {string} text The string to convert.
* @returns {string} The string in snake case.
* @example
* ```typescript
* console.log(toSnakeCase("thisISDifficult")); // Output: "THIS_IS_DIFFICULT"
* console.log(toSnakeCase("thisISNT")); // Output: "THIS_ISNT"
* console.log(toSnakeCase("addElementComponent")); // Output: "ADD_ELEMENT_COMPONENT"
* ```
*/
export declare const toSnakeCase: (text: string) => string;
/**
* Converts a string from snake case to camel case (e.g. "ADD_ELEMENT_COMPONENT" becomes "addElementComponent").
*
* This function takes a string as input, trims it, and then replaces all occurrences of underscores with uppercase letters.
* The resulting string is then converted to camel case by making the first character lowercase.
*
* @param {string} text The string to convert.
* @returns {string} The string in camel case.
* @example
* ```typescript
* console.log(toCamelCase("THIS_IS_DIFFICULT")); // Output: "thisISDifficult"
* console.log(toCamelCase("THIS_ISNT")); // Output: "thisISNT"
* console.log(toCamelCase("ADD_ELEMENT_COMPONENT")); // Output: "addElementComponent"
* ```
*/
export declare const toCamelCase: (text: string) => string;
/**
* Converts the first character of a string to uppercase.
*
* This function takes a string as input, trims it, and then converts the first character to uppercase.
*
* @param {string} str The string to modify.
* @returns {string} The modified string with the first character in uppercase.
* @example
* ```typescript
* console.log(upperFirst("hello world")); // Output: "Hello world"
* console.log(upperFirst("HELLO WORLD")); // Output: "HELLO WORLD"
* console.log(upperFirst("")); // Output: ""
* ```
*/
export declare const upperFirst: (str: string) => string;
/**
* Converts the first character of a string to lowercase.
*
* This function takes a string as input, trims it, and then converts the first character to lowercase.
*
* @param {string} str The string to modify.
* @returns {string} The modified string with the first character in lowercase.
* @example
* ```typescript
* console.log(lowerFirst("Hello World")); // Output: "hello World"
* console.log(lowerFirst("HELLO WORLD")); // Output: "hello WORLD"
* console.log(lowerFirst("")); // Output: ""
* ```
*/
export declare const lowerFirst: (str: string) => string;