Skip to content

过滤器

开发人员可以定义超越基本类型检查的自定义验证逻辑,从而更好地控制数据验证方式。

过滤器使用 Schema.filter 函数声明。此函数需要两个参数:要验证的模式和谓词函数。谓词函数是用户定义的,用于确定数据是否满足条件。如果数据验证失败,可以提供错误消息。

示例(定义最小字符串长度过滤器)

import {
import Schema
Schema
} from "effect"
// 定义一个带有过滤器的字符串模式,以确保字符串
// 至少有 10 个字符长
const
const LongString: Schema.filter<typeof Schema.String>
LongString
=
import Schema
Schema
.
class String
export String

@since3.10.0

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)

@since3.10.0

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 stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.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 out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.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

@seesource

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 stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
import Schema
Schema
.
decodeUnknownSync<string, string>(schema: Schema.Schema<string, string, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => string
export decodeUnknownSync

@throwsParseError

@since3.10.0

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>

过滤器的谓词可以返回几种类型的值,每种都以不同的方式影响验证:

返回类型行为
trueundefined数据满足过滤器的条件并通过验证。
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 String
export String

@since3.10.0

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)

@since3.10.0

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 stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.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 out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.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

@seesource

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 stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

log
(
import Schema
Schema
.
decodeUnknownSync<string, string>(schema: Schema.Schema<string, string, never>, options?: ParseOptions): (u: unknown, overrideOptions?: ParseOptions) => string
export decodeUnknownSync

@throwsParseError

@since3.10.0

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 stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.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 out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.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

@seesource

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 stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

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.

@paramvalue A JavaScript value, usually an object or array, to be converted.

@paramreplacer An array of strings and numbers that acts as an approved list for selecting the object properties that will be stringified.

@paramspace Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.

@throws{TypeError} If a circular reference or a BigInt value is found.

stringify
(
import JSONSchema
JSONSchema
.
const make: <string, string, never>(schema: Schema.Schema<string, string, never>) => JSONSchema.JsonSchema7Root

@since3.10.0

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

@since2.0.0

@since2.0.0

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.

@since3.10.0

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>

@since3.10.0

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)

@since3.10.0

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)

@since3.10.0

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 stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.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 out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.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

@seesource

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 stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

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.

@paramvalue A JavaScript value, usually an object or array, to be converted.

@paramreplacer An array of strings and numbers that acts as an approved list for selecting the object properties that will be stringified.

@paramspace Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.

@throws{TypeError} If a circular reference or a BigInt value is found.

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>

@since3.10.0

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

@since2.0.0

@since2.0.0

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.

@since2.0.0

mapLeft
((
error: ParseResult.ParseError
error
) =>
import ParseResult
ParseResult
.
const ArrayFormatter: ParseResult.ParseResultFormatter<ParseResult.ArrayFormatterIssue[]>

@since3.10.0

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"
}
]
}
*/

在此示例中,我们定义了一个带有两个密码字段(passwordconfirm_password)的MyForm模式。我们使用Schema.filter来检查两个密码是否匹配。如果不匹配,将返回一个错误消息,特别与confirm_password字段关联。这使得更容易精确定位验证失败的位置。

错误使用ArrayFormatter以结构化方式格式化,便于后处理和与表单库集成。

Schema.filter API支持一次报告多个验证问题,这在表单验证等场景中特别有用,因为可能同时有多个检查失败。

示例(报告多个验证错误)

import {
import Either

@since2.0.0

@since2.0.0

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.

@since3.10.0

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>

@since3.10.0

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>

@since3.10.0

optional
(
import Schema
Schema
.
class String
export String

@since3.10.0

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)

@since3.10.0

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)

@since3.10.0

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

@since3.10.0

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.

@paramitems New elements to add to 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.

@paramitems New elements to add to 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 stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.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 out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.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

@seesource

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 stdout
console.log('count:', count);
// Prints: count: 5, to stdout

See util.format() for more information.

@sincev0.1.100

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.

@paramvalue A JavaScript value, usually an object or array, to be converted.

@paramreplacer An array of strings and numbers that acts as an approved list for selecting the object properties that will be stringified.

@paramspace Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.

@throws{TypeError} If a circular reference or a BigInt value is found.

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<...>

@since3.10.0

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

@since2.0.0

@since2.0.0

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.

@since2.0.0

mapLeft
((
error: ParseResult.ParseError
error
) =>
import ParseResult
ParseResult
.
const ArrayFormatter: ParseResult.ParseResultFormatter<ParseResult.ArrayFormatterIssue[]>

@since3.10.0

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 String
export String

@since3.10.0

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)

@since3.10.0

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 String
export String

@since3.10.0

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>

@since3.10.0

maxLength
(5))
// 指定字符串的最小长度
import Schema
Schema
.
class String
export String

@since3.10.0

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>

@since3.10.0

minLength
(5))
// 等同于minLength(1)
import Schema
Schema
.
class String
export String

@since3.10.0

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>

@since3.10.0

nonEmptyString
())
// or
import Schema
Schema
.
class NonEmptyString

@since3.10.0

NonEmptyString
// 指定字符串的确切长度
import Schema
Schema
.
class String
export String

@since3.10.0

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>

@since3.10.0

length
(5))
// 指定字符串长度的范围
import Schema
Schema
.
class String
export String

@since3.10.0

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>

@since3.10.0

length
({
min: number
min
: 2,
max: number
max
: 4 }))
// 根据正则表达式模式匹配字符串
import Schema
Schema
.
class String
export String

@since3.10.0

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>

@since3.10.0

pattern
(/^[a-z]+$/))
// 确保字符串以特定子字符串开头
import Schema
Schema
.
class String
export String

@since3.10.0

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>

@since3.10.0

startsWith
("prefix"))
// 确保字符串以特定子字符串结尾
import Schema
Schema
.
class String
export String

@since3.10.0

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>

@since3.10.0

endsWith
("suffix"))
// 检查字符串是否包含特定子字符串
import Schema
Schema
.
class String
export String

@since3.10.0

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>

@since3.10.0

includes
("substring"))
// 验证字符串没有前导或尾随空格
import Schema
Schema
.
class String
export String

@since3.10.0

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.

@since3.10.0

trimmed
())
// 验证字符串完全是小写
import Schema
Schema
.
class String
export String

@since3.10.0

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.

@since3.10.0

lowercased
())
// 验证字符串完全是大写
import Schema
Schema
.
class String
export String

@since3.10.0

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.

@since3.10.0

uppercased
())
// 验证字符串是首字母大写
import Schema
Schema
.
class String
export String

@since3.10.0

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.

@since3.10.0

capitalized
())
// 验证字符串是首字母小写
import Schema
Schema
.
class String
export String

@since3.10.0

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.

@since3.10.0

uncapitalized
())

以下是Schema模块提供的有用数字过滤器列表:

import {
import Schema
Schema
} from "effect"
// 指定大于5的数字
import Schema
Schema
.
class Number
export Number

@since3.10.0

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.

@since3.10.0

greaterThan
(5))
// 指定大于或等于5的数字
import Schema
Schema
.
class Number
export Number

@since3.10.0

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.

@since3.10.0

greaterThanOrEqualTo
(5))
// 指定小于5的数字
import Schema
Schema
.
class Number
export Number

@since3.10.0

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.

@since3.10.0

lessThan
(5))
// 指定小于或等于5的数字
import Schema
Schema
.
class Number
export Number

@since3.10.0

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.

@since3.10.0

lessThanOrEqualTo
(5))
// 指定-2到2之间的数字,包含边界
import Schema
Schema
.
class Number
export Number

@since3.10.0

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.

@since3.10.0

between
(-2, 2))
// 指定值必须是整数
import Schema
Schema
.
class Number
export Number

@since3.10.0

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).

@since3.10.0

int
())
// or
import Schema
Schema
.
class Int

@since3.10.0

Int
// 确保值不是NaN
import Schema
Schema
.
class Number
export Number

@since3.10.0

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>

@since3.10.0

nonNaN
())
// or
import Schema
Schema
.
class NonNaN

@since3.10.0

NonNaN
// 确保提供的值是有限数字
// (排除NaN、+Infinity和-Infinity)
import Schema
Schema
.
class Number
export Number

@since3.10.0

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).

@since3.10.0

finite
())
// or
import Schema
Schema
.
class Finite

@since3.10.0

Finite
// 指定正数(> 0)
import Schema
Schema
.
class Number
export Number

@since3.10.0

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>

@since3.10.0

positive
())
// or
import Schema
Schema
.
class Positive

@since3.10.0

Positive
// 指定非负数(>= 0)
import Schema
Schema
.
class Number
export Number

@since3.10.0

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>

@since3.10.0

nonNegative
())
// or
import Schema
Schema
.
class NonNegative

@since3.10.0

NonNegative
// 非负整数
import Schema
Schema
.
const NonNegativeInt: Schema.refine<number, typeof Schema.NonNegative>

A non-negative integer. +Infinity is excluded.

@since3.11.10

NonNegativeInt
// 指定负数(< 0)
import Schema
Schema
.
class Number
export Number

@since3.10.0

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>

@since3.10.0

negative
())
// or
import Schema
Schema
.
class Negative

@since3.10.0

Negative
// 指定非正数(<= 0)
import Schema
Schema
.
class Number
export Number

@since3.10.0

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>

@since3.10.0

nonPositive
())
// or
import Schema
Schema
.
class NonPositive

@since3.10.0

NonPositive
// 指定能被5整除的数字
import Schema
Schema
.
class Number
export Number

@since3.10.0

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>

@since3.10.0

multipleOf
(5))
// 8位无符号整数(0到255)
import Schema
Schema
.
class Uint8

@since3.11.10

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

@since3.10.0

Array
(
import Schema
Schema
.
class Number
export Number

@since3.10.0

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>>

@since3.10.0

maxItems
(2))
// 指定数组中项目的最小数量
import Schema
Schema
.
Array<typeof Schema.Number>(value: typeof Schema.Number): Schema.Array$<typeof Schema.Number>
export Array

@since3.10.0

Array
(
import Schema
Schema
.
class Number
export Number

@since3.10.0

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>>

@since3.10.0

minItems
(2))
// 指定数组中项目的确切数量
import Schema
Schema
.
Array<typeof Schema.Number>(value: typeof Schema.Number): Schema.Array$<typeof Schema.Number>
export Array

@since3.10.0

Array
(
import Schema
Schema
.
class Number
export Number

@since3.10.0

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>>

@since3.10.0

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.

@since3.10.0

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.

@since3.10.0

validDate
())
// or
import 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.

@since3.10.0

ValidDateFromSelf
// 指定大于当前日期的日期
import Schema
Schema
.
class Date
export 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").

@since3.10.0

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>

@since3.10.0

greaterThanDate
(new
var Date: DateConstructor
new () => Date (+3 overloads)
Date
()))
// 指定大于或等于当前日期的日期
import Schema
Schema
.
class Date
export 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").

@since3.10.0

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>

@since3.10.0

greaterThanOrEqualToDate
(new
var Date: DateConstructor
new () => Date (+3 overloads)
Date
()))
// 指定小于当前日期的日期
import Schema
Schema
.
class Date
export 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").

@since3.10.0

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>

@since3.10.0

lessThanDate
(new
var Date: DateConstructor
new () => Date (+3 overloads)
Date
()))
// 指定小于或等于当前日期的日期
import Schema
Schema
.
class Date
export 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").

@since3.10.0

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>

@since3.10.0

lessThanOrEqualToDate
(new
var Date: DateConstructor
new () => Date (+3 overloads)
Date
()))
// 指定两个日期之间的日期
import Schema
Schema
.
class Date
export 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").

@since3.10.0

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>

@since3.10.0

betweenDate
(new
var Date: DateConstructor
new (value: number | string | Date) => Date (+3 overloads)
Date
(0), new
var Date: DateConstructor
new () => Date (+3 overloads)
Date
()))

以下是Schema模块提供的有用BigInt过滤器列表:

import {
import Schema
Schema
} from "effect"
// 指定大于5的BigInt
import Schema
Schema
.
class BigInt
export 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).

@since3.10.0

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>

@since3.10.0

greaterThanBigInt
(5n))
// 指定大于或等于5的BigInt
import Schema
Schema
.
class BigInt
export 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).

@since3.10.0

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>

@since3.10.0

greaterThanOrEqualToBigInt
(5n))
// 指定小于5的BigInt
import Schema
Schema
.
class BigInt
export 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).

@since3.10.0

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>

@since3.10.0

lessThanBigInt
(5n))
// 指定小于或等于5的BigInt
import Schema
Schema
.
class BigInt
export 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).

@since3.10.0

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>

@since3.10.0

lessThanOrEqualToBigInt
(5n))
// 指定-2n到2n之间的BigInt,包含边界
import Schema
Schema
.
class BigInt
export 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).

@since3.10.0

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>

@since3.10.0

betweenBigInt
(-2n, 2n))
// 指定正BigInt(> 0n)
import Schema
Schema
.
class BigInt
export 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).

@since3.10.0

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>

@since3.10.0

positiveBigInt
())
// or
import Schema
Schema
.
const PositiveBigIntFromSelf: Schema.filter<Schema.Schema<bigint, bigint, never>>

@since3.10.0

PositiveBigIntFromSelf
// 指定非负BigInt(>= 0n)
import Schema
Schema
.
class BigInt
export 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).

@since3.10.0

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>

@since3.10.0

nonNegativeBigInt
())
// or
import Schema
Schema
.
const NonNegativeBigIntFromSelf: Schema.filter<Schema.Schema<bigint, bigint, never>>

@since3.10.0

NonNegativeBigIntFromSelf
// 指定负BigInt(< 0n)
import Schema
Schema
.
class BigInt
export 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).

@since3.10.0

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>

@since3.10.0

negativeBigInt
())
// or
import Schema
Schema
.
const NegativeBigIntFromSelf: Schema.filter<Schema.Schema<bigint, bigint, never>>

@since3.10.0

NegativeBigIntFromSelf
// 指定非正BigInt(<= 0n)
import Schema
Schema
.
class BigInt
export 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).

@since3.10.0

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>

@since3.10.0

nonPositiveBigInt
())
// or
import Schema
Schema
.
const NonPositiveBigIntFromSelf: Schema.filter<Schema.Schema<bigint, bigint, never>>

@since3.10.0

NonPositiveBigIntFromSelf

以下是Schema模块提供的有用BigDecimal过滤器列表:

import {
import Schema
Schema
,
import BigDecimal
BigDecimal
} from "effect"
// 指定大于5的BigDecimal
import Schema
Schema
.
class BigDecimal

@since3.10.0

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>

@since3.10.0

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).

@example

import * as assert from "node:assert"
import { unsafeFromNumber, make } from "effect/BigDecimal"
assert.deepStrictEqual(unsafeFromNumber(123), make(123n, 0))
assert.deepStrictEqual(unsafeFromNumber(123.456), make(123456n, 3))

@since3.11.0

unsafeFromNumber
(5))
)
// 指定大于或等于5的BigDecimal
import Schema
Schema
.
class BigDecimal

@since3.10.0

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>

@since3.10.0

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).

@example

import * as assert from "node:assert"
import { unsafeFromNumber, make } from "effect/BigDecimal"
assert.deepStrictEqual(unsafeFromNumber(123), make(123n, 0))
assert.deepStrictEqual(unsafeFromNumber(123.456), make(123456n, 3))

@since3.11.0

unsafeFromNumber
(5))
)
// 指定小于5的BigDecimal
import Schema
Schema
.
class BigDecimal

@since3.10.0

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>

@since3.10.0

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).

@example

import * as assert from "node:assert"
import { unsafeFromNumber, make } from "effect/BigDecimal"
assert.deepStrictEqual(unsafeFromNumber(123), make(123n, 0))
assert.deepStrictEqual(unsafeFromNumber(123.456), make(123456n, 3))

@since3.11.0

unsafeFromNumber
(5))
)
// 指定小于或等于5的BigDecimal
import Schema
Schema
.
class BigDecimal

@since3.10.0

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>

@since3.10.0

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).

@example

import * as assert from "node:assert"
import { unsafeFromNumber, make } from "effect/BigDecimal"
assert.deepStrictEqual(unsafeFromNumber(123), make(123n, 0))
assert.deepStrictEqual(unsafeFromNumber(123.456), make(123456n, 3))

@since3.11.0

unsafeFromNumber
(5))
)
// 指定-2到2之间的BigDecimal,包含边界
import Schema
Schema
.
class BigDecimal

@since3.10.0

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>

@since3.10.0

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).

@example

import * as assert from "node:assert"
import { unsafeFromNumber, make } from "effect/BigDecimal"
assert.deepStrictEqual(unsafeFromNumber(123), make(123n, 0))
assert.deepStrictEqual(unsafeFromNumber(123.456), make(123456n, 3))

@since3.11.0

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).

@example

import * as assert from "node:assert"
import { unsafeFromNumber, make } from "effect/BigDecimal"
assert.deepStrictEqual(unsafeFromNumber(123), make(123n, 0))
assert.deepStrictEqual(unsafeFromNumber(123.456), make(123456n, 3))

@since3.11.0

unsafeFromNumber
(2)
)
)
// 指定正BigDecimal(> 0)
import Schema
Schema
.
class BigDecimal

@since3.10.0

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>

@since3.10.0

positiveBigDecimal
())
// 指定非负BigDecimal(>= 0)
import Schema
Schema
.
class BigDecimal

@since3.10.0

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>

@since3.10.0

nonNegativeBigDecimal
())
// 指定负BigDecimal(< 0)
import Schema
Schema
.
class BigDecimal

@since3.10.0

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>

@since3.10.0

negativeBigDecimal
())
// 指定非正BigDecimal(<= 0)
import Schema
Schema
.
class BigDecimal

@since3.10.0

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>

@since3.10.0

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.

@since3.10.0

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>

@since3.10.0

greaterThanDuration
("5 seconds"))
// 指定大于或等于5秒的持续时间
import Schema
Schema
.
class Duration

A schema that converts a JSON-compatible tagged union into a Duration.

@since3.10.0

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>

@since3.10.0

greaterThanOrEqualToDuration
("5 seconds"))
// 指定小于5秒的持续时间
import Schema
Schema
.
class Duration

A schema that converts a JSON-compatible tagged union into a Duration.

@since3.10.0

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>

@since3.10.0

lessThanDuration
("5 seconds"))
// 指定小于或等于5秒的持续时间
import Schema
Schema
.
class Duration

A schema that converts a JSON-compatible tagged union into a Duration.

@since3.10.0

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>

@since3.10.0

lessThanOrEqualToDuration
("5 seconds"))
// 指定5秒到10秒之间的持续时间,包含边界
import Schema
Schema
.
class Duration

A schema that converts a JSON-compatible tagged union into a Duration.

@since3.10.0

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>

@since3.10.0

betweenDuration
("5 seconds", "10 seconds"))