UNPKG

nhb-toolbox

Version:

A versatile collection of smart, efficient, and reusable utility functions, classes and types for everyday development needs.

63 lines (62 loc) 2.65 kB
import type { MaskOptions } from './types'; /** * * Replaces all occurrences of a string or pattern in the given input string. * * - If `find` is a string, it is converted into a global regular expression (`/find/g`). * - If `find` is a `RegExp`, the global (`g`) flag is ensured. * - Trims the input before performing replacements. * * @param input - The string in which replacements should be performed. * @param find - The substring or regex pattern to search for. * @param replace - The string to replace matches with. * @returns The modified/refined string with replacements applied. */ export declare const replaceAllInString: (input: string, find: string | RegExp, replace: string) => string; /** * * Converts a string into a URL-friendly slug. * @param input - The string to be converted. * @returns The slugified string. */ export declare const slugifyString: (input: string) => string; /** * * Masks part of a string for privacy. * @param input - The string to mask. * @param options - Options for masking a string. * @returns The masked string. */ export declare const maskString: (input: string, options?: MaskOptions) => string; /** * * Reverses a given string. * @param input - The string to reverse. * @returns The reversed string. */ export declare const reverseString: (input: string) => string; /** * * Normalizes a string by removing diacritics (accents). * @param str The input string. * @returns The normalized string. */ export declare function normalizeString(str: string): string; /** * * Extracts all email addresses from a string. * @param str The input string. * @returns An array of extracted email addresses. */ export declare function extractEmails(str: string): string[]; /** * * Extracts all URLs from a string. * @param str The input string. * @returns An array of extracted URLs. */ export declare function extractURLs(str: string): string[]; /** * * Returns a grammatically correct unit string, optionally prefixed with the number. * * @remarks For complex and versatile pluralization, please refer to {@link https://toolbox.nazmul-nhb.dev/docs/utilities/string/pluralizer pluralizer} or {@link https://toolbox.nazmul-nhb.dev/docs/classes/Pluralizer Pluralizer Class} instead. * * @param count The numeric value to determine singular or plural. * @param unit The unit name (e.g., "day", "hour"). * @param withNumber Whether to prefix the count before the unit. Defaults to `true`. * @returns Formatted unit string like `"1 day"`, `"2 months"`, or `"hour"`. */ export declare function formatUnitWithPlural(count: number, unit: string, withNumber?: boolean): string;