@rnw-community/react-native-payments
Version:
Accept Payments with Apple Pay and Android Pay using the Payment Request API.
22 lines (15 loc) • 588 B
text/typescript
import validator from 'validator';
import { isNumber, isString } from '@rnw-community/shared';
import type { AmountValue } from '../type/amount-value.type';
const isValidStringAmount = (stringAmount: string): boolean => {
if (stringAmount.endsWith('.')) {
return false;
}
return validator.isDecimal(stringAmount);
};
export const isValidDecimalMonetaryValue = (amountValue: AmountValue): boolean => {
if (!isNumber(amountValue) && !isString(amountValue)) {
return false;
}
return isNumber(amountValue) || isValidStringAmount(amountValue);
};