(
regExp: globalThis.RegExp,
annotations?: Schema.Annotations.Filter
): Filter<string>Creates a Filter that validates strings by running RegExp.test.
When to use
Use when string validation should be represented as a schema Filter backed
by a regular expression.
Details
The filter can be used with Schema.filter or attached directly to a
String AST node through checks. The regular expression source is stored in
annotations for serialization and arbitrary generation.
Gotchas
Use a non-global, non-sticky regular expression, or reset lastIndex
yourself, because RegExp.test is stateful for expressions with the g or
y flag.
Example (Validating an email pattern)
import { SchemaAST } from "effect"
const emailFilter = SchemaAST.isPattern(/^[^@]+@[^@]+$/)export function function isPattern(
regExp: globalThis.RegExp,
annotations?: Schema.Annotations.Filter
): Filter<string>
Creates a
Filter
that validates strings by running RegExp.test.
When to use
Use when string validation should be represented as a schema Filter backed
by a regular expression.
Details
The filter can be used with Schema.filter or attached directly to a
String AST node through checks. The regular expression source is stored in
annotations for serialization and arbitrary generation.
Gotchas
Use a non-global, non-sticky regular expression, or reset lastIndex
yourself, because RegExp.test is stateful for expressions with the g or
y flag.
Example (Validating an email pattern)
import { SchemaAST } from "effect"
const emailFilter = SchemaAST.isPattern(/^[^@]+@[^@]+$/)
isPattern(regExp: RegExpregExp: module globalThisglobalThis.RegExp, annotations: anyannotations?: import SchemaSchema.declareAnnotations.type Schema.Annotations.Filter = /*unresolved*/ anyFilter) {
const const source: stringsource = regExp: RegExpregExp.RegExp.source: stringReturns a copy of the text of the regular expression pattern. Read-only. The regExp argument is a Regular expression object. It can be a variable name or a literal.
source
return function makeFilter<T>(
filter: (
input: T,
ast: AST,
options: ParseOptions
) => Schema.FilterOutput,
annotations?:
| Schema.Annotations.Filter
| undefined,
aborted?: boolean
): Filter<T>
makeFilter(
(s: strings: string) => regExp: RegExpregExp.RegExp.test(string: string): booleanReturns a Boolean value that indicates whether or not a pattern exists in a searched string.
test(s: strings),
{
expected: stringexpected: `a string matching the RegExp ${const source: stringsource}`,
meta: {
_tag: string
regExp: RegExp
}
meta: {
_tag: string_tag: "isPattern",
regExp: RegExpregExp
},
arbitrary: {
constraint: {
patterns: string[]
}
}
arbitrary: {
constraint: {
patterns: string[]
}
constraint: {
patterns: string[](property) patterns: {
0: string;
length: 1;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
pop: () => string | undefined;
push: (...items: Array<string>) => number;
concat: { (...items: Array<ConcatArray<string>>): Array<string>; (...items: Array<string | ConcatArray<string>>): Array<string> };
join: (separator?: string) => string;
reverse: () => Array<string>;
shift: () => string | undefined;
slice: (start?: number, end?: number) => Array<string>;
sort: (compareFn?: ((a: string, b: string) => number) | undefined) => [string];
splice: { (start: number, deleteCount?: number): Array<string>; (start: number, deleteCount: number, ...items: Array<string>): Array<string> };
unshift: (...items: Array<string>) => number;
indexOf: (searchElement: string, fromIndex?: number) => number;
lastIndexOf: (searchElement: string, fromIndex?: number) => number;
every: { (predicate: (value: string, index: number, array: Array<string>) => value is S, thisArg?: any): this is S[]; (predicate: (value: string, index: number, array: Array<string>) => unknown, thisArg?: any): boolean };
some: (predicate: (value: string, index: number, array: Array<string>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: string, index: number, array: Array<string>) => void, thisArg?: any) => void;
map: (callbackfn: (value: string, index: number, array: Array<string>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: string, index: number, array: Array<string>) => value is S, thisArg?: any): Array<S>; (predicate: (value: string, index: number, array: Array<string>) => unknown, thisArg?: any): Array<string> };
reduce: { (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: Array<string>) => string): string; (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: Array<string>) => string, …;
reduceRight: { (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: Array<string>) => string): string; (callbackfn: (previousValue: string, currentValue: string, currentIndex: number, array: Array<string>) => string, …;
find: { (predicate: (value: string, index: number, obj: Array<string>) => value is S, thisArg?: any): S | undefined; (predicate: (value: string, index: number, obj: Array<string>) => unknown, thisArg?: any): string | undefined };
findIndex: (predicate: (value: string, index: number, obj: Array<string>) => unknown, thisArg?: any) => number;
fill: (value: string, start?: number, end?: number) => [string];
copyWithin: (target: number, start: number, end?: number) => [string];
entries: () => ArrayIterator<[number, string]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<string>;
includes: (searchElement: string, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: string, index: number, array: Array<string>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => string | undefined;
findLast: { (predicate: (value: string, index: number, array: Array<string>) => value is S, thisArg?: any): S | undefined; (predicate: (value: string, index: number, array: Array<string>) => unknown, thisArg?: any): string | undefined };
findLastIndex: (predicate: (value: string, index: number, array: Array<string>) => unknown, thisArg?: any) => number;
toReversed: () => Array<string>;
toSorted: (compareFn?: ((a: string, b: string) => number) | undefined) => Array<string>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<string>): Array<string>; (start: number, deleteCount?: number): Array<string> };
with: (index: number, value: string) => Array<string>;
}
patterns: [regExp: RegExpregExp.RegExp.source: stringReturns a copy of the text of the regular expression pattern. Read-only. The regExp argument is a Regular expression object. It can be a variable name or a literal.
source]
}
},
...annotations: anyannotations
}
)
}