RegExpType-level representation of RegExp.
export interface RegExp extends interface instanceOf<T, Iso = T>Creates a schema that validates values using instanceof.
Decoding and encoding pass the value through unchanged.
Example (Defining a schema for a built-in class)
import { Schema } from "effect"
const DateSchema = Schema.instanceOf(Date)
const decoded = Schema.decodeUnknownSync(DateSchema)(new Date("2024-01-01"))
// decoded: Date
Type-level representation returned by
instanceOf
.
instanceOf<module globalThisglobalThis.RegExp> {
readonly "Rebuild": RegExp
}
/**
* Schema for JavaScript `RegExp` objects.
*
* **Details**
*
* The default JSON serializer encodes a `RegExp` as `{ source, flags }`.
*
* @category RegExp
* @since 4.0.0
*/
export const const RegExp: RegExpconst RegExp: {
Rebuild: RegExp;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Annotations.Bottom<globalThis.RegExp, readonly []>) => RegExp;
annotateKey: (annotations: Annotations.Key<globalThis.RegExp>) => RegExp;
check: (checks_0: SchemaAST.Check<globalThis.RegExp>, ...checks: Array<SchemaAST.Check<globalThis.RegExp>>) => RegExp;
rebuild: (ast: SchemaAST.Declaration) => RegExp;
make: (input: globalThis.RegExp, options?: MakeOptions) => globalThis.RegExp;
makeOption: (input: globalThis.RegExp, options?: MakeOptions) => Option_.Option<globalThis.RegExp>;
makeEffect: (input: globalThis.RegExp, options?: MakeOptions) => Effect.Effect<globalThis.RegExp, SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
Type-level representation of
RegExp
.
Schema for JavaScript RegExp objects.
Details
The default JSON serializer encodes a RegExp as { source, flags }.
RegExp: RegExp = function instanceOf<
C extends abstract new (...args: any) => any,
Iso = InstanceType<C>
>(
constructor: C,
annotations?:
| Annotations.Declaration<InstanceType<C>>
| undefined
): instanceOf<InstanceType<C>, Iso>
Creates a schema that validates values using instanceof.
Decoding and encoding pass the value through unchanged.
Example (Defining a schema for a built-in class)
import { Schema } from "effect"
const DateSchema = Schema.instanceOf(Date)
const decoded = Schema.decodeUnknownSync(DateSchema)(new Date("2024-01-01"))
// decoded: Date
instanceOf(
module globalThisglobalThis.var RegExp: RegExpConstructorRegExp,
{
Annotations.Declaration<globalThis.RegExp, readonly []>.typeConstructor?: {
readonly [key: string]: unknown;
readonly _tag: string;
} | undefined
typeConstructor: {
_tag: string_tag: "RegExp"
},
Annotations.Declaration<globalThis.RegExp, readonly []>.generation?: {
readonly runtime: string;
readonly Type: string;
readonly Encoded?: string | undefined;
readonly importDeclaration?: string | undefined;
} | undefined
generation: {
runtime: stringruntime: `Schema.RegExp`,
type Type: stringType: `globalThis.RegExp`
},
Annotations.Augment.expected?: string | undefinedHuman-readable description of what a value is expected to satisfy.
Details
For filter and refinement failures, the default formatter uses
message first, then expected, and finally falls back to <filter>.
Use this to name a failed filter in the default message:
Expected <expected>, got <actual>.
expected: "RegExp",
Annotations.Declaration<globalThis.RegExp, readonly []>.toCodecJson?: ((typeParameters: readonly []) => SchemaAST.Link) | undefinedtoCodecJson: () =>
function link<T>(): <
To extends Constraint
>(
encodeTo: To,
transformation: {
readonly decode: SchemaGetter.Getter<
T,
NoInfer<To["Type"]>
>
readonly encode: SchemaGetter.Getter<
NoInfer<To["Type"]>,
T
>
}
) => SchemaAST.Link
Constructs an SchemaAST.Link that describes how a value of type T encodes to and decodes from a To schema.
Used when building low-level AST transformations that bridge two schema types.
link<module globalThisglobalThis.RegExp>()(
function Struct<
Fields extends Struct.Fields
>(fields: Fields): Struct<Fields>
Defines a struct schema from a map of field schemas.
Details
Each field value is a schema. Use
optionalKey
or
optional
to
mark fields as optional, and
mutableKey
to mark them as mutable.
The resulting schema's Type is a readonly object type with the fields'
decoded types. The Encoded form mirrors the field schemas' encoded types.
Example (Defining a basic struct)
import { Schema } from "effect"
const Person = Schema.Struct({
name: Schema.String,
age: Schema.Number,
email: Schema.optionalKey(Schema.String)
})
// { readonly name: string; readonly age: number; readonly email?: string }
type Person = typeof Person.Type
const alice = Schema.decodeUnknownSync(Person)({ name: "Alice", age: 30 })
console.log(alice)
// { name: 'Alice', age: 30 }
Struct({
source: String(property) source: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Annotations.Bottom<string, readonly []>) => String;
annotateKey: (annotations: Annotations.Key<string>) => String;
check: (checks_0: SchemaAST.Check<string>, ...checks: Array<SchemaAST.Check<string>>) => String;
rebuild: (ast: SchemaAST.String) => String;
make: (input: string, options?: MakeOptions) => string;
makeOption: (input: string, options?: MakeOptions) => Option_.Option<string>;
makeEffect: (input: string, options?: MakeOptions) => Effect.Effect<string, SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
source: const String: Stringconst String: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Annotations.Bottom<string, readonly []>) => String;
annotateKey: (annotations: Annotations.Key<string>) => String;
check: (checks_0: SchemaAST.Check<string>, ...checks: Array<SchemaAST.Check<string>>) => String;
rebuild: (ast: SchemaAST.String) => String;
make: (input: string, options?: MakeOptions) => string;
makeOption: (input: string, options?: MakeOptions) => Option_.Option<string>;
makeEffect: (input: string, options?: MakeOptions) => Effect.Effect<string, SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
Type-level representation of
String
.
Schema for string values. Validates that the input is typeof "string".
String,
flags: String(property) flags: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Annotations.Bottom<string, readonly []>) => String;
annotateKey: (annotations: Annotations.Key<string>) => String;
check: (checks_0: SchemaAST.Check<string>, ...checks: Array<SchemaAST.Check<string>>) => String;
rebuild: (ast: SchemaAST.String) => String;
make: (input: string, options?: MakeOptions) => string;
makeOption: (input: string, options?: MakeOptions) => Option_.Option<string>;
makeEffect: (input: string, options?: MakeOptions) => Effect.Effect<string, SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
flags: const String: Stringconst String: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Annotations.Bottom<string, readonly []>) => String;
annotateKey: (annotations: Annotations.Key<string>) => String;
check: (checks_0: SchemaAST.Check<string>, ...checks: Array<SchemaAST.Check<string>>) => String;
rebuild: (ast: SchemaAST.String) => String;
make: (input: string, options?: MakeOptions) => string;
makeOption: (input: string, options?: MakeOptions) => Option_.Option<string>;
makeEffect: (input: string, options?: MakeOptions) => Effect.Effect<string, SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
Type-level representation of
String
.
Schema for string values. Validates that the input is typeof "string".
String
}),
import SchemaTransformationSchemaTransformation.function transformOrFail<
T,
E,
RD = never,
RE = never
>(options: {
readonly decode: (
e: E,
options: SchemaAST.ParseOptions
) => Effect.Effect<T, SchemaIssue.Issue, RD>
readonly encode: (
t: T,
options: SchemaAST.ParseOptions
) => Effect.Effect<E, SchemaIssue.Issue, RE>
}): Transformation<T, E, RD, RE>
Creates a Transformation from effectful decode and encode functions that
can fail with Issue.
When to use
Use when you need a schema transformation that may fail or require Effect
services.
Details
- Each function receives the input value and
ParseOptions.
- Must return an
Effect that succeeds with the output or fails with Issue.
- Skips
None inputs (missing keys) — functions are only called on present values.
Example (Parsing a date string that can fail)
import { Effect, Option, Schema, SchemaIssue, SchemaTransformation } from "effect"
const DateFromString = Schema.String.pipe(
Schema.decodeTo(
Schema.Date,
SchemaTransformation.transformOrFail({
decode: (s) => {
const d = new Date(s)
return isNaN(d.getTime())
? Effect.fail(new SchemaIssue.InvalidValue(Option.some(s), { message: "Invalid date" }))
: Effect.succeed(d)
},
encode: (d) => Effect.succeed(d.toISOString())
})
)
)
transformOrFail({
decode: (
e: NoInfer<
Struct.ReadonlySide<
{
readonly source: String
readonly flags: String
},
"Type"
>
>,
options: SchemaAST.ParseOptions
) => Effect.Effect<
globalThis.RegExp,
SchemaIssue.Issue,
never
>
decode: (e: NoInfer<
Struct.ReadonlySide<
{
readonly source: String
readonly flags: String
},
"Type"
>
>
e) =>
import EffectEffect.try({
try: () => globalThis.RegExptry: () => new module globalThisglobalThis.var RegExp: RegExpConstructor
new (pattern: globalThis.RegExp | string, flags?: string) => globalThis.RegExp (+2 overloads)
RegExp(e: Struct.ReadonlySide<
{
readonly source: String
readonly flags: String
},
"Type"
>
(parameter) e: {
source: string;
flags: string;
}
e.source: stringsource, e: Struct.ReadonlySide<
{
readonly source: String
readonly flags: String
},
"Type"
>
(parameter) e: {
source: string;
flags: string;
}
e.flags: stringflags),
catch: (e: any) => SchemaIssue.InvalidValuecatch: (e: anye) => new import SchemaIssueSchemaIssue.constructor InvalidValue(actual: StandardJSONSchemaV1<unknown>, annotations?: Annotations.Issue | undefined): SchemaIssue.InvalidValueRepresents a schema issue produced when the input has the correct type but its value violates a
constraint (e.g. a string that is too short, a number out of range).
When to use
Use when you need to detect constraint violations from Schema.filter,
Schema.minLength, Schema.greaterThan, or similar checks.
Details
actual is Option.some(value) when the failing value is known, or
Option.none() when absent.
annotations optionally carries a message string for formatting.
- The default formatter renders this as
"Invalid data <actual>" unless a
custom message annotation is provided.
Example (Returning InvalidValue from a custom filter)
import { Option, SchemaIssue } from "effect"
const issue = new SchemaIssue.InvalidValue(
Option.some(""),
{ message: "must not be empty" }
)
console.log(String(issue))
// "must not be empty"
InvalidValue(import Option_Option_.some(e: anye), { Annotations.Issue.message?: string | undefinedmessage: module globalThisglobalThis.var String: StringConstructor
;(value?: any) => string
Allows manipulation and formatting of text strings and determination and location of substrings within strings.
String(e: anye) })
}),
encode: (
t: globalThis.RegExp,
options: SchemaAST.ParseOptions
) => Effect.Effect<
NoInfer<
Struct.ReadonlySide<
{
readonly source: String
readonly flags: String
},
"Type"
>
>,
SchemaIssue.Issue,
never
>
encode: (regExp: globalThis.RegExpregExp) =>
import EffectEffect.succeed({
source: stringsource: regExp: globalThis.RegExpregExp.RegExp.source: stringReturns a copy of the text of the regular expression pattern. Read-only. The regExp argument is a Regular expression object. It can be a variable name or a literal.
source,
flags: stringflags: regExp: globalThis.RegExpregExp.RegExp.flags: stringReturns a string indicating the flags of the regular expression in question. This field is read-only.
The characters in this string are sequenced and concatenated in the following order:
- "g" for global
- "i" for ignoreCase
- "m" for multiline
- "u" for unicode
- "y" for sticky
If no flags are set, the value is the empty string.
flags
})
})
),
Annotations.Declaration<globalThis.RegExp, readonly []>.toArbitrary?: Annotations.ToArbitrary.Declaration<globalThis.RegExp, readonly []> | undefinedtoArbitrary: () => (fc: typeof FastCheckfc) =>
fc: typeof FastCheckfc
.tuple(
fc: typeof FastCheckfc.constantFrom(
".",
".*",
"\\d+",
"\\w+",
"[a-z]+",
"[A-Z]+",
"[0-9]+",
"^[a-zA-Z0-9]+$",
"^\\d{4}-\\d{2}-\\d{2}$" // date pattern
),
fc: typeof FastCheckfc
.uniqueArray(fc: typeof FastCheckfc.constantFrom("g", "i", "m", "s", "u", "y"), {
minLength: numberminLength: 0,
maxLength: numbermaxLength: 6
})
.map((flags: anyflags) => flags: anyflags.join(""))
)
.map(([source: anysource, flags: anyflags]) => new module globalThisglobalThis.var RegExp: RegExpConstructor
new (pattern: globalThis.RegExp | string, flags?: string) => globalThis.RegExp (+2 overloads)
RegExp(source: anysource, flags: anyflags)),
Annotations.Declaration<globalThis.RegExp, readonly []>.toEquivalence?: Annotations.ToEquivalence.Declaration<globalThis.RegExp, readonly []> | undefinedtoEquivalence: () => (a: anya, b: anyb) => a: anya.source === b: anyb.source && a: anya.flags === b: anyb.flags
}
)