rich-domain
Version:
This package provide utils file and interfaces to assistant build a complex application with domain driving design
178 lines • 6.82 kB
TypeScript
import { CalcOpt } from "../types";
/**
* @description Utility class providing various helper methods for date, number, and string manipulations.
*/
export declare class Utils {
private static instance;
private static validator;
/**
* @description Creates a singleton instance of the Utils class.
* @returns {Utils} An instance of the Utils class.
*/
static create(): Utils;
/**
* @description Provides date manipulation utilities for adding or removing units of time.
* @param target The date to manipulate.
* @returns An object with methods for adding or removing units of time (days, hours, etc.).
*/
date(target: Date): {
add: (value: number) => {
/**
* @description add days to a date.
* @returns a new date with incremented days.
*/
days: () => Date;
/**
* @description add hours to a date.
* @returns a new date with incremented hours.
*/
hours: () => Date;
/**
* @description add minutes to a date.
* @returns a new date with incremented minutes.
*/
minutes: () => Date;
/**
* @description add weeks to a date.
* @returns a new date with incremented weeks.
*/
weeks: () => Date;
/**
* @description add months to a date.
* @returns a new date with incremented months.
*/
months: () => Date;
/**
* @description add years to a date.
* @returns a new date with incremented years.
*/
years: () => Date;
};
remove: (value: number) => {
/**
* @description remove days from a date.
* @returns a new date with removed days.
*/
days: () => Date;
/**
* @description remove hours from a date.
* @returns a new date with removed hours.
*/
hours: () => Date;
/**
* @description remove minutes from a date.
* @returns a new date with removed minutes.
*/
minutes: () => Date;
/**
* @description remove weeks from a date.
* @returns a new date with removed weeks.
*/
weeks: () => Date;
/**
* @description remove months from a date.
* @returns a new date with removed months.
*/
months: () => Date;
/**
* @description remove years from a date.
* @returns a new date with removed years.
*/
years: () => Date;
};
};
/**
* @description Provides number manipulation utilities, including mathematical operations.
* @param target The number to manipulate.
* @returns An object with methods for multiplication, division, subtraction, and addition.
*/
number(target: number): {
/**
* @description multiply a value for another one.
* @param value number or string (number)
* @param options as object with fractionDigits option
* @default fractionDigits 5
* @returns result as number
* @sumary If you provide a string NAN (not a number) 0 will be considered as value.
*/
multiplyBy: (value: number, opt?: CalcOpt) => number;
/**
* @description divide a value for another one.
* @param value number or string
* @param options as object with fractionDigits option
* @default fractionDigits 5
* @returns result as number
* @sumary If you provide a string NAN (not a number) 0 will be considered as value.
*/
divideBy: (value: number, opt?: CalcOpt) => number;
/**
* @description subtract a value for another one.
* @param value number or string
* @param options as object with fractionDigits option
* @default fractionDigits 5
* @returns result as number
* @sumary If you provide a string NAN (not a number) 0 will be considered as value.
*/
subtract: (value: number, opt?: CalcOpt) => number;
/**
* @description sum a value with another one.
* @param value number or string
* @param options as object with fractionDigits option
* @default fractionDigits 5
* @returns result as number
* @sumary If you provide a string NAN (not a number) 0 will be considered as value.
*/
sum: (value: number, opt?: CalcOpt) => number;
};
/**
* @description Provides string manipulation utilities, including removing or replacing characters.
* @param target The string to manipulate.
* @returns An object with methods for character removal, space removal, and replacement.
*/
string(target: string): {
/**
* @description remove all special chars from a string.
* @returns string with no special chars.
* @summary special chars: based on ascii table
* @example
* (asciiCode >= 33 && asciiCode <= 47) ||
* (asciiCode >= 58 && asciiCode <= 64) ||
* (asciiCode >= 91 && asciiCode <= 96) ||
* (asciiCode >= 123 && asciiCode <= 126)
*/
removeSpecialChars: () => string;
/**
* @description remove all spaces from text.
* @returns string with no spaces
*/
removeSpaces: () => string;
/**
* @description remove all numbers from a text
* @returns string with no numbers.
*/
removeNumbers: () => string;
/**
* @description remove only specific character from a text.
* @param char character to be removed.
* @returns string without char.
* @memberof replace. If you need to remove a word or more than one character from a text use replace function.
* @see replace
*/
removeChar: (char: string) => string;
/**
* @description replace any character or word from an string for some provided value.
* @param char character or word to be replaced.
* @param value character or word to be aplied.
* @returns text with replaced value.
* @example
* string("hello world").replace("world").to("dear");
*/
replace: (char: string) => {
to: (value: string | number) => string;
};
};
private constructor();
}
declare const _default: Utils;
export default _default;
//# sourceMappingURL=util.d.ts.map