1 | import { buildMessage, ValidateBy } from '../common/ValidateBy';
|
2 | import isCurrencyValidator from 'validator/lib/isCurrency';
|
3 | export const IS_CURRENCY = 'isCurrency';
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | export function isCurrency(value, options) {
|
9 | return typeof value === 'string' && isCurrencyValidator(value, options);
|
10 | }
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | export 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 |
|
\ | No newline at end of file |