(
schema: S,
options?: SchemaAST.ParseOptions & Options & StreamOptions & { readonly maxFrameSize?: number | undefined }
)
| 341 | * @since 4.0.0 |
| 342 | */ |
| 343 | export function parser<S extends Schema.Constraint>( |
| 344 | schema: S, |
| 345 | options?: SchemaAST.ParseOptions & Options & StreamOptions & { readonly maxFrameSize?: number | undefined } |
| 346 | ): Parser<S["Type"]> { |
| 347 | const { exact, exitSuccess, layout, target } = compileTarget(schema) |
| 348 | const parseOptions: SchemaAST.ParseOptions = options ?? SchemaAST.defaultParseOptions |
| 349 | const decodeTarget = exact |
| 350 | ? undefined |
| 351 | : Schema.decodeUnknownSync(target as Schema.ConstraintDecoder<unknown>, parseOptions) |
| 352 | const decodeEncoded = decodeTarget !== undefined && exitSuccess |
| 353 | ? (value: unknown) => isSuccessExit(value) ? value : decodeTarget(value) |
| 354 | : decodeTarget |
| 355 | return makeParser( |
| 356 | layout, |
| 357 | compileMode(layout, options?.fingerprint), |
| 358 | parseOptions, |
| 359 | options?.maxFrameSize, |
| 360 | decodeEncoded, |
| 361 | requireDictionary(exact, options) |
| 362 | ) |
| 363 | } |
| 364 | |
| 365 | /** |
| 366 | * Options for the connection-scoped pair, {@link encoder} and {@link parser}. |
no test coverage detected