Skip to content

Commit

Permalink
Make StringSchema.matches options optional
Browse files Browse the repository at this point in the history
The second parameter to matches() should be optional. Giving it a default value, like the other methods, generates the appropriate optional types in the build.
  • Loading branch information
bespokebob committed Dec 10, 2020
1 parent 3ca0ebf commit 6ff9f2d
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,26 +105,24 @@ export default class StringSchema<
});
}

matches(regex: RegExp, options: MatchOptions | MatchOptions['message']) {
matches(regex: RegExp, options: MatchOptions | MatchOptions['message'] = locale.matches) {
let excludeEmptyString = false;
let message;
let name;

if (options) {
if (typeof options === 'object') {
({
excludeEmptyString = false,
message,
name,
} = options as MatchOptions);
} else {
message = options;
}
if (typeof options === 'object') {
({
excludeEmptyString = false,
message,
name,
} = options as MatchOptions);
} else {
message = options;
}

return this.test({
name: name || 'matches',
message: message || locale.matches,
message,
params: { regex },
test: (value: Maybe<string>) =>
isAbsent(value) ||
Expand Down

0 comments on commit 6ff9f2d

Please sign in to comment.