1 | import { buildMessage, ValidateBy } from '../common/ValidateBy';
|
2 | import containsValidator from 'validator/lib/contains';
|
3 | export const CONTAINS = 'contains';
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | export function contains(value, seed) {
|
9 | return typeof value === 'string' && containsValidator(value, seed);
|
10 | }
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | export function Contains(seed, validationOptions) {
|
16 | return ValidateBy({
|
17 | name: CONTAINS,
|
18 | constraints: [seed],
|
19 | validator: {
|
20 | validate: (value, args) => contains(value, args.constraints[0]),
|
21 | defaultMessage: buildMessage(eachPrefix => eachPrefix + '$property must contain a $constraint1 string', validationOptions),
|
22 | },
|
23 | }, validationOptions);
|
24 | }
|
25 |
|
\ | No newline at end of file |