UNPKG

928 BJavaScriptView Raw
1import { buildMessage, ValidateBy } from '../common/ValidateBy';
2import containsValidator from 'validator/lib/contains';
3export const CONTAINS = 'contains';
4/**
5 * Checks if the string contains the seed.
6 * If given value is not a string, then it returns false.
7 */
8export function contains(value, seed) {
9 return typeof value === 'string' && containsValidator(value, seed);
10}
11/**
12 * Checks if the string contains the seed.
13 * If given value is not a string, then it returns false.
14 */
15export 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//# sourceMappingURL=Contains.js.map
\No newline at end of file