LogoLogo

Schema Benchmarks

    • home
      Home

    • download_2
      Download

    • timer
      Initialization
    • check_circle
      Validation
    • output_circle
      Parsing
    • swap_horiz
      Codec
    • schema
      Standard Schema
    • format_quote
      String

    • error
      Stack

    • article
      Blog
Code styleCode style
Normal styleNormal style
System themeSystem theme
Light themeLight theme
Dark themeDark theme
Expand sidebarExpand sidebar
decoders/SourceSource
Code styleCode style
Normal styleNormal style
System themeSystem theme
Light themeLight theme
Dark themeDark theme
github
GitHubGitHub
DiscordDiscord
schemas/libraries/decoders/download.ts
Copy to clipboardCopy to clipboard
import type { Decoder } from "decoders"; import { object, number, date, string, array, oneOf, nullable, sized, between, urlString, } from "decoders"; import type { ProductData } from "#src"; const imageDecoder = object({ id: number, created: date, title: sized(string, { min: 1, max: 100 }), type: oneOf(["jpg", "png"]), size: number, url: urlString, }); const ratingDecoder = object({ id: number, stars: between(1, 5), title: sized(string, { min: 1, max: 100 }), text: sized(string, { min: 1, max: 1000 }), images: array(imageDecoder), }); const productDecoder = object({ id: number, created: date, title: sized(string, { min: 1, max: 100 }), brand: sized(string, { min: 1, max: 30 }), description: sized(string, { min: 1, max: 500 }), price: between(1, 10000), discount: nullable(between(1, 100)), quantity: between(1, 10), tags: array(sized(string, { min: 1, max: 30 })), images: array(imageDecoder), ratings: array(ratingDecoder), }) satisfies Decoder<ProductData>; productDecoder.verify({});
Created by eskimojo for Open Circle