URLType-level representation of URL.
export interface URL 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.URL> {
readonly "Rebuild": URL
}
const const URLString: Stringconst URLString: {
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; <…;
}
URLString = 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.Bottom<string, string, never, never, String, String, string, string, readonly [], string, "readonly", "required", "no-default", "readonly", "required">.annotate(annotations: Annotations.Bottom<string, readonly []>): Stringannotate({ Annotations.Augment.expected?: string | undefinedHuman-readable description of what a value is expected to satisfy.
Details
For filter and refinement failures, the default formatter uses
message first, then expected, and finally falls back to <filter>.
Use this to name a failed filter in the default message:
Expected <expected>, got <actual>.
expected: "a string that will be decoded as a URL" })
/**
* Schema for JavaScript `URL` objects.
*
* **Details**
*
* Default JSON serializer:
*
* - encodes `URL` as a `string`
*
* @category URL
* @since 4.0.0
*/
export const const URL: URLconst URL: {
Rebuild: URL;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Annotations.Bottom<globalThis.URL, readonly []>) => URL;
annotateKey: (annotations: Annotations.Key<globalThis.URL>) => URL;
check: (checks_0: SchemaAST.Check<globalThis.URL>, ...checks: Array<SchemaAST.Check<globalThis.URL>>) => URL;
rebuild: (ast: SchemaAST.Declaration) => URL;
make: (input: globalThis.URL, options?: MakeOptions) => globalThis.URL;
makeOption: (input: globalThis.URL, options?: MakeOptions) => Option_.Option<globalThis.URL>;
makeEffect: (input: globalThis.URL, options?: MakeOptions) => Effect.Effect<globalThis.URL, 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
URL
.
Schema for JavaScript URL objects.
Details
Default JSON serializer:
- encodes
URL as a string
URL: URL = 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 URL: {
new (
url: string | globalThis.URL,
base?: string | globalThis.URL
): globalThis.URL
prototype: globalThis.URL
canParse(
url: string | globalThis.URL,
base?: string | globalThis.URL
): boolean
createObjectURL(obj: Blob | MediaSource): string
parse(
url: string | globalThis.URL,
base?: string | globalThis.URL
): globalThis.URL | null
revokeObjectURL(url: string): void
}
The URL interface is used to parse, construct, normalize, and encode URL.
URL,
{
Annotations.Declaration<globalThis.URL, readonly []>.typeConstructor?: {
readonly [key: string]: unknown;
readonly _tag: string;
} | undefined
typeConstructor: {
_tag: string_tag: "URL"
},
Annotations.Declaration<globalThis.URL, readonly []>.generation?: {
readonly runtime: string;
readonly Type: string;
readonly Encoded?: string | undefined;
readonly importDeclaration?: string | undefined;
} | undefined
generation: {
runtime: stringruntime: `Schema.URL`,
type Type: stringType: `globalThis.URL`
},
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: "URL",
Annotations.Declaration<globalThis.URL, 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.URL>()(
const URLString: Stringconst URLString: {
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; <…;
}
URLString,
import SchemaTransformationSchemaTransformation.const urlFromString: Transformation<
URL,
string
>
const urlFromString: {
_tag: 'Transformation';
decode: SchemaGetter.Getter<T, E, RD>;
encode: SchemaGetter.Getter<E, T, RE>;
flip: () => SchemaTransformation.Transformation<string, globalThis.URL, never, never>;
compose: (other: SchemaTransformation.Transformation<T2, globalThis.URL, RD2, RE2>) => SchemaTransformation.Transformation<T2, string, RD2, RE2>;
}
Decodes a string into a URL and encodes a URL back to its href
string.
When to use
Use when you need a schema transformation to parse URL strings from user
input or API responses.
Details
Decoding checks URL.canParse(s) and fails with InvalidValue if the string
is not a valid URL. Encoding returns url.href.
Example (Converting a string to a URL)
import { Schema, SchemaTransformation } from "effect"
const schema = Schema.String.pipe(
Schema.decodeTo(Schema.URL, SchemaTransformation.urlFromString)
)
urlFromString
),
Annotations.Declaration<globalThis.URL, readonly []>.toArbitrary?: Annotations.ToArbitrary.Declaration<globalThis.URL, readonly []> | undefinedtoArbitrary: () => (fc: typeof FastCheckfc) => fc: typeof FastCheckfc.webUrl().map((s: anys) => new module globalThisglobalThis.var URL: new (
url: string | globalThis.URL,
base?: string | globalThis.URL
) => globalThis.URL
The URL interface is used to parse, construct, normalize, and encode URL.
URL(s: anys)),
Annotations.Declaration<globalThis.URL, readonly []>.toEquivalence?: Annotations.ToEquivalence.Declaration<globalThis.URL, readonly []> | undefinedtoEquivalence: () => (a: anya, b: anyb) => a: anya.toString() === b: anyb.toString()
}
)