过滤器
开发人员可以定义超越基本类型检查的自定义验证逻辑,从而更好地控制数据验证方式。
过滤器使用 Schema.filter 函数声明。此函数需要两个参数:要验证的模式和谓词函数。谓词函数是用户定义的,用于确定数据是否满足条件。如果数据验证失败,可以提供错误消息。
示例(定义最小字符串长度过滤器)
import { import Schema
Schema } from "effect"
// 定义一个带有过滤器的字符串模式,以确保字符串// 至少有 10 个字符长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<typeof Schema.String> (+21 overloads)
pipe( import Schema
Schema.function filter<typeof Schema.String>(predicate: (a: string, options: ParseOptions, self: Refinement) => FilterReturnType, annotations?: Schema.Annotations.Filter<string, string> | undefined): (self: typeof Schema.String) => Schema.filter<typeof Schema.String> (+2 overloads)
filter( // 对于少于 10 个字符的字符串的自定义错误消息 (s: string
s) => s: string
s.String.length: number
Returns the length of a String object.
length >= 10 || "a string at least 10 characters long" ))
// ┌─── string// ▼type type Type = string
Type = typeof const LongString: Schema.filter<typeof Schema.String>
LongString.Schema<string, string, never>.Type: string
Type
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"))/*抛出:ParseError: { string | filter }└─ Predicate refinement failure └─ a string at least 10 characters long*/请注意,过滤器不会改变模式的 Type:
// ┌─── string// ▼type Type = typeof LongString.Type过滤器添加额外的验证约束,而不修改模式的底层类型。
过滤器中的谓词函数遵循以下结构:
type Predicate = ( a: A, options: ParseOptions, self: AST.Refinement) => FilterReturnType其中
interface FilterIssue { readonly path: ReadonlyArray<PropertyKey> readonly issue: string | ParseResult.ParseIssue}
type FilterOutput = | undefined | boolean | string | ParseResult.ParseIssue | FilterIssue
type FilterReturnType = FilterOutput | ReadonlyArray<FilterOutput>过滤器的谓词可以返回几种类型的值,每种都以不同的方式影响验证:
| 返回类型 | 行为 |
|---|---|
true 或 undefined | 数据满足过滤器的条件并通过验证。 |
false | 数据不满足条件,且不提供特定的错误消息。 |
string | 验证失败,提供的字符串用作错误消息。 |
ParseResult.ParseIssue | 验证失败并提供详细的错误结构,指定失败的位置和原因。 |
FilterIssue | 允许使用特定路径提供更详细的错误消息,提供增强的错误报告。 |
ReadonlyArray<FilterOutput> | 如果需要报告多个验证错误,可以返回问题数组。 |
在模式中嵌入元数据,如标识符、JSON模式规范和描述,可以增强对模式约束和目的的理解和分析。
示例(使用注解添加元数据)
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<typeof Schema.String> (+21 overloads)
pipe( import Schema
Schema.function filter<typeof Schema.String>(predicate: (a: string, options: ParseOptions, self: Refinement) => FilterReturnType, annotations?: Schema.Annotations.Filter<string, string> | undefined): (self: typeof Schema.String) => Schema.filter<typeof Schema.String> (+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"))/*抛出: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(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 JSONSchema
JSONSchema.const make: <string, string, never>(schema: Schema.Schema<string, string, never>) => JSONSchema.JsonSchema7Root
make(const LongString: Schema.filter<typeof Schema.String>
LongString), null, 2))/*输出:{ "$schema": "http://json-schema.org/draft-07/schema#", "$defs": { "LongString": { "type": "string", "description": "Lorem ipsum dolor sit amet, ...", "minLength": 10 } }, "$ref": "#/$defs/LongString"}*/在验证表单或结构化数据时,可以将特定的错误消息与特定的字段或路径关联。这增强了错误报告,在与react-hook-form等库集成时特别有用。
示例(匹配密码)
import { import Either
Either, import Schema
Schema, import ParseResult
ParseResult } from "effect"
const const Password: Schema.filter<typeof Schema.Trim>
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<typeof Schema.Trim>>(this: typeof Schema.Trim, ab: (_: typeof Schema.Trim) => Schema.filter<typeof Schema.Trim>): Schema.filter<typeof Schema.Trim> (+21 overloads)
pipe(import Schema
Schema.const minLength: <typeof Schema.Trim>(minLength: number, annotations?: Schema.Annotations.Filter<string, string> | undefined) => <A>(self: typeof Schema.Trim & Schema.Schema<A, string, never>) => Schema.filter<typeof Schema.Trim>
minLength(2))
const const MyForm: Schema.filter<Schema.Struct<{ password: Schema.filter<typeof Schema.Trim>; confirm_password: Schema.filter<typeof Schema.Trim>;}>>
MyForm = import Schema
Schema.function Struct<{ password: Schema.filter<typeof Schema.Trim>; confirm_password: Schema.filter<typeof Schema.Trim>;}>(fields: { password: Schema.filter<typeof Schema.Trim>; confirm_password: Schema.filter<typeof Schema.Trim>;}): Schema.Struct<{ password: Schema.filter<typeof Schema.Trim>; confirm_password: Schema.filter<typeof Schema.Trim>;}> (+1 overload)
Struct({ password: Schema.filter<typeof Schema.Trim>
password: const Password: Schema.filter<typeof Schema.Trim>
Password, confirm_password: Schema.filter<typeof Schema.Trim>
confirm_password: const Password: Schema.filter<typeof Schema.Trim>
Password}).Pipeable.pipe<Schema.Struct<{ password: Schema.filter<typeof Schema.Trim>; confirm_password: Schema.filter<typeof Schema.Trim>;}>, Schema.filter<Schema.Struct<{ password: Schema.filter<typeof Schema.Trim>; confirm_password: Schema.filter<typeof Schema.Trim>;}>>>(this: Schema.Struct<...>, ab: (_: Schema.Struct<{ password: Schema.filter<typeof Schema.Trim>; confirm_password: Schema.filter<typeof Schema.Trim>;}>) => Schema.filter<Schema.Struct<{ password: Schema.filter<typeof Schema.Trim>; confirm_password: Schema.filter<typeof Schema.Trim>;}>>): Schema.filter<...> (+21 overloads)
pipe( // 添加过滤器以确保密码匹配 import Schema
Schema.function filter<Schema.Struct<{ password: Schema.filter<typeof Schema.Trim>; confirm_password: Schema.filter<typeof Schema.Trim>;}>>(predicate: (a: { readonly password: string; readonly confirm_password: string;}, options: ParseOptions, self: Refinement) => FilterReturnType, annotations?: Schema.Annotations.Filter<{ readonly password: string; readonly confirm_password: string;}, { readonly password: string; readonly confirm_password: string;}> | 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) { // 返回与"confirm_password"字段关联的错误消息 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<{ readonly password: string; readonly confirm_password: string;}, ParseResult.ParseError>
decodeUnknownEither(const MyForm: Schema.filter<Schema.Struct<{ password: Schema.filter<typeof Schema.Trim>; confirm_password: Schema.filter<typeof Schema.Trim>;}>>
MyForm)({ password: string
password: "abc", confirm_password: string
confirm_password: "abd" // 确认密码不匹配 }).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<{ readonly password: string; readonly confirm_password: string;}, ParseResult.ParseError>) => Either.Either<{ readonly password: string; readonly confirm_password: string;}, ParseResult.ArrayFormatterIssue[]>): Either.Either<...> (+21 overloads)
pipe( import Either
Either.const mapLeft: <ParseResult.ParseError, ParseResult.ArrayFormatterIssue[]>(f: (left: ParseResult.ParseError) => ParseResult.ArrayFormatterIssue[]) => <R>(self: Either.Either<R, ParseResult.ParseError>) => Either.Either<R, ParseResult.ArrayFormatterIssue[]> (+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" } ]}*/在此示例中,我们定义了一个带有两个密码字段(password和confirm_password)的MyForm模式。我们使用Schema.filter来检查两个密码是否匹配。如果不匹配,将返回一个错误消息,特别与confirm_password字段关联。这使得更容易精确定位验证失败的位置。
错误使用ArrayFormatter以结构化方式格式化,便于后处理和与表单库集成。
Schema.filter API支持一次报告多个验证问题,这在表单验证等场景中特别有用,因为可能同时有多个检查失败。
示例(报告多个验证错误)
import { import Either
Either, import Schema
Schema, import ParseResult
ParseResult } from "effect"
const const Password: Schema.filter<typeof Schema.Trim>
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<typeof Schema.Trim>>(this: typeof Schema.Trim, ab: (_: typeof Schema.Trim) => Schema.filter<typeof Schema.Trim>): Schema.filter<typeof Schema.Trim> (+21 overloads)
pipe(import Schema
Schema.const minLength: <typeof Schema.Trim>(minLength: number, annotations?: Schema.Annotations.Filter<string, string> | undefined) => <A>(self: typeof Schema.Trim & Schema.Schema<A, string, never>) => Schema.filter<typeof Schema.Trim>
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<typeof Schema.Trim>; confirm_password: Schema.filter<typeof Schema.Trim>; name: Schema.optional<typeof Schema.String>; surname: Schema.optional<typeof Schema.String>;}>>
MyForm = import Schema
Schema.function Struct<{ password: Schema.filter<typeof Schema.Trim>; confirm_password: Schema.filter<typeof Schema.Trim>; name: Schema.optional<typeof Schema.String>; surname: Schema.optional<typeof Schema.String>;}>(fields: { password: Schema.filter<typeof Schema.Trim>; confirm_password: Schema.filter<typeof Schema.Trim>; name: Schema.optional<typeof Schema.String>; surname: Schema.optional<typeof Schema.String>;}): Schema.Struct<{ password: Schema.filter<typeof Schema.Trim>; confirm_password: Schema.filter<typeof Schema.Trim>; name: Schema.optional<typeof Schema.String>; surname: Schema.optional<typeof Schema.String>;}> (+1 overload)
Struct({ password: Schema.filter<typeof Schema.Trim>
password: const Password: Schema.filter<typeof Schema.Trim>
Password, confirm_password: Schema.filter<typeof Schema.Trim>
confirm_password: const Password: Schema.filter<typeof Schema.Trim>
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<typeof Schema.Trim>; confirm_password: Schema.filter<typeof Schema.Trim>; name: Schema.optional<typeof Schema.String>; surname: Schema.optional<typeof Schema.String>;}>, Schema.filter<Schema.Struct<{ password: Schema.filter<typeof Schema.Trim>; confirm_password: Schema.filter<typeof Schema.Trim>; name: Schema.optional<typeof Schema.String>; surname: Schema.optional<typeof Schema.String>;}>>>(this: Schema.Struct<...>, ab: (_: Schema.Struct<...>) => Schema.filter<...>): Schema.filter<...> (+21 overloads)
pipe( import Schema
Schema.function filter<Schema.Struct<{ password: Schema.filter<typeof Schema.Trim>; confirm_password: Schema.filter<typeof Schema.Trim>; name: Schema.optional<typeof Schema.String>; surname: Schema.optional<typeof Schema.String>;}>>(predicate: (a: { readonly password: string; readonly confirm_password: string; readonly name?: string | undefined; readonly surname?: string | undefined;}, 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> = []
// 检查密码是否匹配 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" }) }
// 确保姓名或姓氏至少存在一个 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<{ 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;}, never>, options?: ParseOptions) => (u: unknown, overrideOptions?: ParseOptions) => Either.Either<...>
decodeUnknownEither(const MyForm: Schema.filter<Schema.Struct<{ password: Schema.filter<typeof Schema.Trim>; confirm_password: Schema.filter<typeof Schema.Trim>; name: Schema.optional<typeof Schema.String>; surname: Schema.optional<typeof Schema.String>;}>>
MyForm)({ password: string
password: "abc", confirm_password: string
confirm_password: "abd" // 确认密码不匹配 }).Pipeable.pipe<Either.Either<{ readonly password: string; readonly confirm_password: string; readonly name?: string | undefined; readonly surname?: string | undefined;}, ParseResult.ParseError>, Either.Either<{ readonly password: string; readonly confirm_password: string; readonly name?: string | undefined; readonly surname?: string | undefined;}, ParseResult.ArrayFormatterIssue[]>>(this: Either.Either<...>, ab: (_: Either.Either<{ readonly password: string; readonly confirm_password: string; readonly name?: string | undefined; readonly surname?: string | undefined;}, ParseResult.ParseError>) => 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<R, ParseResult.ParseError>) => Either.Either<R, ParseResult.ArrayFormatterIssue[]> (+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" } ]}*/在此示例中,我们定义了一个MyForm模式,包含密码验证字段和可选的姓名/姓氏字段。Schema.filter函数检查密码是否匹配,并确保提供姓名或姓氏中的至少一个。如果任一验证失败,相应的错误消息将与相关字段关联,并以结构化格式返回两个错误。
对于带有过滤器的模式,您可以使用from属性访问基础模式(应用过滤器之前的模式):
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<typeof Schema.String> (+21 overloads)
pipe( import Schema
Schema.function filter<typeof Schema.String>(predicate: (a: string, options: ParseOptions, self: Refinement) => FilterReturnType, annotations?: Schema.Annotations.Filter<string, string> | undefined): (self: typeof Schema.String) => Schema.filter<typeof Schema.String> (+2 overloads)
filter((s: string
s) => s: string
s.String.length: number
Returns the length of a String object.
length >= 10))
// 访问基础模式,即应用过滤器之前的字符串模式//// ┌─── 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以下是Schema模块提供的有用字符串过滤器列表:
import { import Schema
Schema } from "effect"
// 指定字符串的最大长度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<typeof Schema.String> (+21 overloads)
pipe(import Schema
Schema.const maxLength: <typeof Schema.String>(maxLength: number, annotations?: Schema.Annotations.Filter<string, string> | undefined) => <A>(self: typeof Schema.String & Schema.Schema<A, string, never>) => Schema.filter<typeof Schema.String>
maxLength(5))
// 指定字符串的最小长度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<typeof Schema.String> (+21 overloads)
pipe(import Schema
Schema.const minLength: <typeof Schema.String>(minLength: number, annotations?: Schema.Annotations.Filter<string, string> | undefined) => <A>(self: typeof Schema.String & Schema.Schema<A, string, never>) => Schema.filter<typeof Schema.String>
minLength(5))
// 等同于minLength(1)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<typeof Schema.String> (+21 overloads)
pipe(import Schema
Schema.const nonEmptyString: <typeof Schema.String>(annotations?: Schema.Annotations.Filter<string, string> | undefined) => <A>(self: typeof Schema.String & Schema.Schema<A, string, never>) => Schema.filter<typeof Schema.String>
nonEmptyString())// orimport Schema
Schema.class NonEmptyString
NonEmptyString
// 指定字符串的确切长度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<typeof Schema.String> (+21 overloads)
pipe(import Schema
Schema.const length: <typeof Schema.String>(length: number | { readonly min: number; readonly max: number;}, annotations?: Schema.Annotations.Filter<string, string> | undefined) => <A>(self: typeof Schema.String & Schema.Schema<A, string, never>) => Schema.filter<typeof Schema.String>
length(5))
// 指定字符串长度的范围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<typeof Schema.String> (+21 overloads)
pipe(import Schema
Schema.const length: <typeof Schema.String>(length: number | { readonly min: number; readonly max: number;}, annotations?: Schema.Annotations.Filter<string, string> | undefined) => <A>(self: typeof Schema.String & Schema.Schema<A, string, never>) => Schema.filter<typeof Schema.String>
length({ min: number
min: 2, max: number
max: 4 }))
// 根据正则表达式模式匹配字符串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<typeof Schema.String> (+21 overloads)
pipe(import Schema
Schema.const pattern: <typeof Schema.String>(regex: RegExp, annotations?: Schema.Annotations.Filter<string, string> | undefined) => <A>(self: typeof Schema.String & Schema.Schema<A, string, never>) => Schema.filter<typeof Schema.String>
pattern(/^[a-z]+$/))
// 确保字符串以特定子字符串开头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<typeof Schema.String> (+21 overloads)
pipe(import Schema
Schema.const startsWith: <typeof Schema.String>(startsWith: string, annotations?: Schema.Annotations.Filter<string, string> | undefined) => <A>(self: typeof Schema.String & Schema.Schema<A, string, never>) => Schema.filter<typeof Schema.String>
startsWith("prefix"))
// 确保字符串以特定子字符串结尾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<typeof Schema.String> (+21 overloads)
pipe(import Schema
Schema.const endsWith: <typeof Schema.String>(endsWith: string, annotations?: Schema.Annotations.Filter<string, string> | undefined) => <A>(self: typeof Schema.String & Schema.Schema<A, string, never>) => Schema.filter<typeof Schema.String>
endsWith("suffix"))
// 检查字符串是否包含特定子字符串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<typeof Schema.String> (+21 overloads)
pipe(import Schema
Schema.const includes: <typeof Schema.String>(searchString: string, annotations?: Schema.Annotations.Filter<string, string> | undefined) => <A>(self: typeof Schema.String & Schema.Schema<A, string, never>) => Schema.filter<typeof Schema.String>
includes("substring"))
// 验证字符串没有前导或尾随空格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<typeof Schema.String> (+21 overloads)
pipe(import Schema
Schema.const trimmed: <typeof Schema.String>(annotations?: Schema.Annotations.Filter<string, string> | undefined) => <A>(self: typeof Schema.String & Schema.Schema<A, string, never>) => Schema.filter<typeof Schema.String>
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())
// 验证字符串完全是小写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<typeof Schema.String> (+21 overloads)
pipe(import Schema
Schema.const lowercased: <typeof Schema.String>(annotations?: Schema.Annotations.Filter<string, string> | undefined) => <A>(self: typeof Schema.String & Schema.Schema<A, string, never>) => Schema.filter<typeof Schema.String>
Verifies that a string is lowercased.
lowercased())
// 验证字符串完全是大写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<typeof Schema.String> (+21 overloads)
pipe(import Schema
Schema.const uppercased: <typeof Schema.String>(annotations?: Schema.Annotations.Filter<string, string> | undefined) => <A>(self: typeof Schema.String & Schema.Schema<A, string, never>) => Schema.filter<typeof Schema.String>
Verifies that a string is uppercased.
uppercased())
// 验证字符串是首字母大写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<typeof Schema.String> (+21 overloads)
pipe(import Schema
Schema.const capitalized: <typeof Schema.String>(annotations?: Schema.Annotations.Filter<string, string> | undefined) => <A>(self: typeof Schema.String & Schema.Schema<A, string, never>) => Schema.filter<typeof Schema.String>
Verifies that a string is capitalized.
capitalized())
// 验证字符串是首字母小写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<typeof Schema.String> (+21 overloads)
pipe(import Schema
Schema.const uncapitalized: <typeof Schema.String>(annotations?: Schema.Annotations.Filter<string, string> | undefined) => <A>(self: typeof Schema.String & Schema.Schema<A, string, never>) => Schema.filter<typeof Schema.String>
Verifies that a string is uncapitalized.
uncapitalized())以下是Schema模块提供的有用数字过滤器列表:
import { import Schema
Schema } from "effect"
// 指定大于5的数字import Schema
Schema.class Numberexport Number
Number.Pipeable.pipe<typeof Schema.Number, Schema.filter<typeof Schema.Number>>(this: typeof Schema.Number, ab: (_: typeof Schema.Number) => Schema.filter<typeof Schema.Number>): Schema.filter<typeof Schema.Number> (+21 overloads)
pipe(import Schema
Schema.const greaterThan: <typeof Schema.Number>(exclusiveMinimum: number, annotations?: Schema.Annotations.Filter<number, number> | undefined) => <A>(self: typeof Schema.Number & Schema.Schema<A, number, never>) => Schema.filter<typeof Schema.Number>
This filter checks whether the provided number is greater than the specified minimum.
greaterThan(5))
// 指定大于或等于5的数字import Schema
Schema.class Numberexport Number
Number.Pipeable.pipe<typeof Schema.Number, Schema.filter<typeof Schema.Number>>(this: typeof Schema.Number, ab: (_: typeof Schema.Number) => Schema.filter<typeof Schema.Number>): Schema.filter<typeof Schema.Number> (+21 overloads)
pipe(import Schema
Schema.const greaterThanOrEqualTo: <typeof Schema.Number>(minimum: number, annotations?: Schema.Annotations.Filter<number, number> | undefined) => <A>(self: typeof Schema.Number & Schema.Schema<A, number, never>) => Schema.filter<typeof Schema.Number>
This filter checks whether the provided number is greater than or equal to the specified minimum.
greaterThanOrEqualTo(5))
// 指定小于5的数字import Schema
Schema.class Numberexport Number
Number.Pipeable.pipe<typeof Schema.Number, Schema.filter<typeof Schema.Number>>(this: typeof Schema.Number, ab: (_: typeof Schema.Number) => Schema.filter<typeof Schema.Number>): Schema.filter<typeof Schema.Number> (+21 overloads)
pipe(import Schema
Schema.const lessThan: <typeof Schema.Number>(exclusiveMaximum: number, annotations?: Schema.Annotations.Filter<number, number> | undefined) => <A>(self: typeof Schema.Number & Schema.Schema<A, number, never>) => Schema.filter<typeof Schema.Number>
This filter checks whether the provided number is less than the specified maximum.
lessThan(5))
// 指定小于或等于5的数字import Schema
Schema.class Numberexport Number
Number.Pipeable.pipe<typeof Schema.Number, Schema.filter<typeof Schema.Number>>(this: typeof Schema.Number, ab: (_: typeof Schema.Number) => Schema.filter<typeof Schema.Number>): Schema.filter<typeof Schema.Number> (+21 overloads)
pipe(import Schema
Schema.const lessThanOrEqualTo: <typeof Schema.Number>(maximum: number, annotations?: Schema.Annotations.Filter<number, number> | undefined) => <A>(self: typeof Schema.Number & Schema.Schema<A, number, never>) => Schema.filter<typeof Schema.Number>
This schema checks whether the provided number is less than or equal to the specified maximum.
lessThanOrEqualTo(5))
// 指定-2到2之间的数字,包含边界import Schema
Schema.class Numberexport Number
Number.Pipeable.pipe<typeof Schema.Number, Schema.filter<typeof Schema.Number>>(this: typeof Schema.Number, ab: (_: typeof Schema.Number) => Schema.filter<typeof Schema.Number>): Schema.filter<typeof Schema.Number> (+21 overloads)
pipe(import Schema
Schema.const between: <typeof Schema.Number>(minimum: number, maximum: number, annotations?: Schema.Annotations.Filter<number, number> | undefined) => <A>(self: typeof Schema.Number & Schema.Schema<A, number, never>) => Schema.filter<typeof Schema.Number>
This filter checks whether the provided number falls within the specified minimum and maximum values.
between(-2, 2))
// 指定值必须是整数import Schema
Schema.class Numberexport Number
Number.Pipeable.pipe<typeof Schema.Number, Schema.filter<typeof Schema.Number>>(this: typeof Schema.Number, ab: (_: typeof Schema.Number) => Schema.filter<typeof Schema.Number>): Schema.filter<typeof Schema.Number> (+21 overloads)
pipe(import Schema
Schema.const int: <typeof Schema.Number>(annotations?: Schema.Annotations.Filter<number, number> | undefined) => <A>(self: typeof Schema.Number & Schema.Schema<A, number, never>) => Schema.filter<typeof Schema.Number>
Ensures that the provided value is an integer number (excluding NaN, +Infinity, and -Infinity).
int())// orimport Schema
Schema.class Int
Int
// 确保值不是NaNimport Schema
Schema.class Numberexport Number
Number.Pipeable.pipe<typeof Schema.Number, Schema.filter<typeof Schema.Number>>(this: typeof Schema.Number, ab: (_: typeof Schema.Number) => Schema.filter<typeof Schema.Number>): Schema.filter<typeof Schema.Number> (+21 overloads)
pipe(import Schema
Schema.const nonNaN: <typeof Schema.Number>(annotations?: Schema.Annotations.Filter<number, number> | undefined) => <A>(self: typeof Schema.Number & Schema.Schema<A, number, never>) => Schema.filter<typeof Schema.Number>
nonNaN())// orimport Schema
Schema.class NonNaN
NonNaN
// 确保提供的值是有限数字// (排除NaN、+Infinity和-Infinity)import Schema
Schema.class Numberexport Number
Number.Pipeable.pipe<typeof Schema.Number, Schema.filter<typeof Schema.Number>>(this: typeof Schema.Number, ab: (_: typeof Schema.Number) => Schema.filter<typeof Schema.Number>): Schema.filter<typeof Schema.Number> (+21 overloads)
pipe(import Schema
Schema.const finite: <typeof Schema.Number>(annotations?: Schema.Annotations.Filter<number, number> | undefined) => <A>(self: typeof Schema.Number & Schema.Schema<A, number, never>) => Schema.filter<typeof Schema.Number>
Ensures that the provided value is a finite number (excluding NaN, +Infinity, and -Infinity).
finite())// orimport Schema
Schema.class Finite
Finite
// 指定正数(> 0)import Schema
Schema.class Numberexport Number
Number.Pipeable.pipe<typeof Schema.Number, Schema.filter<typeof Schema.Number>>(this: typeof Schema.Number, ab: (_: typeof Schema.Number) => Schema.filter<typeof Schema.Number>): Schema.filter<typeof Schema.Number> (+21 overloads)
pipe(import Schema
Schema.const positive: <typeof Schema.Number>(annotations?: Schema.Annotations.Filter<number, number> | undefined) => <A>(self: typeof Schema.Number & Schema.Schema<A, number, never>) => Schema.filter<typeof Schema.Number>
positive())// orimport Schema
Schema.class Positive
Positive
// 指定非负数(>= 0)import Schema
Schema.class Numberexport Number
Number.Pipeable.pipe<typeof Schema.Number, Schema.filter<typeof Schema.Number>>(this: typeof Schema.Number, ab: (_: typeof Schema.Number) => Schema.filter<typeof Schema.Number>): Schema.filter<typeof Schema.Number> (+21 overloads)
pipe(import Schema
Schema.const nonNegative: <typeof Schema.Number>(annotations?: Schema.Annotations.Filter<number, number> | undefined) => <A>(self: typeof Schema.Number & Schema.Schema<A, number, never>) => Schema.filter<typeof Schema.Number>
nonNegative())// orimport Schema
Schema.class NonNegative
NonNegative
// 非负整数import Schema
Schema.const NonNegativeInt: Schema.refine<number, typeof Schema.NonNegative>
A non-negative integer. +Infinity is excluded.
NonNegativeInt
// 指定负数(< 0)import Schema
Schema.class Numberexport Number
Number.Pipeable.pipe<typeof Schema.Number, Schema.filter<typeof Schema.Number>>(this: typeof Schema.Number, ab: (_: typeof Schema.Number) => Schema.filter<typeof Schema.Number>): Schema.filter<typeof Schema.Number> (+21 overloads)
pipe(import Schema
Schema.const negative: <typeof Schema.Number>(annotations?: Schema.Annotations.Filter<number, number> | undefined) => <A>(self: typeof Schema.Number & Schema.Schema<A, number, never>) => Schema.filter<typeof Schema.Number>
negative())// orimport Schema
Schema.class Negative
Negative
// 指定非正数(<= 0)import Schema
Schema.class Numberexport Number
Number.Pipeable.pipe<typeof Schema.Number, Schema.filter<typeof Schema.Number>>(this: typeof Schema.Number, ab: (_: typeof Schema.Number) => Schema.filter<typeof Schema.Number>): Schema.filter<typeof Schema.Number> (+21 overloads)
pipe(import Schema
Schema.const nonPositive: <typeof Schema.Number>(annotations?: Schema.Annotations.Filter<number, number> | undefined) => <A>(self: typeof Schema.Number & Schema.Schema<A, number, never>) => Schema.filter<typeof Schema.Number>
nonPositive())// orimport Schema
Schema.class NonPositive
NonPositive
// 指定能被5整除的数字import Schema
Schema.class Numberexport Number
Number.Pipeable.pipe<typeof Schema.Number, Schema.filter<typeof Schema.Number>>(this: typeof Schema.Number, ab: (_: typeof Schema.Number) => Schema.filter<typeof Schema.Number>): Schema.filter<typeof Schema.Number> (+21 overloads)
pipe(import Schema
Schema.const multipleOf: <typeof Schema.Number>(divisor: number, annotations?: Schema.Annotations.Filter<number, number> | undefined) => <A>(self: typeof Schema.Number & Schema.Schema<A, number, never>) => Schema.filter<typeof Schema.Number>
multipleOf(5))
// 8位无符号整数(0到255)import Schema
Schema.class Uint8
Uint8以下是Schema模块提供的有用数组过滤器列表:
import { import Schema
Schema } from "effect"
// 指定数组中项目的最大数量import 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.Array$<typeof Schema.Number>>>(this: Schema.Array$<typeof Schema.Number>, ab: (_: Schema.Array$<typeof Schema.Number>) => Schema.filter<Schema.Array$<typeof Schema.Number>>): Schema.filter<Schema.Array$<typeof Schema.Number>> (+21 overloads)
pipe(import Schema
Schema.const maxItems: <Schema.Array$<typeof Schema.Number>>(n: number, annotations?: Schema.Annotations.Filter<readonly number[], readonly number[]> | undefined) => <A>(self: Schema.Array$<typeof Schema.Number> & Schema.Schema<A, readonly number[], never>) => Schema.filter<Schema.Array$<typeof Schema.Number>>
maxItems(2))
// 指定数组中项目的最小数量import 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.Array$<typeof Schema.Number>>>(this: Schema.Array$<typeof Schema.Number>, ab: (_: Schema.Array$<typeof Schema.Number>) => Schema.filter<Schema.Array$<typeof Schema.Number>>): Schema.filter<Schema.Array$<typeof Schema.Number>> (+21 overloads)
pipe(import Schema
Schema.const minItems: <Schema.Array$<typeof Schema.Number>>(n: number, annotations?: Schema.Annotations.Filter<readonly number[], readonly number[]> | undefined) => <A>(self: Schema.Array$<typeof Schema.Number> & Schema.Schema<A, readonly number[], never>) => Schema.filter<Schema.Array$<typeof Schema.Number>>
minItems(2))
// 指定数组中项目的确切数量import 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.Array$<typeof Schema.Number>>>(this: Schema.Array$<typeof Schema.Number>, ab: (_: Schema.Array$<typeof Schema.Number>) => Schema.filter<Schema.Array$<typeof Schema.Number>>): Schema.filter<Schema.Array$<typeof Schema.Number>> (+21 overloads)
pipe(import Schema
Schema.const itemsCount: <Schema.Array$<typeof Schema.Number>>(n: number, annotations?: Schema.Annotations.Filter<readonly number[], readonly number[]> | undefined) => <A>(self: Schema.Array$<typeof Schema.Number> & Schema.Schema<A, readonly number[], never>) => Schema.filter<Schema.Array$<typeof Schema.Number>>
itemsCount(2))import { import Schema
Schema } from "effect"
// 指定有效日期(拒绝像`new Date("Invalid Date")`这样的值)import Schema
Schema.class DateFromSelf
Describes a schema that accommodates potentially invalid Date instances,
such as new Date("Invalid Date"), without rejection.
DateFromSelf.Pipeable.pipe<typeof Schema.DateFromSelf, Schema.filter<typeof Schema.DateFromSelf>>(this: typeof Schema.DateFromSelf, ab: (_: typeof Schema.DateFromSelf) => Schema.filter<typeof Schema.DateFromSelf>): Schema.filter<typeof Schema.DateFromSelf> (+21 overloads)
pipe(import Schema
Schema.const validDate: <typeof Schema.DateFromSelf>(annotations?: Schema.Annotations.Filter<Date, Date> | undefined) => <A>(self: typeof Schema.DateFromSelf & Schema.Schema<A, Date, never>) => Schema.filter<typeof Schema.DateFromSelf>
Defines a filter that specifically rejects invalid dates, such as new Date("Invalid Date"). This filter ensures that only properly formatted and
valid date objects are accepted, enhancing data integrity by preventing
erroneous date values from being processed.
validDate())// orimport Schema
Schema.class ValidDateFromSelf
Defines a schema that ensures only valid dates are accepted. This schema
rejects values like new Date("Invalid Date"), which, despite being a Date
instance, represents an invalid date. Such stringent validation ensures that
all date objects processed through this schema are properly formed and
represent real dates.
ValidDateFromSelf
// 指定大于当前日期的日期import Schema
Schema.class Dateexport Date
This schema converts a string into a Date object using the new Date
constructor. It ensures that only valid date strings are accepted,
rejecting any strings that would result in an invalid date, such as new Date("Invalid Date").
Date.Pipeable.pipe<typeof Schema.Date, Schema.filter<typeof Schema.Date>>(this: typeof Schema.Date, ab: (_: typeof Schema.Date) => Schema.filter<typeof Schema.Date>): Schema.filter<typeof Schema.Date> (+21 overloads)
pipe(import Schema
Schema.const greaterThanDate: <typeof Schema.Date>(min: Date, annotations?: Schema.Annotations.Filter<Date, Date> | undefined) => <A>(self: typeof Schema.Date & Schema.Schema<A, string, never>) => Schema.filter<typeof Schema.Date>
greaterThanDate(new var Date: DateConstructornew () => Date (+3 overloads)
Date()))
// 指定大于或等于当前日期的日期import Schema
Schema.class Dateexport Date
This schema converts a string into a Date object using the new Date
constructor. It ensures that only valid date strings are accepted,
rejecting any strings that would result in an invalid date, such as new Date("Invalid Date").
Date.Pipeable.pipe<typeof Schema.Date, Schema.filter<typeof Schema.Date>>(this: typeof Schema.Date, ab: (_: typeof Schema.Date) => Schema.filter<typeof Schema.Date>): Schema.filter<typeof Schema.Date> (+21 overloads)
pipe(import Schema
Schema.const greaterThanOrEqualToDate: <typeof Schema.Date>(min: Date, annotations?: Schema.Annotations.Filter<Date, Date> | undefined) => <A>(self: typeof Schema.Date & Schema.Schema<A, string, never>) => Schema.filter<typeof Schema.Date>
greaterThanOrEqualToDate(new var Date: DateConstructornew () => Date (+3 overloads)
Date()))
// 指定小于当前日期的日期import Schema
Schema.class Dateexport Date
This schema converts a string into a Date object using the new Date
constructor. It ensures that only valid date strings are accepted,
rejecting any strings that would result in an invalid date, such as new Date("Invalid Date").
Date.Pipeable.pipe<typeof Schema.Date, Schema.filter<typeof Schema.Date>>(this: typeof Schema.Date, ab: (_: typeof Schema.Date) => Schema.filter<typeof Schema.Date>): Schema.filter<typeof Schema.Date> (+21 overloads)
pipe(import Schema
Schema.const lessThanDate: <typeof Schema.Date>(max: Date, annotations?: Schema.Annotations.Filter<Date, Date> | undefined) => <A>(self: typeof Schema.Date & Schema.Schema<A, string, never>) => Schema.filter<typeof Schema.Date>
lessThanDate(new var Date: DateConstructornew () => Date (+3 overloads)
Date()))
// 指定小于或等于当前日期的日期import Schema
Schema.class Dateexport Date
This schema converts a string into a Date object using the new Date
constructor. It ensures that only valid date strings are accepted,
rejecting any strings that would result in an invalid date, such as new Date("Invalid Date").
Date.Pipeable.pipe<typeof Schema.Date, Schema.filter<typeof Schema.Date>>(this: typeof Schema.Date, ab: (_: typeof Schema.Date) => Schema.filter<typeof Schema.Date>): Schema.filter<typeof Schema.Date> (+21 overloads)
pipe(import Schema
Schema.const lessThanOrEqualToDate: <typeof Schema.Date>(max: Date, annotations?: Schema.Annotations.Filter<Date, Date> | undefined) => <A>(self: typeof Schema.Date & Schema.Schema<A, string, never>) => Schema.filter<typeof Schema.Date>
lessThanOrEqualToDate(new var Date: DateConstructornew () => Date (+3 overloads)
Date()))
// 指定两个日期之间的日期import Schema
Schema.class Dateexport Date
This schema converts a string into a Date object using the new Date
constructor. It ensures that only valid date strings are accepted,
rejecting any strings that would result in an invalid date, such as new Date("Invalid Date").
Date.Pipeable.pipe<typeof Schema.Date, Schema.filter<typeof Schema.Date>>(this: typeof Schema.Date, ab: (_: typeof Schema.Date) => Schema.filter<typeof Schema.Date>): Schema.filter<typeof Schema.Date> (+21 overloads)
pipe(import Schema
Schema.const betweenDate: <typeof Schema.Date>(min: Date, max: Date, annotations?: Schema.Annotations.Filter<Date, Date> | undefined) => <A>(self: typeof Schema.Date & Schema.Schema<A, string, never>) => Schema.filter<typeof Schema.Date>
betweenDate(new var Date: DateConstructornew (value: number | string | Date) => Date (+3 overloads)
Date(0), new var Date: DateConstructornew () => Date (+3 overloads)
Date()))以下是Schema模块提供的有用BigInt过滤器列表:
import { import Schema
Schema } from "effect"
// 指定大于5的BigIntimport 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<typeof Schema.BigInt>>(this: typeof Schema.BigInt, ab: (_: typeof Schema.BigInt) => Schema.filter<typeof Schema.BigInt>): Schema.filter<typeof Schema.BigInt> (+21 overloads)
pipe(import Schema
Schema.const greaterThanBigInt: <typeof Schema.BigInt>(min: bigint, annotations?: Schema.Annotations.Filter<bigint, bigint> | undefined) => <A>(self: typeof Schema.BigInt & Schema.Schema<A, string, never>) => Schema.filter<typeof Schema.BigInt>
greaterThanBigInt(5n))
// 指定大于或等于5的BigIntimport 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<typeof Schema.BigInt>>(this: typeof Schema.BigInt, ab: (_: typeof Schema.BigInt) => Schema.filter<typeof Schema.BigInt>): Schema.filter<typeof Schema.BigInt> (+21 overloads)
pipe(import Schema
Schema.const greaterThanOrEqualToBigInt: <typeof Schema.BigInt>(min: bigint, annotations?: Schema.Annotations.Filter<bigint, bigint> | undefined) => <A>(self: typeof Schema.BigInt & Schema.Schema<A, string, never>) => Schema.filter<typeof Schema.BigInt>
greaterThanOrEqualToBigInt(5n))
// 指定小于5的BigIntimport 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<typeof Schema.BigInt>>(this: typeof Schema.BigInt, ab: (_: typeof Schema.BigInt) => Schema.filter<typeof Schema.BigInt>): Schema.filter<typeof Schema.BigInt> (+21 overloads)
pipe(import Schema
Schema.const lessThanBigInt: <typeof Schema.BigInt>(max: bigint, annotations?: Schema.Annotations.Filter<bigint, bigint> | undefined) => <A>(self: typeof Schema.BigInt & Schema.Schema<A, string, never>) => Schema.filter<typeof Schema.BigInt>
lessThanBigInt(5n))
// 指定小于或等于5的BigIntimport 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<typeof Schema.BigInt>>(this: typeof Schema.BigInt, ab: (_: typeof Schema.BigInt) => Schema.filter<typeof Schema.BigInt>): Schema.filter<typeof Schema.BigInt> (+21 overloads)
pipe(import Schema
Schema.const lessThanOrEqualToBigInt: <typeof Schema.BigInt>(max: bigint, annotations?: Schema.Annotations.Filter<bigint, bigint> | undefined) => <A>(self: typeof Schema.BigInt & Schema.Schema<A, string, never>) => Schema.filter<typeof Schema.BigInt>
lessThanOrEqualToBigInt(5n))
// 指定-2n到2n之间的BigInt,包含边界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<typeof Schema.BigInt>>(this: typeof Schema.BigInt, ab: (_: typeof Schema.BigInt) => Schema.filter<typeof Schema.BigInt>): Schema.filter<typeof Schema.BigInt> (+21 overloads)
pipe(import Schema
Schema.const betweenBigInt: <typeof Schema.BigInt>(min: bigint, max: bigint, annotations?: Schema.Annotations.Filter<bigint, bigint> | undefined) => <A>(self: typeof Schema.BigInt & Schema.Schema<A, string, never>) => Schema.filter<typeof Schema.BigInt>
betweenBigInt(-2n, 2n))
// 指定正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<typeof Schema.BigInt>>(this: typeof Schema.BigInt, ab: (_: typeof Schema.BigInt) => Schema.filter<typeof Schema.BigInt>): Schema.filter<typeof Schema.BigInt> (+21 overloads)
pipe(import Schema
Schema.const positiveBigInt: <typeof Schema.BigInt>(annotations?: Schema.Annotations.Filter<bigint, bigint> | undefined) => <A>(self: typeof Schema.BigInt & Schema.Schema<A, string, never>) => Schema.filter<typeof Schema.BigInt>
positiveBigInt())// orimport Schema
Schema.const PositiveBigIntFromSelf: Schema.filter<Schema.Schema<bigint, bigint, never>>
PositiveBigIntFromSelf
// 指定非负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<typeof Schema.BigInt>>(this: typeof Schema.BigInt, ab: (_: typeof Schema.BigInt) => Schema.filter<typeof Schema.BigInt>): Schema.filter<typeof Schema.BigInt> (+21 overloads)
pipe(import Schema
Schema.const nonNegativeBigInt: <typeof Schema.BigInt>(annotations?: Schema.Annotations.Filter<bigint, bigint> | undefined) => <A>(self: typeof Schema.BigInt & Schema.Schema<A, string, never>) => Schema.filter<typeof Schema.BigInt>
nonNegativeBigInt())// orimport Schema
Schema.const NonNegativeBigIntFromSelf: Schema.filter<Schema.Schema<bigint, bigint, never>>
NonNegativeBigIntFromSelf
// 指定负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<typeof Schema.BigInt>>(this: typeof Schema.BigInt, ab: (_: typeof Schema.BigInt) => Schema.filter<typeof Schema.BigInt>): Schema.filter<typeof Schema.BigInt> (+21 overloads)
pipe(import Schema
Schema.const negativeBigInt: <typeof Schema.BigInt>(annotations?: Schema.Annotations.Filter<bigint, bigint> | undefined) => <A>(self: typeof Schema.BigInt & Schema.Schema<A, string, never>) => Schema.filter<typeof Schema.BigInt>
negativeBigInt())// orimport Schema
Schema.const NegativeBigIntFromSelf: Schema.filter<Schema.Schema<bigint, bigint, never>>
NegativeBigIntFromSelf
// 指定非正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<typeof Schema.BigInt>>(this: typeof Schema.BigInt, ab: (_: typeof Schema.BigInt) => Schema.filter<typeof Schema.BigInt>): Schema.filter<typeof Schema.BigInt> (+21 overloads)
pipe(import Schema
Schema.const nonPositiveBigInt: <typeof Schema.BigInt>(annotations?: Schema.Annotations.Filter<bigint, bigint> | undefined) => <A>(self: typeof Schema.BigInt & Schema.Schema<A, string, never>) => Schema.filter<typeof Schema.BigInt>
nonPositiveBigInt())// orimport Schema
Schema.const NonPositiveBigIntFromSelf: Schema.filter<Schema.Schema<bigint, bigint, never>>
NonPositiveBigIntFromSelf以下是Schema模块提供的有用BigDecimal过滤器列表:
import { import Schema
Schema, import BigDecimal
BigDecimal } from "effect"
// 指定大于5的BigDecimalimport Schema
Schema.class BigDecimal
BigDecimal.Pipeable.pipe<typeof Schema.BigDecimal, Schema.filter<typeof Schema.BigDecimal>>(this: typeof Schema.BigDecimal, ab: (_: typeof Schema.BigDecimal) => Schema.filter<typeof Schema.BigDecimal>): Schema.filter<typeof Schema.BigDecimal> (+21 overloads)
pipe( import Schema
Schema.const greaterThanBigDecimal: <typeof Schema.BigDecimal>(min: BigDecimal.BigDecimal, annotations?: Schema.Annotations.Filter<BigDecimal.BigDecimal, BigDecimal.BigDecimal> | undefined) => <A>(self: typeof Schema.BigDecimal & Schema.Schema<A, string, never>) => Schema.filter<typeof Schema.BigDecimal>
greaterThanBigDecimal(import BigDecimal
BigDecimal.const unsafeFromNumber: (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).
unsafeFromNumber(5)))
// 指定大于或等于5的BigDecimalimport Schema
Schema.class BigDecimal
BigDecimal.Pipeable.pipe<typeof Schema.BigDecimal, Schema.filter<typeof Schema.BigDecimal>>(this: typeof Schema.BigDecimal, ab: (_: typeof Schema.BigDecimal) => Schema.filter<typeof Schema.BigDecimal>): Schema.filter<typeof Schema.BigDecimal> (+21 overloads)
pipe( import Schema
Schema.const greaterThanOrEqualToBigDecimal: <typeof Schema.BigDecimal>(min: BigDecimal.BigDecimal, annotations?: Schema.Annotations.Filter<BigDecimal.BigDecimal, BigDecimal.BigDecimal> | undefined) => <A>(self: typeof Schema.BigDecimal & Schema.Schema<A, string, never>) => Schema.filter<typeof Schema.BigDecimal>
greaterThanOrEqualToBigDecimal(import BigDecimal
BigDecimal.const unsafeFromNumber: (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).
unsafeFromNumber(5)))// 指定小于5的BigDecimalimport Schema
Schema.class BigDecimal
BigDecimal.Pipeable.pipe<typeof Schema.BigDecimal, Schema.filter<typeof Schema.BigDecimal>>(this: typeof Schema.BigDecimal, ab: (_: typeof Schema.BigDecimal) => Schema.filter<typeof Schema.BigDecimal>): Schema.filter<typeof Schema.BigDecimal> (+21 overloads)
pipe( import Schema
Schema.const lessThanBigDecimal: <typeof Schema.BigDecimal>(max: BigDecimal.BigDecimal, annotations?: Schema.Annotations.Filter<BigDecimal.BigDecimal, BigDecimal.BigDecimal> | undefined) => <A>(self: typeof Schema.BigDecimal & Schema.Schema<A, string, never>) => Schema.filter<typeof Schema.BigDecimal>
lessThanBigDecimal(import BigDecimal
BigDecimal.const unsafeFromNumber: (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).
unsafeFromNumber(5)))
// 指定小于或等于5的BigDecimalimport Schema
Schema.class BigDecimal
BigDecimal.Pipeable.pipe<typeof Schema.BigDecimal, Schema.filter<typeof Schema.BigDecimal>>(this: typeof Schema.BigDecimal, ab: (_: typeof Schema.BigDecimal) => Schema.filter<typeof Schema.BigDecimal>): Schema.filter<typeof Schema.BigDecimal> (+21 overloads)
pipe( import Schema
Schema.const lessThanOrEqualToBigDecimal: <typeof Schema.BigDecimal>(max: BigDecimal.BigDecimal, annotations?: Schema.Annotations.Filter<BigDecimal.BigDecimal, BigDecimal.BigDecimal> | undefined) => <A>(self: typeof Schema.BigDecimal & Schema.Schema<A, string, never>) => Schema.filter<typeof Schema.BigDecimal>
lessThanOrEqualToBigDecimal(import BigDecimal
BigDecimal.const unsafeFromNumber: (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).
unsafeFromNumber(5)))
// 指定-2到2之间的BigDecimal,包含边界import Schema
Schema.class BigDecimal
BigDecimal.Pipeable.pipe<typeof Schema.BigDecimal, Schema.filter<typeof Schema.BigDecimal>>(this: typeof Schema.BigDecimal, ab: (_: typeof Schema.BigDecimal) => Schema.filter<typeof Schema.BigDecimal>): Schema.filter<typeof Schema.BigDecimal> (+21 overloads)
pipe( import Schema
Schema.const betweenBigDecimal: <typeof Schema.BigDecimal>(minimum: BigDecimal.BigDecimal, maximum: BigDecimal.BigDecimal, annotations?: Schema.Annotations.Filter<BigDecimal.BigDecimal, BigDecimal.BigDecimal> | undefined) => <A>(self: typeof Schema.BigDecimal & Schema.Schema<A, string, never>) => Schema.filter<typeof Schema.BigDecimal>
betweenBigDecimal( import BigDecimal
BigDecimal.const unsafeFromNumber: (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).
unsafeFromNumber(-2), import BigDecimal
BigDecimal.const unsafeFromNumber: (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).
unsafeFromNumber(2) ))
// 指定正BigDecimal(> 0)import Schema
Schema.class BigDecimal
BigDecimal.Pipeable.pipe<typeof Schema.BigDecimal, Schema.filter<typeof Schema.BigDecimal>>(this: typeof Schema.BigDecimal, ab: (_: typeof Schema.BigDecimal) => Schema.filter<typeof Schema.BigDecimal>): Schema.filter<typeof Schema.BigDecimal> (+21 overloads)
pipe(import Schema
Schema.const positiveBigDecimal: <typeof Schema.BigDecimal>(annotations?: Schema.Annotations.Filter<BigDecimal.BigDecimal, BigDecimal.BigDecimal> | undefined) => <A>(self: typeof Schema.BigDecimal & Schema.Schema<A, string, never>) => Schema.filter<typeof Schema.BigDecimal>
positiveBigDecimal())
// 指定非负BigDecimal(>= 0)import Schema
Schema.class BigDecimal
BigDecimal.Pipeable.pipe<typeof Schema.BigDecimal, Schema.filter<typeof Schema.BigDecimal>>(this: typeof Schema.BigDecimal, ab: (_: typeof Schema.BigDecimal) => Schema.filter<typeof Schema.BigDecimal>): Schema.filter<typeof Schema.BigDecimal> (+21 overloads)
pipe(import Schema
Schema.const nonNegativeBigDecimal: <typeof Schema.BigDecimal>(annotations?: Schema.Annotations.Filter<BigDecimal.BigDecimal, BigDecimal.BigDecimal> | undefined) => <A>(self: typeof Schema.BigDecimal & Schema.Schema<A, string, never>) => Schema.filter<typeof Schema.BigDecimal>
nonNegativeBigDecimal())
// 指定负BigDecimal(< 0)import Schema
Schema.class BigDecimal
BigDecimal.Pipeable.pipe<typeof Schema.BigDecimal, Schema.filter<typeof Schema.BigDecimal>>(this: typeof Schema.BigDecimal, ab: (_: typeof Schema.BigDecimal) => Schema.filter<typeof Schema.BigDecimal>): Schema.filter<typeof Schema.BigDecimal> (+21 overloads)
pipe(import Schema
Schema.const negativeBigDecimal: <typeof Schema.BigDecimal>(annotations?: Schema.Annotations.Filter<BigDecimal.BigDecimal, BigDecimal.BigDecimal> | undefined) => <A>(self: typeof Schema.BigDecimal & Schema.Schema<A, string, never>) => Schema.filter<typeof Schema.BigDecimal>
negativeBigDecimal())
// 指定非正BigDecimal(<= 0)import Schema
Schema.class BigDecimal
BigDecimal.Pipeable.pipe<typeof Schema.BigDecimal, Schema.filter<typeof Schema.BigDecimal>>(this: typeof Schema.BigDecimal, ab: (_: typeof Schema.BigDecimal) => Schema.filter<typeof Schema.BigDecimal>): Schema.filter<typeof Schema.BigDecimal> (+21 overloads)
pipe(import Schema
Schema.const nonPositiveBigDecimal: <typeof Schema.BigDecimal>(annotations?: Schema.Annotations.Filter<BigDecimal.BigDecimal, BigDecimal.BigDecimal> | undefined) => <A>(self: typeof Schema.BigDecimal & Schema.Schema<A, string, never>) => Schema.filter<typeof Schema.BigDecimal>
nonPositiveBigDecimal())以下是Schema模块提供的有用持续时间过滤器列表:
import { import Schema
Schema } from "effect"
// 指定大于5秒的持续时间import Schema
Schema.class Duration
A schema that converts a JSON-compatible tagged union into a Duration.
Duration.Pipeable.pipe<typeof Schema.Duration, Schema.filter<typeof Schema.Duration>>(this: typeof Schema.Duration, ab: (_: typeof Schema.Duration) => Schema.filter<typeof Schema.Duration>): Schema.filter<typeof Schema.Duration> (+21 overloads)
pipe(import Schema
Schema.const greaterThanDuration: <typeof Schema.Duration>(min: DurationInput, annotations?: Schema.Annotations.Filter<Duration, Duration> | undefined) => <A>(self: typeof Schema.Duration & Schema.Schema<A, Schema.DurationEncoded | readonly [seconds: number, nanos: number], never>) => Schema.filter<typeof Schema.Duration>
greaterThanDuration("5 seconds"))
// 指定大于或等于5秒的持续时间import Schema
Schema.class Duration
A schema that converts a JSON-compatible tagged union into a Duration.
Duration.Pipeable.pipe<typeof Schema.Duration, Schema.filter<typeof Schema.Duration>>(this: typeof Schema.Duration, ab: (_: typeof Schema.Duration) => Schema.filter<typeof Schema.Duration>): Schema.filter<typeof Schema.Duration> (+21 overloads)
pipe(import Schema
Schema.const greaterThanOrEqualToDuration: <typeof Schema.Duration>(min: DurationInput, annotations?: Schema.Annotations.Filter<Duration, Duration> | undefined) => <A>(self: typeof Schema.Duration & Schema.Schema<A, Schema.DurationEncoded | readonly [seconds: number, nanos: number], never>) => Schema.filter<typeof Schema.Duration>
greaterThanOrEqualToDuration("5 seconds"))
// 指定小于5秒的持续时间import Schema
Schema.class Duration
A schema that converts a JSON-compatible tagged union into a Duration.
Duration.Pipeable.pipe<typeof Schema.Duration, Schema.filter<typeof Schema.Duration>>(this: typeof Schema.Duration, ab: (_: typeof Schema.Duration) => Schema.filter<typeof Schema.Duration>): Schema.filter<typeof Schema.Duration> (+21 overloads)
pipe(import Schema
Schema.const lessThanDuration: <typeof Schema.Duration>(max: DurationInput, annotations?: Schema.Annotations.Filter<Duration, Duration> | undefined) => <A>(self: typeof Schema.Duration & Schema.Schema<A, Schema.DurationEncoded | readonly [seconds: number, nanos: number], never>) => Schema.filter<typeof Schema.Duration>
lessThanDuration("5 seconds"))
// 指定小于或等于5秒的持续时间import Schema
Schema.class Duration
A schema that converts a JSON-compatible tagged union into a Duration.
Duration.Pipeable.pipe<typeof Schema.Duration, Schema.filter<typeof Schema.Duration>>(this: typeof Schema.Duration, ab: (_: typeof Schema.Duration) => Schema.filter<typeof Schema.Duration>): Schema.filter<typeof Schema.Duration> (+21 overloads)
pipe(import Schema
Schema.const lessThanOrEqualToDuration: <typeof Schema.Duration>(max: DurationInput, annotations?: Schema.Annotations.Filter<Duration, Duration> | undefined) => <A>(self: typeof Schema.Duration & Schema.Schema<A, Schema.DurationEncoded | readonly [seconds: number, nanos: number], never>) => Schema.filter<typeof Schema.Duration>
lessThanOrEqualToDuration("5 seconds"))
// 指定5秒到10秒之间的持续时间,包含边界import Schema
Schema.class Duration
A schema that converts a JSON-compatible tagged union into a Duration.
Duration.Pipeable.pipe<typeof Schema.Duration, Schema.filter<typeof Schema.Duration>>(this: typeof Schema.Duration, ab: (_: typeof Schema.Duration) => Schema.filter<typeof Schema.Duration>): Schema.filter<typeof Schema.Duration> (+21 overloads)
pipe(import Schema
Schema.const betweenDuration: <typeof Schema.Duration>(minimum: DurationInput, maximum: DurationInput, annotations?: Schema.Annotations.Filter<Duration, Duration> | undefined) => <A>(self: typeof Schema.Duration & Schema.Schema<A, Schema.DurationEncoded | readonly [seconds: number, nanos: number], never>) => Schema.filter<typeof Schema.Duration>
betweenDuration("5 seconds", "10 seconds"))