UNPKG

964 BJavaScriptView Raw
1import { buildMessage, ValidateBy } from '../common/ValidateBy';
2import isCurrencyValidator from 'validator/lib/isCurrency';
3export const IS_CURRENCY = 'isCurrency';
4/**
5 * Checks if the string is a valid currency amount.
6 * If given value is not a string, then it returns false.
7 */
8export function isCurrency(value, options) {
9 return typeof value === 'string' && isCurrencyValidator(value, options);
10}
11/**
12 * Checks if the string is a valid currency amount.
13 * If given value is not a string, then it returns false.
14 */
15export function IsCurrency(options, validationOptions) {
16 return ValidateBy({
17 name: IS_CURRENCY,
18 constraints: [options],
19 validator: {
20 validate: (value, args) => isCurrency(value, args.constraints[0]),
21 defaultMessage: buildMessage(eachPrefix => eachPrefix + '$property must be a currency', validationOptions),
22 },
23 }, validationOptions);
24}
25//# sourceMappingURL=IsCurrency.js.map
\No newline at end of file