(annotations?: Annotations.Filter): SchemaAST.Filter<string>Validates that the first character of a string is unchanged by
toUpperCase().
Details
Empty strings pass. Strings whose first character has no lowercase form, such as a digit, punctuation mark, or whitespace, also pass.
export function function isCapitalized(
annotations?: Annotations.Filter
): SchemaAST.Filter<string>
Validates that the first character of a string is unchanged by
toUpperCase().
Details
Empty strings pass. Strings whose first character has no lowercase form, such
as a digit, punctuation mark, or whitespace, also pass.
isCapitalized(annotations: Annotations.Filter | undefinedannotations?: Annotations.interface Annotations.FilterAnnotations for filter schema nodes (created via Schema.filter). Extends
Augment
with an optional error message, identifier, and metadata.
Filters are intentionally non-parametric to keep them covariant.
Filter) {
return const makeFilter: <T>(
filter: (
input: T,
ast: SchemaAST.AST,
options: SchemaAST.ParseOptions
) => FilterOutput,
annotations?: Annotations.Filter | undefined,
abort?: boolean
) => SchemaAST.Filter<T>
Creates a custom validation filter from a predicate function.
Details
The predicate receives the decoded input value, the schema AST, and parse
options, and returns a FilterOutput. Non-success outputs are normalized into
schema issues. The annotations parameter annotates the filter itself; with
the default formatter, failures use message first, expected second, and
<filter> when neither is provided.
When abort is true, parsing stops after this filter fails instead of
collecting later check failures.
Example (Reporting failure at a nested path)
import { Schema } from "effect"
const schema = Schema.Struct({ password: Schema.String, confirmPassword: Schema.String }).check(
Schema.makeFilter((o) =>
o.password === o.confirmPassword
? undefined
: { path: ["password"], issue: "password and confirmPassword must match" }
)
)
console.log(String(Schema.decodeUnknownExit(schema)({ password: "123456", confirmPassword: "1234567" })))
// Failure(Cause([Fail(SchemaError: password and confirmPassword must match
// at ["password"])]))
Example (Reporting multiple failures at once)
import { Schema } from "effect"
const schema = Schema.Struct({ a: Schema.Finite, b: Schema.Finite, c: Schema.Finite }).check(
Schema.makeFilter((o) => {
const issues: Array<Schema.FilterIssue> = []
if (o.a > 0) {
if (o.b <= 0) issues.push({ path: ["b"], issue: "b must be greater than 0" })
if (o.c <= 0) issues.push({ path: ["c"], issue: "c must be greater than 0" })
}
return issues
})
)
console.log(String(Schema.decodeUnknownExit(schema)({ a: 1, b: 0, c: 0 })))
// Failure(Cause([Fail(SchemaError: b must be greater than 0
// at ["b"]
// c must be greater than 0
// at ["c"])]))
makeFilter(
(s: strings: string) => s: strings.String.charAt(pos: number): stringReturns the character at the specified index.
charAt(0).String.toUpperCase(): stringConverts all the alphabetic characters in a string to uppercase.
toUpperCase() === s: strings.String.charAt(pos: number): stringReturns the character at the specified index.
charAt(0),
{
Annotations.Augment.expected?: string | undefinedHuman-readable description of what a value is expected to satisfy.
Details
For filter and refinement failures, the default formatter uses
message first, then expected, and finally falls back to <filter>.
Use this to name a failed filter in the default message:
Expected <expected>, got <actual>.
expected: "a string with the first character in uppercase",
Annotations.Filter.meta?: Annotations.Meta | undefined(property) Annotations.Filter.meta?: {
_tag: 'isCapitalized';
regExp: globalThis.RegExp;
}
Optional metadata used to identify or extend the filter with custom data.
meta: {
_tag: "isCapitalized"_tag: "isCapitalized",
regExp: globalThis.RegExpregExp: new module globalThisglobalThis.var RegExp: RegExpConstructor
new (pattern: globalThis.RegExp | string, flags?: string) => globalThis.RegExp (+2 overloads)
RegExp(const CAPITALIZED_PATTERN: "^[^a-z]?.*$"CAPITALIZED_PATTERN)
},
Annotations.Filter.arbitrary?: Annotations.ToArbitrary.Filter | undefined(property) Annotations.Filter.arbitrary?: {
constraint: { patterns: [string] };
}
Optional hints used by arbitrary derivation for this filter.
Details
The same annotation can be attached to a single filter or a
FilterGroup. Group hints apply to the same schema node while child
filters are still collected and checked normally.
arbitrary: {
Annotations.ToArbitrary.Filter.constraint?: Annotations.ToArbitrary.GenerationConstraint | undefined(property) Annotations.ToArbitrary.Filter.constraint?: {
patterns: [string];
}
constraint: {
Annotations.ToArbitrary.GenerationConstraint.patterns?: readonly [string, ...string[]] | undefined(property) Annotations.ToArbitrary.GenerationConstraint.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: [const CAPITALIZED_PATTERN: "^[^a-z]?.*$"CAPITALIZED_PATTERN]
}
},
...annotations: Annotations.Filter | undefinedannotations
}
)
}