jsm-utilities
Version:
A utilities library.
82 lines (81 loc) • 4.03 kB
TypeScript
/**
* @description Uses lodash flatten to split a string by , / ; +
* @param str string to split
* @returns {string[]}
*/
export declare const splitString: (str: string, use_plus_character?: boolean) => string[];
export declare const stringToBoolean: (str: string) => boolean;
export declare const addLeadingZeros: (num: number, totalLength: number) => string;
export declare const toPriceAmount: (str: string) => number;
export declare const isNumeric: (val: string) => boolean;
export declare const abbreviateNumber: (n: number) => string;
export declare const createBigram: (word: string) => string[];
export declare const checkSimilarity: (a: string, b: string) => number;
export declare const generateStringNgrams: (str: string) => string[];
export declare const formatBytes: (bytes: number, decimals?: number) => string;
export declare const generateSlug: (title: string) => Promise<string>;
export declare const toSnakeCase: (str: string) => string;
export declare const toKebabCase: (input: string) => string;
export declare function capitalizeFirstLetter(str: string): string;
export declare function kebabToCamel(kebabString: string): string;
export declare function camelToKebab(camelCaseString: string): string;
export declare function camelToWords(camelCaseString: string): string;
export declare function pluralize(word: string): string;
export declare function singularize(word: string): string;
export declare function replaceAll(input: string, search: string, replace: string): string;
export declare function buildUserFullName(names: {
first_name?: string | null;
family_name?: string | null;
}): string;
/**
* @description Formats a number or an object containing amount, separator, decimals, and currency into a formatted string.
* @example usage:
* - formatAmount(1234567.89) // "1,234,567.89"
* - formatAmount({ amount: 1234567.89, separator: ".", decimals: 2, currency: "USD" }) // "1.234.567,89 USD"
* - formatAmount({ amount: 1234567.89, separator: ",", decimals: 2 }) // "1,234,567.89"
* - formatAmount(1234567.89, ".", 2, "USD") // "1.234.567,89 USD"
* - formatAmount(1234567.89, { separator: ".", decimals: 2, currency: "USD" }) // "1.234.567,89 USD"
* - formatAmount(1234567.89, { separator: ",", decimals: 2 }) // "1,234,567.89"
* - formatAmount(1234567.89, ",", 2, "USD") // "1,234,567.89 USD"
* @param x - The number or an object containing amount, separator, decimals, and currency.
* @param separator - The separator to use for thousands (default is ",").
* @param decimals - The number of decimal places to display (default is 2).
* @param currency - The currency symbol to append (optional).
* @returns A formatted string representing the amount.
*/
export declare const formatAmount: (x: number | {
amount: number;
separator?: string;
decimals?: number;
currency?: string;
}, separator?: string | {
separator?: string;
decimals?: number;
currency?: string;
}, decimals?: number, currency?: string) => string;
export declare const formatNotificationSpace: (space: string, infos: {
user?: string;
company?: string | null;
office?: string;
store?: string;
role?: string;
}) => string | null;
/**
* @description Generate a random 4-digit pin code between 1000 and 9999 (inclusive)
* @returns {string} a random 4-digit pin code
*/
export declare function generatePinCode(): string;
/**
* Function to get a substring from position 0 to the first whitespace after threshold characters
* @param str - The input string
* @param threshold - The threshold number of characters
* @returns - The extracted substring
*/
export declare function getSubstringUntilFirstWhitespaceAfterNChars(str: string, threshold?: number, dots?: string): string;
/**
* @generator Jsm
* @author dr. Salmi <reevosolutions@gmail.com>
* @since 23-07-2024 08:43:03
*/
export declare function generateItemAlphabetCode(usedCodes: string[]): string;
export declare function countCharacterOccurrenceInString(str: string, character: string): number;