@mauchero/helpers
v1.0.84
Published
Generic functions to help dev
Readme
helpers
Generic functions to help develop all apps
to use:
npm i @mauchero/helpers
helpers
warning
- this repo is private, but the code is public in npm
- do not put sensitive/confidential information here
current functions
Shortcuts
clog(message?: any, ...optionalParams: any[])cloj(value: any, space: string | number | undefined = 2)cloe(message?: any, ...optionalParams: any[])jstr(value: any, space: string | number | undefined = 2)
API Related
recordError(db: firebase.Firestore, errorInfo: any): Promise<void>
Mathematics
arraySum(array: number[]): numberround(number: number, decimals: number): numberroundFloor(number: number, decimals: number): numberroundCeil(number: number, decimals: number): numberaverage(array: number[]): numbergetHighestBetweenTwo(value1: number, value2: number): numbergetLowestBetweenTwo(value1: number, value2: number): numberintToFloat(intValue: number, decimals?: number): number
Generic
removeDuplicates(arr: any[]): any[]copyToClipboardWeb(copyText: string): Promise<boolean>isObjEmpty(obj: Object): booleanopenInNewTab(url: string): voidreloadPage(): voidonClickUrl(url: string): () => voidvarToString(varObj: Object): stringbuildMap(keys: (keyof Object)[], values: any[]): ObjectisHex(hex: any): booleanhex2Int(hex: any): numbersleep(milliseconds: number): voidstring2Float(strNumber: string): numberfetchImage(imageUrl: string): Promise<void>reorderListSmallestToLargest(oldList: any[], orderKeyParam: string): any[]reorderListLargestToSmallest(oldList: any[], orderKeyParam: string): any[]checkCpfNumberValidity(cpf: string): booleanreorderListSubParam(oldList: Object[], orderKeyParam: keyof Object, orderKeySubParam: keyof Object): Object[]
Formatting Stuff
formatPrice(numFloat: number, fiatSymbol: "BRL" | "USD" = "BRL"): stringformatPercentage(numFloat: number, fractionDigits: number = 2): stringformatCpf(cpf: string): stringformatPhone(phone: string): stringformatDate(date: string): stringisDateValid(date: string): booleanisUserMinor(birthDate: string, minAge: number): booleancalculateAge(birthDateStr: string): numbergetOnlyNumbers(str: string): stringfloat2INFormat(number: number, decimals: number): stringdarkenHexColor(hexColor: string, factor: number): stringremoveSpaces(inputString: string): stringreplacePtBrCharacters(inputString: string): string
Time
secsToDateTime(secs: number): stringsecsToLocaleDateTime(secs: number): stringtoLongFormatDateTime(secs: number): DategetLocalTimezoneOffset(): numbertoTimestamp(strDate: string): numberadjustDateMonthToName(date: string): stringnumberToMonth(month: string): string
