Function: parse()

Parses a value using a Standard Schema compatible schema. Returns a Result with the parsed value on success or validation errors on failure.

Type Param

The Standard Schema V1 compatible schema type.

Examples

import { 
import Result
Result
} from '@praha/byethrow';
import {
import z
z
} from 'zod';
const
const schema: z.ZodObject<{
    name: z.ZodString;
}, z.core.$strip>
schema
=
import z
z
.
function object<{
    name: z.ZodString;
}>(shape?: {
    name: z.ZodString;
} | undefined, params?: string | {
    error?: string | z.core.$ZodErrorMap<NonNullable<z.core.$ZodIssueInvalidType<unknown> | z.core.$ZodIssueUnrecognizedKeys>> | undefined;
    message?: string | undefined | undefined;
} | undefined): z.ZodObject<{
    name: z.ZodString;
}, z.core.$strip>
object
({
name: z.ZodString
name
:
import z
z
.
function string(params?: string | z.core.$ZodStringParams): z.ZodString (+1 overload)
string
() });
const
const result: Result.Result<{
    name: string;
}, readonly StandardSchemaV1.Issue[]>
result
=
import Result
Result
.
const parse: <z.ZodObject<{
    name: z.ZodString;
}, z.core.$strip>>(schema: z.ZodObject<{
    name: z.ZodString;
}, z.core.$strip>, value: unknown) => Result.Result<{
    name: string;
}, readonly StandardSchemaV1<Input = unknown, Output = Input>.Issue[]> (+1 overload)
parse
(
const schema: z.ZodObject<{
    name: z.ZodString;
}, z.core.$strip>
schema
, {
name: string
name
: 'John' });
// Result.Result<{ name: string }, ReadonlyArray<StandardSchemaV1.Issue>>
import { 
import Result
Result
} from '@praha/byethrow';
import {
import z
z
} from 'zod';
const
const schema: z.ZodObject<{
    name: z.ZodString;
}, z.core.$strip>
schema
=
import z
z
.
function object<{
    name: z.ZodString;
}>(shape?: {
    name: z.ZodString;
} | undefined, params?: string | {
    error?: string | z.core.$ZodErrorMap<NonNullable<z.core.$ZodIssueInvalidType<unknown> | z.core.$ZodIssueUnrecognizedKeys>> | undefined;
    message?: string | undefined | undefined;
} | undefined): z.ZodObject<{
    name: z.ZodString;
}, z.core.$strip>
object
({
name: z.ZodString
name
:
import z
z
.
function string(params?: string | z.core.$ZodStringParams): z.ZodString (+1 overload)
string
() });
const
const parser: (value: unknown) => Result.Result<{
    name: string;
}, readonly StandardSchemaV1.Issue[]>
parser
=
import Result
Result
.
const parse: <z.ZodObject<{
    name: z.ZodString;
}, z.core.$strip>>(schema: z.ZodObject<{
    name: z.ZodString;
}, z.core.$strip>) => (value: unknown) => Result.Result<{
    name: string;
}, readonly StandardSchemaV1<Input = unknown, Output = Input>.Issue[]> (+1 overload)
parse
(
const schema: z.ZodObject<{
    name: z.ZodString;
}, z.core.$strip>
schema
);
const
const result: Result.Result<{
    name: string;
}, readonly StandardSchemaV1.Issue[]>
result
=
const parser: (value: unknown) => Result.Result<{
    name: string;
}, readonly StandardSchemaV1<Input = unknown, Output = Input>.Issue[]>
parser
({
name: string
name
: 'John' });
// Result.Result<{ name: string }, ReadonlyArray<StandardSchemaV1.Issue>>

Call Signature

parse<S>(schema): (value) => Result<InferOutput<S>, readonly Issue[]>

Type Parameters

S

S extends StandardSchemaV1<unknown, unknown>

Parameters

schema

S

Returns

(value): Result<InferOutput<S>, readonly Issue[]>

Parameters

value

unknown

Returns

Result<InferOutput<S>, readonly Issue[]>

Call Signature

parse<S>(schema, value): Result<InferOutput<S>, readonly Issue[]>

Type Parameters

S

S extends StandardSchemaV1<unknown, unknown>

Parameters

schema

S

value

unknown

Returns

Result<InferOutput<S>, readonly Issue[]>