mirror of
https://github.com/swc-project/swc.git
synced 2024-12-19 19:52:21 +03:00
32 lines
856 B
JavaScript
32 lines
856 B
JavaScript
export function string_create() {
|
|
return new StringSchema();
|
|
}
|
|
export class StringSchema extends BaseSchema {
|
|
matches(regex, options) {
|
|
let excludeEmptyString = false;
|
|
let message;
|
|
let name;
|
|
|
|
if (options) {
|
|
if (typeof options === "object") {
|
|
({ excludeEmptyString = false, message, name } = options);
|
|
} else {
|
|
message = options;
|
|
}
|
|
}
|
|
|
|
return this.test({
|
|
name: name || "matches",
|
|
message: message || string.matches,
|
|
params: {
|
|
regex,
|
|
},
|
|
test: (value) =>
|
|
isAbsent(value) ||
|
|
(value === "" && excludeEmptyString) ||
|
|
value.search(regex) !== -1,
|
|
});
|
|
}
|
|
}
|
|
string_create.prototype = StringSchema.prototype;
|