Skip to content

Commit

Permalink
Changed regex to split
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus committed Oct 30, 2021
1 parent 61a3b48 commit a276b6b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/lib/contains.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ export default function contains(str, elem, options) {
assertString(str);
options = merge(options, defaulContainsOptions);

const regex = new RegExp(toString(elem), `g${options.ignoreCase ? 'i' : ''}`);
if (options.ignoreCase) {
return str.toLowerCase().split(toString(elem).toLowerCase()).length > options.minOccurrences;
}

return (str.match(regex) || []).length >= options.minOccurrences;
return str.split(toString(elem)).length > options.minOccurrences;
}
2 changes: 1 addition & 1 deletion test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -4245,7 +4245,7 @@ describe('Validators', () => {
args: ['foo', {
minOccurrences: 2,
}],
valid: ['foofoofoo', '12foo124foo', 'fofooofoooofoooo'],
valid: ['foofoofoo', '12foo124foo', 'fofooofoooofoooo', 'foo1foo'],
invalid: ['foo', 'foobar', 'Fooofoo', 'foofo'],
});
});
Expand Down

0 comments on commit a276b6b

Please sign in to comment.