Skip to Content

Utilities

Helper functions and constants exported by the package.

PRESETS

A record of built-in mask configurations.

import { PRESETS } from '@virastack/input-mask'; // Access PRESETS.card, PRESETS.phone, etc.

VALIDATORS

A record of built-in validator functions.

import { VALIDATORS } from '@virastack/input-mask'; // VALIDATORS.luhn(value) // VALIDATORS.tckn(value)

Validation Helpers

validateTCKN

Standalone TCKN validation function.

function validateTCKN(value: string): boolean

validateLuhn

Standalone Luhn algorithm validation function.

function validateLuhn(value: string): boolean

Formatting Helpers

These functions allow you to use ViraStack Mask’s masking and formatting logic outside of the useViraMask hook (e.g., for displaying formatted data in a table).

applyMask

Applies a mask pattern to a raw value.

import { applyMask } from '@virastack/input-mask'; const formatted = applyMask('5551234567', '(999) 999 99 99'); // Output: "(555) 123 45 67"

unmask

Removes mask characters from a value, returning only the raw characters defined by the mask type.

import { unmask } from '@virastack/input-mask'; const raw = unmask('(555) 123 45 67', '(999) 999 99 99'); // Output: "5551234567"

cleanValue

Removes all non-numeric characters from a string. Useful for cleaning inputs before processing.

import { cleanValue } from '@virastack/input-mask'; const clean = cleanValue('(555) 123-4567'); // Output: "5551234567"

formatCurrency

Formats a number string as currency.

import { formatCurrency } from '@virastack/input-mask'; const price = formatCurrency('1234.50', { symbol: '$', precision: 2, thousandSeparator: ',', decimalSeparator: '.' }); // Output: "$ 1,234.50"

unformatCurrency

Parses a formatted currency string back to a raw number string.

import { unformatCurrency } from '@virastack/input-mask'; const raw = unformatCurrency('$ 1,234.50', { decimalSeparator: '.' }); // Output: "1234.50"

getCardType

Detects the credit card type from a number.

import { getCardType } from '@virastack/input-mask'; const type = getCardType('4111'); // Output: "visa"

React Helpers

mergeRefs

Utility to merge multiple React refs into one.

function mergeRefs<T>(...refs: Ref<T>[]): RefCallback<T>

© 2026 ViraStack. MIT License.