UNPKG

react-native-web-mask

Version:

A cross-platform input mask hook for React and React Native, with TypeScript and helper utilities

43 lines (42 loc) 1.54 kB
/** * Strips all non-digit characters from a string. */ export declare function stripNonDigits(value: string): string; /** * Ensures the string doesn't exceed a certain length. */ export declare function limitLength(value: string, maxLength: number): string; /** * Inserts a separator (e.g. '/') between chunks of specified sizes. * * Example: * insertChunks("12345", [2, 2, 1], "/") * -> "12/34/5" */ export declare function insertChunks(value: string, chunkSizes: number[], separator: string): string; /** * A flexible RegExp replace helper. * Pass in a pattern (RegExp) and a replacer string or function. * * Example: * applyRegexReplace("12345", /\d/g, "*") * -> "*****" */ export declare function applyRegexReplace(value: string, pattern: RegExp, replaceWith: string): string; /** * Clamps a numeric string (after parsing to a number) within min and max range. * Useful if you want to ensure months/days remain in valid ranges, etc. * * Example: * clampDigits("13", 1, 12) -> "12" */ export declare function clampDigits(numericString: string, min: number, max: number): string; /** * Takes a string that is expected to contain a currency value and extracts * the decimal equivalent from it. Any non-numeric characters are removed and the * result is parsed as a float. If the result is NaN, returns 0. * * @param {string} currency - The currency string to parse * @returns {number} The parsed number, or 0 if parsing fails */ export declare function parseCurrencyToNumber(currency: string): number;