UNPKG

react-native-web-mask

Version:

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

72 lines (71 loc) 2.53 kB
import { MaskFn, MaskType } from "./types"; /** * Format a value as a phone number in the format (###) ###-#### * @param {string} value the value to format * @returns {string} the formatted value * @example * maskPhone("1234567890") -> "(123) 456-7890" */ export declare const maskPhone: MaskFn; /** * Format a value as a decimal number in the format 0.00 * @param {string} value the value to format * @returns {string} the formatted value * @example * maskMoney("123456") -> "1,234.56" */ export declare const maskMoney: MaskFn; /** * Format a value as a credit card number in the format XXXX XXXX XXXX XXXX * @param {string} value the value to format * @returns {string} the formatted value * @example * maskCard("1234567890123456") -> "1234 5678 9012 3456" */ export declare const maskCard: MaskFn; /** * Format a value as a zip code in the format 12345-6789 * @param {string} value the value to format * @returns {string} the formatted value * @example * maskZip("123456789") -> "12345-6789" */ export declare const maskZip: MaskFn; /** * Format a value as a date in the format MM/DD/YYYY * @param {string} value the value to format * @returns {string} the formatted value * @example * maskDate("12345678") -> "01/23/4567" */ export declare const maskDate: MaskFn; /** * Format a value as a month/day in the format MM/DD * @param {string} value the value to format * @returns {string} the formatted value * @example * maskMonthDay("1231") -> "12/31" */ export declare const maskMonthDay: MaskFn; export declare const defaultMask: MaskFn; /** * Given a mask type and a raw value, clamps the raw value to a suitable * length for the given mask type. This is useful for limiting the length * of input values when the user is typing, so that the formatting doesn't * get out of hand. * * For example, for a phone number, the raw value will be clamped to 10 * digits. For a date, it will be clamped to 8 digits (MMDDYYYY). * * Note that this function does not remove any characters from the raw * value - it simply truncates it to the desired length. This means that * if the user enters a non-digit character, it will still be included * in the final output. * * @param {MaskType} type the mask type to use for clamping * @param {string} raw the raw value to clamp * @returns {string} the clamped raw value * @example * clampRawValueByMaskType("phone", "1234567890333") -> "1234567890" */ export declare function clampRawValueByMaskType(type: MaskType, raw: string): string;