@traversable/schema
    Preparing search index...

    Module @traversable/schema-to-validator - v0.0.6


    ᯓ𝘁𝗿𝗮𝘃𝗲𝗿𝘀𝗮𝗯𝗹𝗲/𝗱𝗲𝗿𝗶𝘃𝗲-𝘃𝗮𝗹𝗶𝗱𝗮𝘁𝗼𝗿𝘀


    Re-use your schema to derive a super fast validation function (with even faster compiled validators coming soon!)

    NPM Version   TypeScript   License   npm  
    Static Badge   Static Badge   Static Badge  
    Demo (Stackblitz)   •   TypeScript Playground   •   npm



    .validate is similar to z.safeParse, except more than an order of magnitude faster*.

    • Instructions: To install the .validate method to all schemas, all you need to do is import @traversable/schema-to-validator.
    • [ ] TODO: add benchmarks + write-up

    Play with this example in the TypeScript playground.

    import { t } from '@traversable/schema'
    import '@traversable/schema-to-validator'

    let schema_01 = t.object({
    product: t.object({
    x: t.integer,
    y: t.integer
    }),
    sum: t.union(
    t.tuple(t.eq(0), t.integer),
    t.tuple(t.eq(1), t.integer),
    ),
    })

    let result = schema_01.validate({ product: { x: null }, sum: [2, 3.141592]})
    // ↑↑ importing `@traversable/schema-to-validator` installs `.validate`

    console.log(result)
    // =>
    // [
    // { "kind": "TYPE_MISMATCH", "path": [ "product", "x" ], "expected": "number", "got": null },
    // { "kind": "REQUIRED", "path": [ "product" ], "msg": "Missing key 'y'" },
    // { "kind": "TYPE_MISMATCH", "path": [ "sum", 0 ], "expected": 0, "got": 2 },
    // { "kind": "TYPE_MISMATCH", "path": [ "sum", 1 ], "expected": "number", "got": 3.141592 },
    // { "kind": "TYPE_MISMATCH", "path": [ "sum", 0 ], "expected": 1, "got": 2 },
    // { "kind": "TYPE_MISMATCH", "path": [ "sum", 1 ], "expected": "number", "got": 3.141592 },
    // ]

    Namespaces

    Validator

    Interfaces

    Options
    ValidationError

    Type Aliases

    ErrorType
    Validate
    ValidationFn
    Validator
    VERSION

    Variables

    dataPathFromSchemaPath
    Errors
    ErrorType
    fromSchema
    fromSchemaWithOptions
    VERSION

    Functions

    isOptional