Filters
Developers can define custom validation logic beyond basic type checks, giving more control over how data is validated.
Filters are declared using the Schema.filter
function. This function requires two arguments: the schema to be validated and a predicate function. The predicate function is user-defined and determines whether the data satisfies the condition. If the data fails the validation, an error message can be provided.
Example (Defining a Minimum String Length Filter)
Note that the filter does not alter the schema’s Type
:
// ┌─── string// ▼type Type = typeof LongString.Type
Filters add additional validation constraints without modifying the schema’s underlying type.
The predicate function in a filter follows this structure:
type Predicate = ( a: A, options: ParseOptions, self: AST.Refinement) => FilterReturnType
where
interface FilterIssue { readonly path: ReadonlyArray<PropertyKey> readonly issue: string | ParseResult.ParseIssue}
type FilterOutput = | undefined | boolean | string | ParseResult.ParseIssue | FilterIssue
type FilterReturnType = FilterOutput | ReadonlyArray<FilterOutput>
The filter’s predicate can return several types of values, each affecting validation in a different way:
Return Type | Behavior |
---|---|
true | The data satisfies the filter’s condition and passes validation. |
false or undefined | The data does not meet the condition, and no specific error message is provided. |
string | The validation fails, and the provided string is used as the error message. |
ParseResult.ParseIssue | The validation fails with a detailed error structure, specifying where and why it failed. |
FilterIssue | Allows for more detailed error messages with specific paths, providing enhanced error reporting. |
ReadonlyArray<FilterOutput> | An array of issues can be returned if multiple validation errors need to be reported. |
Embedding metadata within the schema, such as identifiers, JSON schema specifications, and descriptions, enhances understanding and analysis of the schema’s constraints and purpose.
Example (Adding Metadata with Annotations)
import { import Schema
Schema, import JSONSchema
JSONSchema } from "effect"
const const LongString: Schema.filter<typeof Schema.String>
LongString = import Schema
Schema.class Stringexport String
String.Pipeable.pipe<typeof Schema.String, Schema.filter<typeof Schema.String>>(this: typeof Schema.String, ab: (_: typeof Schema.String) => Schema.filter<typeof Schema.String>): Schema.filter<...> (+21 overloads)
pipe( import Schema
Schema.function filter<typeof Schema.String>(predicate: (a: string, options: ParseOptions, self: Refinement) => FilterReturnType, annotations?: Schema.Annotations.Filter<...> | undefined): (self: typeof Schema.String) => Schema.filter<...> (+2 overloads)
filter( (s: string
s) => s: string
s.String.length: number
Returns the length of a String object.
length >= 10 ? var undefined
undefined : "a string at least 10 characters long", { Annotations.Schema<A, TypeParameters extends ReadonlyArray<any> = readonly []>.identifier?: string
identifier: "LongString", Annotations.Schema<A, TypeParameters extends ReadonlyArray<any> = readonly []>.jsonSchema?: object
jsonSchema: { minLength: number
minLength: 10 }, Annotations.Doc<A>.description?: string
description: "Lorem ipsum dolor sit amet, ..." } ))
var console: Console
The console
module provides a simple debugging console that is similar to the
JavaScript console mechanism provided by web browsers.
The module exports two specific components:
- A
Console
class with methods such as console.log()
, console.error()
and console.warn()
that can be used to write to any Node.js stream.
- A global
console
instance configured to write to process.stdout
and
process.stderr
. The global console
can be used without importing the node:console
module.
Warning: The global console object's methods are neither consistently
synchronous like the browser APIs they resemble, nor are they consistently
asynchronous like all other Node.js streams. See the note on process I/O
for
more information.
Example using the global console
:
console.log('hello world');// Prints: hello world, to stdoutconsole.log('hello %s', 'world');// Prints: hello world, to stdoutconsole.error(new Error('Whoops, something bad happened'));// Prints error message and stack trace to stderr:// Error: Whoops, something bad happened// at [eval]:5:15// at Script.runInThisContext (node:vm:132:18)// at Object.runInThisContext (node:vm:309:38)// at node:internal/process/execution:77:19// at [eval]-wrapper:6:22// at evalScript (node:internal/process/execution:76:60)// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';console.warn(`Danger ${name}! Danger!`);// Prints: Danger Will Robinson! Danger!, to stderr
Example using the Console
class:
const out = getStreamSomehow();const err = getStreamSomehow();const myConsole = new console.Console(out, err);
myConsole.log('hello world');// Prints: hello world, to outmyConsole.log('hello %s', 'world');// Prints: hello world, to outmyConsole.error(new Error('Whoops, something bad happened'));// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';myConsole.warn(`Danger ${name}! Danger!`);// Prints: Danger Will Robinson! Danger!, to err
console.Console.log(message?: any, ...optionalParams: any[]): void
Prints to stdout
with newline. Multiple arguments can be passed, with the
first used as the primary message and all additional used as substitution
values similar to printf(3)
(the arguments are all passed to util.format()
).
const count = 5;console.log('count: %d', count);// Prints: count: 5, to stdoutconsole.log('count:', count);// Prints: count: 5, to stdout
See util.format()
for more information.
log(import Schema
Schema.decodeUnknownSync<string, string>(schema: Schema.Schema<string, string, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => stringexport decodeUnknownSync
decodeUnknownSync(const LongString: Schema.filter<typeof Schema.String>
LongString)("a"))/*throws:ParseError: LongString└─ Predicate refinement failure └─ a string at least 10 characters long*/
var console: Console
The console
module provides a simple debugging console that is similar to the
JavaScript console mechanism provided by web browsers.
The module exports two specific components:
- A
Console
class with methods such as console.log()
, console.error()
and console.warn()
that can be used to write to any Node.js stream.
- A global
console
instance configured to write to process.stdout
and
process.stderr
. The global console
can be used without importing the node:console
module.
Warning: The global console object's methods are neither consistently
synchronous like the browser APIs they resemble, nor are they consistently
asynchronous like all other Node.js streams. See the note on process I/O
for
more information.
Example using the global console
:
console.log('hello world');// Prints: hello world, to stdoutconsole.log('hello %s', 'world');// Prints: hello world, to stdoutconsole.error(new Error('Whoops, something bad happened'));// Prints error message and stack trace to stderr:// Error: Whoops, something bad happened// at [eval]:5:15// at Script.runInThisContext (node:vm:132:18)// at Object.runInThisContext (node:vm:309:38)// at node:internal/process/execution:77:19// at [eval]-wrapper:6:22// at evalScript (node:internal/process/execution:76:60)// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';console.warn(`Danger ${name}! Danger!`);// Prints: Danger Will Robinson! Danger!, to stderr
Example using the Console
class:
const out = getStreamSomehow();const err = getStreamSomehow();const myConsole = new console.Console(out, err);
myConsole.log('hello world');// Prints: hello world, to outmyConsole.log('hello %s', 'world');// Prints: hello world, to outmyConsole.error(new Error('Whoops, something bad happened'));// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';myConsole.warn(`Danger ${name}! Danger!`);// Prints: Danger Will Robinson! Danger!, to err
console.Console.log(message?: any, ...optionalParams: any[]): void
Prints to stdout
with newline. Multiple arguments can be passed, with the
first used as the primary message and all additional used as substitution
values similar to printf(3)
(the arguments are all passed to util.format()
).
const count = 5;console.log('count: %d', count);// Prints: count: 5, to stdoutconsole.log('count:', count);// Prints: count: 5, to stdout
See util.format()
for more information.
log(import JSONSchema
JSONSchema.const make: <string, string, never>(schema: Schema.Schema<string, string, never>) => JSONSchema.JsonSchema7Root
make(const LongString: Schema.filter<typeof Schema.String>
LongString))/*Output:{ '$schema': 'http://json-schema.org/draft-07/schema#', type: 'string', description: 'Lorem ipsum dolor sit amet, ...', minLength: 10}*/
When validating forms or structured data, it’s possible to associate specific error messages with particular fields or paths. This enhances error reporting and is especially useful when integrating with libraries like react-hook-form.
Example (Matching Passwords)
import { import Either
Either, import Schema
Schema, import ParseResult
ParseResult } from "effect"
const const Password: Schema.filter<Schema.Schema<string, string, never>>
Password = import Schema
Schema.class Trim
This schema allows removing whitespaces from the beginning and end of a string.
Trim.Pipeable.pipe<typeof Schema.Trim, Schema.filter<Schema.Schema<string, string, never>>>(this: typeof Schema.Trim, ab: (_: typeof Schema.Trim) => Schema.filter<Schema.Schema<string, string, never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const minLength: <string>(minLength: number, annotations?: Schema.Annotations.Filter<string, string> | undefined) => <I, R>(self: Schema.Schema<string, I, R>) => Schema.filter<...>
minLength(2))
const const MyForm: Schema.filter<Schema.Struct<{ password: Schema.filter<Schema.Schema<string, string, never>>; confirm_password: Schema.filter<Schema.Schema<string, string, never>>;}>>
MyForm = import Schema
Schema.function Struct<{ password: Schema.filter<Schema.Schema<string, string, never>>; confirm_password: Schema.filter<Schema.Schema<string, string, never>>;}>(fields: { password: Schema.filter<Schema.Schema<string, string, never>>; confirm_password: Schema.filter<Schema.Schema<string, string, never>>;}): Schema.Struct<...> (+1 overload)
Struct({ password: Schema.filter<Schema.Schema<string, string, never>>
password: const Password: Schema.filter<Schema.Schema<string, string, never>>
Password, confirm_password: Schema.filter<Schema.Schema<string, string, never>>
confirm_password: const Password: Schema.filter<Schema.Schema<string, string, never>>
Password}).Pipeable.pipe<Schema.Struct<{ password: Schema.filter<Schema.Schema<string, string, never>>; confirm_password: Schema.filter<Schema.Schema<string, string, never>>;}>, Schema.filter<...>>(this: Schema.Struct<...>, ab: (_: Schema.Struct<...>) => Schema.filter<...>): Schema.filter<...> (+21 overloads)
pipe( // Add a filter to ensure that passwords match import Schema
Schema.function filter<Schema.Struct<{ password: Schema.filter<Schema.Schema<string, string, never>>; confirm_password: Schema.filter<Schema.Schema<string, string, never>>;}>>(predicate: (a: { ...;}, options: ParseOptions, self: Refinement) => FilterReturnType, annotations?: Schema.Annotations.Filter<...> | undefined): (self: Schema.Struct<...>) => Schema.filter<...> (+2 overloads)
filter((input: { readonly password: string; readonly confirm_password: string;}
input) => { if (input: { readonly password: string; readonly confirm_password: string;}
input.password: string
password !== input: { readonly password: string; readonly confirm_password: string;}
input.confirm_password: string
confirm_password) { // Return an error message associated // with the "confirm_password" field return { path: [string]
path: ["confirm_password"], message: string
message: "Passwords do not match" } } }))
var console: Console
The console
module provides a simple debugging console that is similar to the
JavaScript console mechanism provided by web browsers.
The module exports two specific components:
- A
Console
class with methods such as console.log()
, console.error()
and console.warn()
that can be used to write to any Node.js stream.
- A global
console
instance configured to write to process.stdout
and
process.stderr
. The global console
can be used without importing the node:console
module.
Warning: The global console object's methods are neither consistently
synchronous like the browser APIs they resemble, nor are they consistently
asynchronous like all other Node.js streams. See the note on process I/O
for
more information.
Example using the global console
:
console.log('hello world');// Prints: hello world, to stdoutconsole.log('hello %s', 'world');// Prints: hello world, to stdoutconsole.error(new Error('Whoops, something bad happened'));// Prints error message and stack trace to stderr:// Error: Whoops, something bad happened// at [eval]:5:15// at Script.runInThisContext (node:vm:132:18)// at Object.runInThisContext (node:vm:309:38)// at node:internal/process/execution:77:19// at [eval]-wrapper:6:22// at evalScript (node:internal/process/execution:76:60)// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';console.warn(`Danger ${name}! Danger!`);// Prints: Danger Will Robinson! Danger!, to stderr
Example using the Console
class:
const out = getStreamSomehow();const err = getStreamSomehow();const myConsole = new console.Console(out, err);
myConsole.log('hello world');// Prints: hello world, to outmyConsole.log('hello %s', 'world');// Prints: hello world, to outmyConsole.error(new Error('Whoops, something bad happened'));// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';myConsole.warn(`Danger ${name}! Danger!`);// Prints: Danger Will Robinson! Danger!, to err
console.Console.log(message?: any, ...optionalParams: any[]): void
Prints to stdout
with newline. Multiple arguments can be passed, with the
first used as the primary message and all additional used as substitution
values similar to printf(3)
(the arguments are all passed to util.format()
).
const count = 5;console.log('count: %d', count);// Prints: count: 5, to stdoutconsole.log('count:', count);// Prints: count: 5, to stdout
See util.format()
for more information.
log( var JSON: JSON
An intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format.
JSON.JSON.stringify(value: any, replacer?: (number | string)[] | null, space?: string | number): string (+1 overload)
Converts a JavaScript value to a JavaScript Object Notation (JSON) string.
stringify( import Schema
Schema.const decodeUnknownEither: <{ readonly password: string; readonly confirm_password: string;}, { readonly password: string; readonly confirm_password: string;}>(schema: Schema.Schema<{ readonly password: string; readonly confirm_password: string;}, { readonly password: string; readonly confirm_password: string;}, never>, options?: ParseOptions) => (u: unknown, overrideOptions?: ParseOptions) => Either.Either<...>
decodeUnknownEither(const MyForm: Schema.filter<Schema.Struct<{ password: Schema.filter<Schema.Schema<string, string, never>>; confirm_password: Schema.filter<Schema.Schema<string, string, never>>;}>>
MyForm)({ password: string
password: "abc", confirm_password: string
confirm_password: "d" // Confirm password does not match }).Pipeable.pipe<Either.Either<{ readonly password: string; readonly confirm_password: string;}, ParseResult.ParseError>, Either.Either<{ readonly password: string; readonly confirm_password: string;}, ParseResult.ArrayFormatterIssue[]>>(this: Either.Either<...>, ab: (_: Either.Either<...>) => Either.Either<...>): Either.Either<...> (+21 overloads)
pipe( import Either
Either.const mapLeft: <ParseResult.ParseError, ParseResult.ArrayFormatterIssue[]>(f: (left: ParseResult.ParseError) => ParseResult.ArrayFormatterIssue[]) => <R>(self: Either.Either<...>) => Either.Either<...> (+1 overload)
Maps the Left
side of an Either
value to a new Either
value.
mapLeft((error: ParseResult.ParseError
error) => import ParseResult
ParseResult.const ArrayFormatter: ParseResult.ParseResultFormatter<ParseResult.ArrayFormatterIssue[]>
ArrayFormatter.ParseResultFormatter<ArrayFormatterIssue[]>.formatErrorSync: (error: ParseResult.ParseError) => ParseResult.ArrayFormatterIssue[]
formatErrorSync(error: ParseResult.ParseError
error) ) ), null, 2 ))/* "_id": "Either", "_tag": "Left", "left": [ { "_tag": "Type", "path": [ "confirm_password" ], "message": "Passwords do not match" } ]}*/
In this example, we define a MyForm
schema with two password fields (password
and confirm_password
). We use Schema.filter
to check that both passwords match. If they don’t, an error message is returned, specifically associated with the confirm_password
field. This makes it easier to pinpoint the exact location of the validation failure.
The error is formatted in a structured way using ArrayFormatter
, allowing for easier post-processing and integration with form libraries.
The Schema.filter
API supports reporting multiple validation issues at once, which is especially useful in scenarios like form validation where several checks might fail simultaneously.
Example (Reporting Multiple Validation Errors)
import { import Either
Either, import Schema
Schema, import ParseResult
ParseResult } from "effect"
const const Password: Schema.filter<Schema.Schema<string, string, never>>
Password = import Schema
Schema.class Trim
This schema allows removing whitespaces from the beginning and end of a string.
Trim.Pipeable.pipe<typeof Schema.Trim, Schema.filter<Schema.Schema<string, string, never>>>(this: typeof Schema.Trim, ab: (_: typeof Schema.Trim) => Schema.filter<Schema.Schema<string, string, never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const minLength: <string>(minLength: number, annotations?: Schema.Annotations.Filter<string, string> | undefined) => <I, R>(self: Schema.Schema<string, I, R>) => Schema.filter<...>
minLength(2))const const OptionalString: Schema.optional<typeof Schema.String>
OptionalString = import Schema
Schema.const optional: <typeof Schema.String>(self: typeof Schema.String) => Schema.optional<typeof Schema.String>
optional(import Schema
Schema.class Stringexport String
String)
const const MyForm: Schema.filter<Schema.Struct<{ password: Schema.filter<Schema.Schema<string, string, never>>; confirm_password: Schema.filter<Schema.Schema<string, string, never>>; name: Schema.optional<...>; surname: Schema.optional<...>;}>>
MyForm = import Schema
Schema.function Struct<{ password: Schema.filter<Schema.Schema<string, string, never>>; confirm_password: Schema.filter<Schema.Schema<string, string, never>>; name: Schema.optional<...>; surname: Schema.optional<...>;}>(fields: { password: Schema.filter<Schema.Schema<string, string, never>>; confirm_password: Schema.filter<Schema.Schema<string, string, never>>; name: Schema.optional<...>; surname: Schema.optional<...>;}): Schema.Struct<...> (+1 overload)
Struct({ password: Schema.filter<Schema.Schema<string, string, never>>
password: const Password: Schema.filter<Schema.Schema<string, string, never>>
Password, confirm_password: Schema.filter<Schema.Schema<string, string, never>>
confirm_password: const Password: Schema.filter<Schema.Schema<string, string, never>>
Password, name: Schema.optional<typeof Schema.String>
name: const OptionalString: Schema.optional<typeof Schema.String>
OptionalString, surname: Schema.optional<typeof Schema.String>
surname: const OptionalString: Schema.optional<typeof Schema.String>
OptionalString}).Pipeable.pipe<Schema.Struct<{ password: Schema.filter<Schema.Schema<string, string, never>>; confirm_password: Schema.filter<Schema.Schema<string, string, never>>; name: Schema.optional<...>; surname: Schema.optional<...>;}>, Schema.filter<...>>(this: Schema.Struct<...>, ab: (_: Schema.Struct<...>) => Schema.filter<...>): Schema.filter<...> (+21 overloads)
pipe( import Schema
Schema.function filter<Schema.Struct<{ password: Schema.filter<Schema.Schema<string, string, never>>; confirm_password: Schema.filter<Schema.Schema<string, string, never>>; name: Schema.optional<...>; surname: Schema.optional<...>;}>>(predicate: (a: { ...;}, options: ParseOptions, self: Refinement) => FilterReturnType, annotations?: Schema.Annotations.Filter<...> | undefined): (self: Schema.Struct<...>) => Schema.filter<...> (+2 overloads)
filter((input: { readonly password: string; readonly confirm_password: string; readonly name?: string | undefined; readonly surname?: string | undefined;}
input) => { const const issues: Schema.FilterIssue[]
issues: interface Array<T>
Array<import Schema
Schema.interface FilterIssue
FilterIssue> = []
// Check if passwords match if (input: { readonly password: string; readonly confirm_password: string; readonly name?: string | undefined; readonly surname?: string | undefined;}
input.password: string
password !== input: { readonly password: string; readonly confirm_password: string; readonly name?: string | undefined; readonly surname?: string | undefined;}
input.confirm_password: string
confirm_password) { const issues: Schema.FilterIssue[]
issues.Array<FilterIssue>.push(...items: Schema.FilterIssue[]): number
Appends new elements to the end of an array, and returns the new length of the array.
push({ FilterIssue.path: readonly PropertyKey[]
path: ["confirm_password"], FilterIssue.message: string
message: "Passwords do not match" }) }
// Ensure either name or surname is present if (!input: { readonly password: string; readonly confirm_password: string; readonly name?: string | undefined; readonly surname?: string | undefined;}
input.name?: string | undefined
name && !input: { readonly password: string; readonly confirm_password: string; readonly name?: string | undefined; readonly surname?: string | undefined;}
input.surname?: string | undefined
surname) { const issues: Schema.FilterIssue[]
issues.Array<FilterIssue>.push(...items: Schema.FilterIssue[]): number
Appends new elements to the end of an array, and returns the new length of the array.
push({ FilterIssue.path: readonly PropertyKey[]
path: ["surname"], FilterIssue.message: string
message: "Surname must be present if name is not present" }) } return const issues: Schema.FilterIssue[]
issues }))
var console: Console
The console
module provides a simple debugging console that is similar to the
JavaScript console mechanism provided by web browsers.
The module exports two specific components:
- A
Console
class with methods such as console.log()
, console.error()
and console.warn()
that can be used to write to any Node.js stream.
- A global
console
instance configured to write to process.stdout
and
process.stderr
. The global console
can be used without importing the node:console
module.
Warning: The global console object's methods are neither consistently
synchronous like the browser APIs they resemble, nor are they consistently
asynchronous like all other Node.js streams. See the note on process I/O
for
more information.
Example using the global console
:
console.log('hello world');// Prints: hello world, to stdoutconsole.log('hello %s', 'world');// Prints: hello world, to stdoutconsole.error(new Error('Whoops, something bad happened'));// Prints error message and stack trace to stderr:// Error: Whoops, something bad happened// at [eval]:5:15// at Script.runInThisContext (node:vm:132:18)// at Object.runInThisContext (node:vm:309:38)// at node:internal/process/execution:77:19// at [eval]-wrapper:6:22// at evalScript (node:internal/process/execution:76:60)// at node:internal/main/eval_string:23:3
const name = 'Will Robinson';console.warn(`Danger ${name}! Danger!`);// Prints: Danger Will Robinson! Danger!, to stderr
Example using the Console
class:
const out = getStreamSomehow();const err = getStreamSomehow();const myConsole = new console.Console(out, err);
myConsole.log('hello world');// Prints: hello world, to outmyConsole.log('hello %s', 'world');// Prints: hello world, to outmyConsole.error(new Error('Whoops, something bad happened'));// Prints: [Error: Whoops, something bad happened], to err
const name = 'Will Robinson';myConsole.warn(`Danger ${name}! Danger!`);// Prints: Danger Will Robinson! Danger!, to err
console.Console.log(message?: any, ...optionalParams: any[]): void
Prints to stdout
with newline. Multiple arguments can be passed, with the
first used as the primary message and all additional used as substitution
values similar to printf(3)
(the arguments are all passed to util.format()
).
const count = 5;console.log('count: %d', count);// Prints: count: 5, to stdoutconsole.log('count:', count);// Prints: count: 5, to stdout
See util.format()
for more information.
log( var JSON: JSON
An intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format.
JSON.JSON.stringify(value: any, replacer?: (number | string)[] | null, space?: string | number): string (+1 overload)
Converts a JavaScript value to a JavaScript Object Notation (JSON) string.
stringify( import Schema
Schema.const decodeUnknownEither: <{ readonly password: string; readonly confirm_password: string; readonly name?: string | undefined; readonly surname?: string | undefined;}, { readonly password: string; readonly confirm_password: string; readonly name?: string | undefined; readonly surname?: string | undefined;}>(schema: Schema.Schema<...>, options?: ParseOptions) => (u: unknown, overrideOptions?: ParseOptions) => Either.Either<...>
decodeUnknownEither(const MyForm: Schema.filter<Schema.Struct<{ password: Schema.filter<Schema.Schema<string, string, never>>; confirm_password: Schema.filter<Schema.Schema<string, string, never>>; name: Schema.optional<...>; surname: Schema.optional<...>;}>>
MyForm)({ password: string
password: "abc", confirm_password: string
confirm_password: "d" // Confirm password does not match }).Pipeable.pipe<Either.Either<{ readonly password: string; readonly confirm_password: string; readonly name?: string | undefined; readonly surname?: string | undefined;}, ParseResult.ParseError>, Either.Either<...>>(this: Either.Either<...>, ab: (_: Either.Either<...>) => Either.Either<...>): Either.Either<...> (+21 overloads)
pipe( import Either
Either.const mapLeft: <ParseResult.ParseError, ParseResult.ArrayFormatterIssue[]>(f: (left: ParseResult.ParseError) => ParseResult.ArrayFormatterIssue[]) => <R>(self: Either.Either<...>) => Either.Either<...> (+1 overload)
Maps the Left
side of an Either
value to a new Either
value.
mapLeft((error: ParseResult.ParseError
error) => import ParseResult
ParseResult.const ArrayFormatter: ParseResult.ParseResultFormatter<ParseResult.ArrayFormatterIssue[]>
ArrayFormatter.ParseResultFormatter<ArrayFormatterIssue[]>.formatErrorSync: (error: ParseResult.ParseError) => ParseResult.ArrayFormatterIssue[]
formatErrorSync(error: ParseResult.ParseError
error) ) ), null, 2 ))/*{ "_id": "Either", "_tag": "Left", "left": [ { "_tag": "Type", "path": [ "confirm_password" ], "message": "Passwords do not match" }, { "_tag": "Type", "path": [ "surname" ], "message": "Surname must be present if name is not present" } ]}*/
In this example, we define a MyForm
schema with fields for password validation and optional name/surname fields. The Schema.filter
function checks if the passwords match and ensures that either a name or surname is provided. If either validation fails, the corresponding error message is associated with the relevant field and both errors are returned in a structured format.
For schemas with filters, you can access the base schema (the schema before the filter was applied) using the from
property:
import { import Schema
Schema } from "effect"
const const LongString: Schema.filter<typeof Schema.String>
LongString = import Schema
Schema.class Stringexport String
String.Pipeable.pipe<typeof Schema.String, Schema.filter<typeof Schema.String>>(this: typeof Schema.String, ab: (_: typeof Schema.String) => Schema.filter<typeof Schema.String>): Schema.filter<...> (+21 overloads)
pipe( import Schema
Schema.function filter<typeof Schema.String>(predicate: (a: string, options: ParseOptions, self: Refinement) => FilterReturnType, annotations?: Schema.Annotations.Filter<...> | undefined): (self: typeof Schema.String) => Schema.filter<...> (+2 overloads)
filter((s: string
s) => s: string
s.String.length: number
Returns the length of a String object.
length >= 10))
// Access the base schema, which is the string schema// before the filter was applied//// ┌─── typeof Schema.String// ▼const const From: typeof Schema.String
From = const LongString: Schema.filter<typeof Schema.String>
LongString.refine<string, typeof String$>.from: typeof Schema.String
from
Here is a list of useful string filters provided by the Schema module:
import { import Schema
Schema } from "effect"
// Specifies maximum length of a stringimport Schema
Schema.class Stringexport String
String.Pipeable.pipe<typeof Schema.String, Schema.filter<Schema.Schema<string, string, never>>>(this: typeof Schema.String, ab: (_: typeof Schema.String) => Schema.filter<Schema.Schema<string, string, never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const maxLength: <string>(maxLength: number, annotations?: Schema.Annotations.Filter<string, string> | undefined) => <I, R>(self: Schema.Schema<string, I, R>) => Schema.filter<...>
maxLength(5))
// Specifies minimum length of a stringimport Schema
Schema.class Stringexport String
String.Pipeable.pipe<typeof Schema.String, Schema.filter<Schema.Schema<string, string, never>>>(this: typeof Schema.String, ab: (_: typeof Schema.String) => Schema.filter<Schema.Schema<string, string, never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const minLength: <string>(minLength: number, annotations?: Schema.Annotations.Filter<string, string> | undefined) => <I, R>(self: Schema.Schema<string, I, R>) => Schema.filter<...>
minLength(5))
// Equivalent to ensuring the string has a minimum length of 1import Schema
Schema.class NonEmptyString
NonEmptyString
// Specifies exact length of a stringimport Schema
Schema.class Stringexport String
String.Pipeable.pipe<typeof Schema.String, Schema.filter<Schema.Schema<string, string, never>>>(this: typeof Schema.String, ab: (_: typeof Schema.String) => Schema.filter<Schema.Schema<string, string, never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const length: <string>(length: number | { readonly min: number; readonly max: number;}, annotations?: Schema.Annotations.Filter<string, string> | undefined) => <I, R>(self: Schema.Schema<...>) => Schema.filter<...>
length(5))
// Specifies a range for the length of a stringimport Schema
Schema.class Stringexport String
String.Pipeable.pipe<typeof Schema.String, Schema.filter<Schema.Schema<string, string, never>>>(this: typeof Schema.String, ab: (_: typeof Schema.String) => Schema.filter<Schema.Schema<string, string, never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const length: <string>(length: number | { readonly min: number; readonly max: number;}, annotations?: Schema.Annotations.Filter<string, string> | undefined) => <I, R>(self: Schema.Schema<...>) => Schema.filter<...>
length({ min: number
min: 2, max: number
max: 4 }))
// Matches a string against a regular expression patternimport Schema
Schema.class Stringexport String
String.Pipeable.pipe<typeof Schema.String, Schema.filter<Schema.Schema<string, string, never>>>(this: typeof Schema.String, ab: (_: typeof Schema.String) => Schema.filter<Schema.Schema<string, string, never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const pattern: <string>(regex: RegExp, annotations?: Schema.Annotations.Filter<string, string> | undefined) => <I, R>(self: Schema.Schema<string, I, R>) => Schema.filter<Schema.Schema<...>>
pattern(/^[a-z]+$/))
// Ensures a string starts with a specific substringimport Schema
Schema.class Stringexport String
String.Pipeable.pipe<typeof Schema.String, Schema.filter<Schema.Schema<string, string, never>>>(this: typeof Schema.String, ab: (_: typeof Schema.String) => Schema.filter<Schema.Schema<string, string, never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const startsWith: <string>(startsWith: string, annotations?: Schema.Annotations.Filter<string, string> | undefined) => <I, R>(self: Schema.Schema<string, I, R>) => Schema.filter<...>
startsWith("prefix"))
// Ensures a string ends with a specific substringimport Schema
Schema.class Stringexport String
String.Pipeable.pipe<typeof Schema.String, Schema.filter<Schema.Schema<string, string, never>>>(this: typeof Schema.String, ab: (_: typeof Schema.String) => Schema.filter<Schema.Schema<string, string, never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const endsWith: <string>(endsWith: string, annotations?: Schema.Annotations.Filter<string, string> | undefined) => <I, R>(self: Schema.Schema<string, I, R>) => Schema.filter<...>
endsWith("suffix"))
// Checks if a string includes a specific substringimport Schema
Schema.class Stringexport String
String.Pipeable.pipe<typeof Schema.String, Schema.filter<Schema.Schema<string, string, never>>>(this: typeof Schema.String, ab: (_: typeof Schema.String) => Schema.filter<Schema.Schema<string, string, never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const includes: <string>(searchString: string, annotations?: Schema.Annotations.Filter<string, string> | undefined) => <I, R>(self: Schema.Schema<string, I, R>) => Schema.filter<...>
includes("substring"))
// Validates that a string has no leading or trailing whitespacesimport Schema
Schema.class Stringexport String
String.Pipeable.pipe<typeof Schema.String, Schema.filter<Schema.Schema<string, string, never>>>(this: typeof Schema.String, ab: (_: typeof Schema.String) => Schema.filter<Schema.Schema<string, string, never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const trimmed: <string>(annotations?: Schema.Annotations.Filter<string, string> | undefined) => <I, R>(self: Schema.Schema<string, I, R>) => Schema.filter<Schema.Schema<string, I, R>>
Verifies that a string contains no leading or trailing whitespaces.
Note. This combinator does not make any transformations, it only validates.
If what you were looking for was a combinator to trim strings, then check out the trim
combinator.
trimmed())
// Validates that a string is entirely in lowercaseimport Schema
Schema.class Stringexport String
String.Pipeable.pipe<typeof Schema.String, Schema.filter<Schema.Schema<string, string, never>>>(this: typeof Schema.String, ab: (_: typeof Schema.String) => Schema.filter<Schema.Schema<string, string, never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const lowercased: <string>(annotations?: Schema.Annotations.Filter<string, string> | undefined) => <I, R>(self: Schema.Schema<string, I, R>) => Schema.filter<Schema.Schema<string, I, R>>
Verifies that a string is lowercased.
lowercased())
// Validates that a string is entirely in uppercaseimport Schema
Schema.class Stringexport String
String.Pipeable.pipe<typeof Schema.String, Schema.filter<Schema.Schema<string, string, never>>>(this: typeof Schema.String, ab: (_: typeof Schema.String) => Schema.filter<Schema.Schema<string, string, never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const uppercased: <string>(annotations?: Schema.Annotations.Filter<string, string> | undefined) => <I, R>(self: Schema.Schema<string, I, R>) => Schema.filter<Schema.Schema<string, I, R>>
Verifies that a string is uppercased.
uppercased())
// Validates that a string is capitalizedimport Schema
Schema.class Stringexport String
String.Pipeable.pipe<typeof Schema.String, Schema.filter<Schema.Schema<string, string, never>>>(this: typeof Schema.String, ab: (_: typeof Schema.String) => Schema.filter<Schema.Schema<string, string, never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const capitalized: <string>(annotations?: Schema.Annotations.Filter<string, string> | undefined) => <I, R>(self: Schema.Schema<string, I, R>) => Schema.filter<Schema.Schema<string, I, R>>
Verifies that a string is capitalized.
capitalized())
// Validates that a string is uncapitalizedimport Schema
Schema.class Stringexport String
String.Pipeable.pipe<typeof Schema.String, Schema.filter<Schema.Schema<string, string, never>>>(this: typeof Schema.String, ab: (_: typeof Schema.String) => Schema.filter<Schema.Schema<string, string, never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const uncapitalized: <string>(annotations?: Schema.Annotations.Filter<string, string> | undefined) => <I, R>(self: Schema.Schema<string, I, R>) => Schema.filter<Schema.Schema<string, I, R>>
Verifies that a string is uncapitalized.
uncapitalized())
Here is a list of useful number filters provided by the Schema module:
import { import Schema
Schema } from "effect"
// Specifies a number greater than 5import Schema
Schema.class Numberexport Number
Number.Pipeable.pipe<typeof Schema.Number, Schema.filter<Schema.Schema<number, number, never>>>(this: typeof Schema.Number, ab: (_: typeof Schema.Number) => Schema.filter<Schema.Schema<number, number, never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const greaterThan: <number>(min: number, annotations?: Schema.Annotations.Filter<number, number> | undefined) => <I, R>(self: Schema.Schema<number, I, R>) => Schema.filter<Schema.Schema<number, I, R>>
This filter checks whether the provided number is greater than the specified minimum.
greaterThan(5))
// Specifies a number greater than or equal to 5import Schema
Schema.class Numberexport Number
Number.Pipeable.pipe<typeof Schema.Number, Schema.filter<Schema.Schema<number, number, never>>>(this: typeof Schema.Number, ab: (_: typeof Schema.Number) => Schema.filter<Schema.Schema<number, number, never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const greaterThanOrEqualTo: <number>(min: number, annotations?: Schema.Annotations.Filter<number, number> | undefined) => <I, R>(self: Schema.Schema<number, I, R>) => Schema.filter<Schema.Schema<number, I, R>>
This filter checks whether the provided number is greater than or equal to the specified minimum.
greaterThanOrEqualTo(5))
// Specifies a number less than 5import Schema
Schema.class Numberexport Number
Number.Pipeable.pipe<typeof Schema.Number, Schema.filter<Schema.Schema<number, number, never>>>(this: typeof Schema.Number, ab: (_: typeof Schema.Number) => Schema.filter<Schema.Schema<number, number, never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const lessThan: <number>(max: number, annotations?: Schema.Annotations.Filter<number, number> | undefined) => <I, R>(self: Schema.Schema<number, I, R>) => Schema.filter<Schema.Schema<number, I, R>>
This filter checks whether the provided number is less than the specified maximum.
lessThan(5))
// Specifies a number less than or equal to 5import Schema
Schema.class Numberexport Number
Number.Pipeable.pipe<typeof Schema.Number, Schema.filter<Schema.Schema<number, number, never>>>(this: typeof Schema.Number, ab: (_: typeof Schema.Number) => Schema.filter<Schema.Schema<number, number, never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const lessThanOrEqualTo: <number>(max: number, annotations?: Schema.Annotations.Filter<number, number> | undefined) => <I, R>(self: Schema.Schema<number, I, R>) => Schema.filter<Schema.Schema<number, I, R>>
This schema checks whether the provided number is less than or equal to the specified maximum.
lessThanOrEqualTo(5))
// Specifies a number between -2 and 2, inclusiveimport Schema
Schema.class Numberexport Number
Number.Pipeable.pipe<typeof Schema.Number, Schema.filter<Schema.Schema<number, number, never>>>(this: typeof Schema.Number, ab: (_: typeof Schema.Number) => Schema.filter<Schema.Schema<number, number, never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const between: <number>(min: number, max: number, annotations?: Schema.Annotations.Filter<number, number> | undefined) => <I, R>(self: Schema.Schema<number, I, R>) => Schema.filter<...>
This filter checks whether the provided number falls within the specified minimum and maximum values.
between(-2, 2))
// Specifies that the value must be an integerimport Schema
Schema.class Numberexport Number
Number.Pipeable.pipe<typeof Schema.Number, Schema.filter<Schema.Schema<number, number, never>>>(this: typeof Schema.Number, ab: (_: typeof Schema.Number) => Schema.filter<Schema.Schema<number, number, never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const int: <number>(annotations?: Schema.Annotations.Filter<number, number> | undefined) => <I, R>(self: Schema.Schema<number, I, R>) => Schema.filter<Schema.Schema<number, I, R>>
int())
// Ensures the value is not NaNimport Schema
Schema.class Numberexport Number
Number.Pipeable.pipe<typeof Schema.Number, Schema.filter<Schema.Schema<number, number, never>>>(this: typeof Schema.Number, ab: (_: typeof Schema.Number) => Schema.filter<Schema.Schema<number, number, never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const nonNaN: <number>(annotations?: Schema.Annotations.Filter<number, number> | undefined) => <I, R>(self: Schema.Schema<number, I, R>) => Schema.filter<Schema.Schema<number, I, R>>
nonNaN())
// Ensures the value is finite and not Infinity or -Infinityimport Schema
Schema.class Numberexport Number
Number.Pipeable.pipe<typeof Schema.Number, Schema.filter<Schema.Schema<number, number, never>>>(this: typeof Schema.Number, ab: (_: typeof Schema.Number) => Schema.filter<Schema.Schema<number, number, never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const finite: <number>(annotations?: Schema.Annotations.Filter<number, number> | undefined) => <I, R>(self: Schema.Schema<number, I, R>) => Schema.filter<Schema.Schema<number, I, R>>
Ensures that the provided value is a finite number.
This schema filters out non-finite numeric values, allowing only finite numbers to pass through.
finite())
// Specifies a positive number (> 0)import Schema
Schema.class Numberexport Number
Number.Pipeable.pipe<typeof Schema.Number, Schema.filter<Schema.Schema<number, number, never>>>(this: typeof Schema.Number, ab: (_: typeof Schema.Number) => Schema.filter<Schema.Schema<number, number, never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const positive: <number>(annotations?: Schema.Annotations.Filter<number, number> | undefined) => <I, R>(self: Schema.Schema<number, I, R>) => Schema.filter<Schema.Schema<number, I, R>>
positive())
// Specifies a non-negative number (>= 0)import Schema
Schema.class Numberexport Number
Number.Pipeable.pipe<typeof Schema.Number, Schema.filter<Schema.Schema<number, number, never>>>(this: typeof Schema.Number, ab: (_: typeof Schema.Number) => Schema.filter<Schema.Schema<number, number, never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const nonNegative: <number>(annotations?: Schema.Annotations.Filter<number, number> | undefined) => <I, R>(self: Schema.Schema<number, I, R>) => Schema.filter<Schema.Schema<number, I, R>>
nonNegative())
// Specifies a negative number (< 0)import Schema
Schema.class Numberexport Number
Number.Pipeable.pipe<typeof Schema.Number, Schema.filter<Schema.Schema<number, number, never>>>(this: typeof Schema.Number, ab: (_: typeof Schema.Number) => Schema.filter<Schema.Schema<number, number, never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const negative: <number>(annotations?: Schema.Annotations.Filter<number, number> | undefined) => <I, R>(self: Schema.Schema<number, I, R>) => Schema.filter<Schema.Schema<number, I, R>>
negative())
// Specifies a non-positive number (<= 0)import Schema
Schema.class Numberexport Number
Number.Pipeable.pipe<typeof Schema.Number, Schema.filter<Schema.Schema<number, number, never>>>(this: typeof Schema.Number, ab: (_: typeof Schema.Number) => Schema.filter<Schema.Schema<number, number, never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const nonPositive: <number>(annotations?: Schema.Annotations.Filter<number, number> | undefined) => <I, R>(self: Schema.Schema<number, I, R>) => Schema.filter<Schema.Schema<number, I, R>>
nonPositive())
// Specifies a number that is evenly divisible by 5import Schema
Schema.class Numberexport Number
Number.Pipeable.pipe<typeof Schema.Number, Schema.filter<Schema.Schema<number, number, never>>>(this: typeof Schema.Number, ab: (_: typeof Schema.Number) => Schema.filter<Schema.Schema<number, number, never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const multipleOf: <number>(divisor: number, annotations?: Schema.Annotations.Filter<number, number> | undefined) => <I, R>(self: Schema.Schema<number, I, R>) => Schema.filter<...>
multipleOf(5))
Here is a list of useful array filters provided by the Schema module:
import { import Schema
Schema } from "effect"
// Specifies the maximum number of items in the arrayimport Schema
Schema.Array<typeof Schema.Number>(value: typeof Schema.Number): Schema.Array$<typeof Schema.Number>export Array
Array(import Schema
Schema.class Numberexport Number
Number).Pipeable.pipe<Schema.Array$<typeof Schema.Number>, Schema.filter<Schema.Schema<readonly number[], readonly number[], never>>>(this: Schema.Array$<...>, ab: (_: Schema.Array$<typeof Schema.Number>) => Schema.filter<...>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const maxItems: <number>(n: number, annotations?: Schema.Annotations.Filter<readonly number[], readonly number[]> | undefined) => <I, R>(self: Schema.Schema<readonly number[], I, R>) => Schema.filter<Schema.Schema<readonly number[], I, R>>
maxItems(2))
// Specifies the minimum number of items in the arrayimport Schema
Schema.Array<typeof Schema.Number>(value: typeof Schema.Number): Schema.Array$<typeof Schema.Number>export Array
Array(import Schema
Schema.class Numberexport Number
Number).Pipeable.pipe<Schema.Array$<typeof Schema.Number>, Schema.filter<Schema.Schema<readonly number[], readonly number[], never>>>(this: Schema.Array$<...>, ab: (_: Schema.Array$<typeof Schema.Number>) => Schema.filter<...>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const minItems: <number>(n: number, annotations?: Schema.Annotations.Filter<readonly number[], readonly number[]> | undefined) => <I, R>(self: Schema.Schema<readonly number[], I, R>) => Schema.filter<Schema.Schema<readonly number[], I, R>>
minItems(2))
// Specifies the exact number of items in the arrayimport Schema
Schema.Array<typeof Schema.Number>(value: typeof Schema.Number): Schema.Array$<typeof Schema.Number>export Array
Array(import Schema
Schema.class Numberexport Number
Number).Pipeable.pipe<Schema.Array$<typeof Schema.Number>, Schema.filter<Schema.Schema<readonly number[], readonly number[], never>>>(this: Schema.Array$<...>, ab: (_: Schema.Array$<typeof Schema.Number>) => Schema.filter<...>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const itemsCount: <number>(n: number, annotations?: Schema.Annotations.Filter<readonly number[], readonly number[]> | undefined) => <I, R>(self: Schema.Schema<readonly number[], I, R>) => Schema.filter<Schema.Schema<readonly number[], I, R>>
itemsCount(2))
Here is a list of useful BigInt
filters provided by the Schema module:
import { import Schema
Schema } from "effect"
// Specifies a BigInt greater than 5import Schema
Schema.class BigIntexport BigInt
This schema transforms a string
into a bigint
by parsing the string using the BigInt
function.
It returns an error if the value can't be converted (for example when non-numeric characters are provided).
BigInt.Pipeable.pipe<typeof Schema.BigInt, Schema.filter<Schema.Schema<bigint, string, never>>>(this: typeof Schema.BigInt, ab: (_: typeof Schema.BigInt) => Schema.filter<Schema.Schema<bigint, string, never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const greaterThanBigInt: <bigint>(min: bigint, annotations?: Schema.Annotations.Filter<bigint, bigint> | undefined) => <I, R>(self: Schema.Schema<bigint, I, R>) => Schema.filter<Schema.Schema<bigint, I, R>>
greaterThanBigInt(5n))
// Specifies a BigInt greater than or equal to 5import Schema
Schema.class BigIntexport BigInt
This schema transforms a string
into a bigint
by parsing the string using the BigInt
function.
It returns an error if the value can't be converted (for example when non-numeric characters are provided).
BigInt.Pipeable.pipe<typeof Schema.BigInt, Schema.filter<Schema.Schema<bigint, string, never>>>(this: typeof Schema.BigInt, ab: (_: typeof Schema.BigInt) => Schema.filter<Schema.Schema<bigint, string, never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const greaterThanOrEqualToBigInt: <bigint>(min: bigint, annotations?: Schema.Annotations.Filter<bigint, bigint> | undefined) => <I, R>(self: Schema.Schema<bigint, I, R>) => Schema.filter<Schema.Schema<bigint, I, R>>
greaterThanOrEqualToBigInt(5n))
// Specifies a BigInt less than 5import Schema
Schema.class BigIntexport BigInt
This schema transforms a string
into a bigint
by parsing the string using the BigInt
function.
It returns an error if the value can't be converted (for example when non-numeric characters are provided).
BigInt.Pipeable.pipe<typeof Schema.BigInt, Schema.filter<Schema.Schema<bigint, string, never>>>(this: typeof Schema.BigInt, ab: (_: typeof Schema.BigInt) => Schema.filter<Schema.Schema<bigint, string, never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const lessThanBigInt: <bigint>(max: bigint, annotations?: Schema.Annotations.Filter<bigint, bigint> | undefined) => <I, R>(self: Schema.Schema<bigint, I, R>) => Schema.filter<Schema.Schema<bigint, I, R>>
lessThanBigInt(5n))
// Specifies a BigInt less than or equal to 5import Schema
Schema.class BigIntexport BigInt
This schema transforms a string
into a bigint
by parsing the string using the BigInt
function.
It returns an error if the value can't be converted (for example when non-numeric characters are provided).
BigInt.Pipeable.pipe<typeof Schema.BigInt, Schema.filter<Schema.Schema<bigint, string, never>>>(this: typeof Schema.BigInt, ab: (_: typeof Schema.BigInt) => Schema.filter<Schema.Schema<bigint, string, never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const lessThanOrEqualToBigInt: <bigint>(max: bigint, annotations?: Schema.Annotations.Filter<bigint, bigint> | undefined) => <I, R>(self: Schema.Schema<bigint, I, R>) => Schema.filter<Schema.Schema<bigint, I, R>>
lessThanOrEqualToBigInt(5n))
// Specifies a BigInt between -2n and 2n, inclusiveimport Schema
Schema.class BigIntexport BigInt
This schema transforms a string
into a bigint
by parsing the string using the BigInt
function.
It returns an error if the value can't be converted (for example when non-numeric characters are provided).
BigInt.Pipeable.pipe<typeof Schema.BigInt, Schema.filter<Schema.Schema<bigint, string, never>>>(this: typeof Schema.BigInt, ab: (_: typeof Schema.BigInt) => Schema.filter<Schema.Schema<bigint, string, never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const betweenBigInt: <bigint>(min: bigint, max: bigint, annotations?: Schema.Annotations.Filter<bigint, bigint> | undefined) => <I, R>(self: Schema.Schema<bigint, I, R>) => Schema.filter<...>
betweenBigInt(-2n, 2n))
// Specifies a positive BigInt (> 0n)import Schema
Schema.class BigIntexport BigInt
This schema transforms a string
into a bigint
by parsing the string using the BigInt
function.
It returns an error if the value can't be converted (for example when non-numeric characters are provided).
BigInt.Pipeable.pipe<typeof Schema.BigInt, Schema.filter<Schema.Schema<bigint, string, never>>>(this: typeof Schema.BigInt, ab: (_: typeof Schema.BigInt) => Schema.filter<Schema.Schema<bigint, string, never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const positiveBigInt: <bigint>(annotations?: Schema.Annotations.Filter<bigint, bigint> | undefined) => <I, R>(self: Schema.Schema<bigint, I, R>) => Schema.filter<Schema.Schema<bigint, I, R>>
positiveBigInt())
// Specifies a non-negative BigInt (>= 0n)import Schema
Schema.class BigIntexport BigInt
This schema transforms a string
into a bigint
by parsing the string using the BigInt
function.
It returns an error if the value can't be converted (for example when non-numeric characters are provided).
BigInt.Pipeable.pipe<typeof Schema.BigInt, Schema.filter<Schema.Schema<bigint, string, never>>>(this: typeof Schema.BigInt, ab: (_: typeof Schema.BigInt) => Schema.filter<Schema.Schema<bigint, string, never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const nonNegativeBigInt: <bigint>(annotations?: Schema.Annotations.Filter<bigint, bigint> | undefined) => <I, R>(self: Schema.Schema<bigint, I, R>) => Schema.filter<Schema.Schema<bigint, I, R>>
nonNegativeBigInt())
// Specifies a negative BigInt (< 0n)import Schema
Schema.class BigIntexport BigInt
This schema transforms a string
into a bigint
by parsing the string using the BigInt
function.
It returns an error if the value can't be converted (for example when non-numeric characters are provided).
BigInt.Pipeable.pipe<typeof Schema.BigInt, Schema.filter<Schema.Schema<bigint, string, never>>>(this: typeof Schema.BigInt, ab: (_: typeof Schema.BigInt) => Schema.filter<Schema.Schema<bigint, string, never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const negativeBigInt: <bigint>(annotations?: Schema.Annotations.Filter<bigint, bigint> | undefined) => <I, R>(self: Schema.Schema<bigint, I, R>) => Schema.filter<Schema.Schema<bigint, I, R>>
negativeBigInt())
// Specifies a non-positive BigInt (<= 0n)import Schema
Schema.class BigIntexport BigInt
This schema transforms a string
into a bigint
by parsing the string using the BigInt
function.
It returns an error if the value can't be converted (for example when non-numeric characters are provided).
BigInt.Pipeable.pipe<typeof Schema.BigInt, Schema.filter<Schema.Schema<bigint, string, never>>>(this: typeof Schema.BigInt, ab: (_: typeof Schema.BigInt) => Schema.filter<Schema.Schema<bigint, string, never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const nonPositiveBigInt: <bigint>(annotations?: Schema.Annotations.Filter<bigint, bigint> | undefined) => <I, R>(self: Schema.Schema<bigint, I, R>) => Schema.filter<Schema.Schema<bigint, I, R>>
nonPositiveBigInt())
Here is a list of useful BigDecimal
filters provided by the Schema module:
import { import Schema
Schema } from "effect"import { import BigDecimal
BigDecimal } from "effect"
// Specifies a BigDecimal greater than 5import Schema
Schema.class BigDecimal
BigDecimal.Pipeable.pipe<typeof Schema.BigDecimal, Schema.filter<Schema.Schema<BigDecimal.BigDecimal, string, never>>>(this: typeof Schema.BigDecimal, ab: (_: typeof Schema.BigDecimal) => Schema.filter<Schema.Schema<BigDecimal.BigDecimal, string, never>>): Schema.filter<...> (+21 overloads)
pipe( import Schema
Schema.const greaterThanBigDecimal: <BigDecimal.BigDecimal>(min: BigDecimal.BigDecimal, annotations?: Schema.Annotations.Filter<BigDecimal.BigDecimal, BigDecimal.BigDecimal> | undefined) => <I, R>(self: Schema.Schema<...>) => Schema.filter<...>
greaterThanBigDecimal(import BigDecimal
BigDecimal.const fromNumber: (n: number) => BigDecimal.BigDecimal
Creates a BigDecimal
from a number
value.
It is not recommended to convert a floating point number to a decimal directly,
as the floating point representation may be unexpected.
Throws a RangeError
if the number is not finite (NaN
, +Infinity
or -Infinity
).
fromNumber(5)))
// Specifies a BigDecimal greater than or equal to 5import Schema
Schema.class BigDecimal
BigDecimal.Pipeable.pipe<typeof Schema.BigDecimal, Schema.filter<Schema.Schema<BigDecimal.BigDecimal, string, never>>>(this: typeof Schema.BigDecimal, ab: (_: typeof Schema.BigDecimal) => Schema.filter<Schema.Schema<BigDecimal.BigDecimal, string, never>>): Schema.filter<...> (+21 overloads)
pipe( import Schema
Schema.const greaterThanOrEqualToBigDecimal: <BigDecimal.BigDecimal>(min: BigDecimal.BigDecimal, annotations?: Schema.Annotations.Filter<BigDecimal.BigDecimal, BigDecimal.BigDecimal> | undefined) => <I, R>(self: Schema.Schema<...>) => Schema.filter<...>
greaterThanOrEqualToBigDecimal(import BigDecimal
BigDecimal.const fromNumber: (n: number) => BigDecimal.BigDecimal
Creates a BigDecimal
from a number
value.
It is not recommended to convert a floating point number to a decimal directly,
as the floating point representation may be unexpected.
Throws a RangeError
if the number is not finite (NaN
, +Infinity
or -Infinity
).
fromNumber(5)))// Specifies a BigDecimal less than 5import Schema
Schema.class BigDecimal
BigDecimal.Pipeable.pipe<typeof Schema.BigDecimal, Schema.filter<Schema.Schema<BigDecimal.BigDecimal, string, never>>>(this: typeof Schema.BigDecimal, ab: (_: typeof Schema.BigDecimal) => Schema.filter<Schema.Schema<BigDecimal.BigDecimal, string, never>>): Schema.filter<...> (+21 overloads)
pipe( import Schema
Schema.const lessThanBigDecimal: <BigDecimal.BigDecimal>(max: BigDecimal.BigDecimal, annotations?: Schema.Annotations.Filter<BigDecimal.BigDecimal, BigDecimal.BigDecimal> | undefined) => <I, R>(self: Schema.Schema<...>) => Schema.filter<...>
lessThanBigDecimal(import BigDecimal
BigDecimal.const fromNumber: (n: number) => BigDecimal.BigDecimal
Creates a BigDecimal
from a number
value.
It is not recommended to convert a floating point number to a decimal directly,
as the floating point representation may be unexpected.
Throws a RangeError
if the number is not finite (NaN
, +Infinity
or -Infinity
).
fromNumber(5)))
// Specifies a BigDecimal less than or equal to 5import Schema
Schema.class BigDecimal
BigDecimal.Pipeable.pipe<typeof Schema.BigDecimal, Schema.filter<Schema.Schema<BigDecimal.BigDecimal, string, never>>>(this: typeof Schema.BigDecimal, ab: (_: typeof Schema.BigDecimal) => Schema.filter<Schema.Schema<BigDecimal.BigDecimal, string, never>>): Schema.filter<...> (+21 overloads)
pipe( import Schema
Schema.const lessThanOrEqualToBigDecimal: <BigDecimal.BigDecimal>(max: BigDecimal.BigDecimal, annotations?: Schema.Annotations.Filter<BigDecimal.BigDecimal, BigDecimal.BigDecimal> | undefined) => <I, R>(self: Schema.Schema<...>) => Schema.filter<...>
lessThanOrEqualToBigDecimal(import BigDecimal
BigDecimal.const fromNumber: (n: number) => BigDecimal.BigDecimal
Creates a BigDecimal
from a number
value.
It is not recommended to convert a floating point number to a decimal directly,
as the floating point representation may be unexpected.
Throws a RangeError
if the number is not finite (NaN
, +Infinity
or -Infinity
).
fromNumber(5)))
// Specifies a BigDecimal between -2 and 2, inclusiveimport Schema
Schema.class BigDecimal
BigDecimal.Pipeable.pipe<typeof Schema.BigDecimal, Schema.filter<Schema.Schema<BigDecimal.BigDecimal, string, never>>>(this: typeof Schema.BigDecimal, ab: (_: typeof Schema.BigDecimal) => Schema.filter<Schema.Schema<BigDecimal.BigDecimal, string, never>>): Schema.filter<...> (+21 overloads)
pipe( import Schema
Schema.const betweenBigDecimal: <BigDecimal.BigDecimal>(minimum: BigDecimal.BigDecimal, maximum: BigDecimal.BigDecimal, annotations?: Schema.Annotations.Filter<...> | undefined) => <I, R>(self: Schema.Schema<...>) => Schema.filter<...>
betweenBigDecimal( import BigDecimal
BigDecimal.const fromNumber: (n: number) => BigDecimal.BigDecimal
Creates a BigDecimal
from a number
value.
It is not recommended to convert a floating point number to a decimal directly,
as the floating point representation may be unexpected.
Throws a RangeError
if the number is not finite (NaN
, +Infinity
or -Infinity
).
fromNumber(-2), import BigDecimal
BigDecimal.const fromNumber: (n: number) => BigDecimal.BigDecimal
Creates a BigDecimal
from a number
value.
It is not recommended to convert a floating point number to a decimal directly,
as the floating point representation may be unexpected.
Throws a RangeError
if the number is not finite (NaN
, +Infinity
or -Infinity
).
fromNumber(2) ))
// Specifies a positive BigDecimal (> 0)import Schema
Schema.class BigDecimal
BigDecimal.Pipeable.pipe<typeof Schema.BigDecimal, Schema.filter<Schema.Schema<BigDecimal.BigDecimal, string, never>>>(this: typeof Schema.BigDecimal, ab: (_: typeof Schema.BigDecimal) => Schema.filter<Schema.Schema<BigDecimal.BigDecimal, string, never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const positiveBigDecimal: <BigDecimal.BigDecimal>(annotations?: Schema.Annotations.Filter<BigDecimal.BigDecimal, BigDecimal.BigDecimal> | undefined) => <I, R>(self: Schema.Schema<...>) => Schema.filter<...>
positiveBigDecimal())
// Specifies a non-negative BigDecimal (>= 0)import Schema
Schema.class BigDecimal
BigDecimal.Pipeable.pipe<typeof Schema.BigDecimal, Schema.filter<Schema.Schema<BigDecimal.BigDecimal, string, never>>>(this: typeof Schema.BigDecimal, ab: (_: typeof Schema.BigDecimal) => Schema.filter<Schema.Schema<BigDecimal.BigDecimal, string, never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const nonNegativeBigDecimal: <BigDecimal.BigDecimal>(annotations?: Schema.Annotations.Filter<BigDecimal.BigDecimal, BigDecimal.BigDecimal> | undefined) => <I, R>(self: Schema.Schema<...>) => Schema.filter<...>
nonNegativeBigDecimal())
// Specifies a negative BigDecimal (< 0)import Schema
Schema.class BigDecimal
BigDecimal.Pipeable.pipe<typeof Schema.BigDecimal, Schema.filter<Schema.Schema<BigDecimal.BigDecimal, string, never>>>(this: typeof Schema.BigDecimal, ab: (_: typeof Schema.BigDecimal) => Schema.filter<Schema.Schema<BigDecimal.BigDecimal, string, never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const negativeBigDecimal: <BigDecimal.BigDecimal>(annotations?: Schema.Annotations.Filter<BigDecimal.BigDecimal, BigDecimal.BigDecimal> | undefined) => <I, R>(self: Schema.Schema<...>) => Schema.filter<...>
negativeBigDecimal())
// Specifies a non-positive BigDecimal (<= 0)import Schema
Schema.class BigDecimal
BigDecimal.Pipeable.pipe<typeof Schema.BigDecimal, Schema.filter<Schema.Schema<BigDecimal.BigDecimal, string, never>>>(this: typeof Schema.BigDecimal, ab: (_: typeof Schema.BigDecimal) => Schema.filter<Schema.Schema<BigDecimal.BigDecimal, string, never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const nonPositiveBigDecimal: <BigDecimal.BigDecimal>(annotations?: Schema.Annotations.Filter<BigDecimal.BigDecimal, BigDecimal.BigDecimal> | undefined) => <I, R>(self: Schema.Schema<...>) => Schema.filter<...>
nonPositiveBigDecimal())
Here is a list of useful Duration
filters provided by the Schema module:
import { import Schema
Schema } from "effect"
// Specifies a duration greater than 5 secondsimport Schema
Schema.class Duration
A schema that transforms a [number, number]
tuple into a Duration
.
Duration.Pipeable.pipe<typeof Schema.Duration, Schema.filter<Schema.Schema<Duration, readonly [seconds: number, nanos: number], never>>>(this: typeof Schema.Duration, ab: (_: typeof Schema.Duration) => Schema.filter<Schema.Schema<Duration, readonly [seconds: ...], never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const greaterThanDuration: <Duration>(min: DurationInput, annotations?: Schema.Annotations.Filter<Duration, Duration> | undefined) => <I, R>(self: Schema.Schema<...>) => Schema.filter<...>
greaterThanDuration("5 seconds"))
// Specifies a duration greater than or equal to 5 secondsimport Schema
Schema.class Duration
A schema that transforms a [number, number]
tuple into a Duration
.
Duration.Pipeable.pipe<typeof Schema.Duration, Schema.filter<Schema.Schema<Duration, readonly [seconds: number, nanos: number], never>>>(this: typeof Schema.Duration, ab: (_: typeof Schema.Duration) => Schema.filter<Schema.Schema<Duration, readonly [seconds: ...], never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const greaterThanOrEqualToDuration: <Duration>(min: DurationInput, annotations?: Schema.Annotations.Filter<Duration, Duration> | undefined) => <I, R>(self: Schema.Schema<...>) => Schema.filter<...>
greaterThanOrEqualToDuration("5 seconds"))
// Specifies a duration less than 5 secondsimport Schema
Schema.class Duration
A schema that transforms a [number, number]
tuple into a Duration
.
Duration.Pipeable.pipe<typeof Schema.Duration, Schema.filter<Schema.Schema<Duration, readonly [seconds: number, nanos: number], never>>>(this: typeof Schema.Duration, ab: (_: typeof Schema.Duration) => Schema.filter<Schema.Schema<Duration, readonly [seconds: ...], never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const lessThanDuration: <Duration>(max: DurationInput, annotations?: Schema.Annotations.Filter<Duration, Duration> | undefined) => <I, R>(self: Schema.Schema<...>) => Schema.filter<...>
lessThanDuration("5 seconds"))
// Specifies a duration less than or equal to 5 secondsimport Schema
Schema.class Duration
A schema that transforms a [number, number]
tuple into a Duration
.
Duration.Pipeable.pipe<typeof Schema.Duration, Schema.filter<Schema.Schema<Duration, readonly [seconds: number, nanos: number], never>>>(this: typeof Schema.Duration, ab: (_: typeof Schema.Duration) => Schema.filter<Schema.Schema<Duration, readonly [seconds: ...], never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const lessThanOrEqualToDuration: <Duration>(max: DurationInput, annotations?: Schema.Annotations.Filter<Duration, Duration> | undefined) => <I, R>(self: Schema.Schema<...>) => Schema.filter<...>
lessThanOrEqualToDuration("5 seconds"))
// Specifies a duration between 5 seconds and 10 seconds, inclusiveimport Schema
Schema.class Duration
A schema that transforms a [number, number]
tuple into a Duration
.
Duration.Pipeable.pipe<typeof Schema.Duration, Schema.filter<Schema.Schema<Duration, readonly [seconds: number, nanos: number], never>>>(this: typeof Schema.Duration, ab: (_: typeof Schema.Duration) => Schema.filter<Schema.Schema<Duration, readonly [seconds: ...], never>>): Schema.filter<...> (+21 overloads)
pipe(import Schema
Schema.const betweenDuration: <Duration>(minimum: DurationInput, maximum: DurationInput, annotations?: Schema.Annotations.Filter<Duration, Duration> | undefined) => <I, R>(self: Schema.Schema<...>) => Schema.filter<...>
betweenDuration("5 seconds", "10 seconds"))