UNPKG

react-currency-input-field

Version:

React <input/> component for formatting currency and numbers.

17 lines (15 loc) 475 B
import { escapeRegExp } from './escapeRegExp'; type Options = { decimalSeparator?: string; groupSeparator?: string; }; export const getSuffix = ( value: string, { groupSeparator = ',', decimalSeparator = '.' }: Options ): string | undefined => { const suffixReg = new RegExp( `\\d([^${escapeRegExp(groupSeparator)}${escapeRegExp(decimalSeparator)}0-9]+)` ); const suffixMatch = value.match(suffixReg); return suffixMatch ? suffixMatch[1] : undefined; };