@traversable/schema
    Preparing search index...

    Module @traversable/arktype - v0.0.9


    ᯓ𝘁𝗿𝗮𝘃𝗲𝗿𝘀𝗮𝗯𝗹𝗲/𝗮𝗿𝗸𝘁𝘆𝗽𝗲


    @traversable/arktype is a schema rewriter for ArkType schemas.

    NPM Version   TypeScript   License   npm  
    Static Badge   Static Badge   Static Badge  


    Note

    Currently this package only supports ArkType schemas that can be compiled to JSON Schema Draft 2020-12. We're in the process of adding support for all schemas.

    $ pnpm add @traversable/arktype
    

    Here's an example of importing the library:

    import { type } from 'arktype'
    import { ark } from '@traversable/arktype'

    // or, if you prefer, you can use named imports:
    import { deepClone, deepEqual } from '@traversable/arktype'

    // see below for specific examples

    ark.deepClone lets users derive a specialized "deep copy" function that works with values that have been already validated.

    Because the values have already been validated, clone times are significantly faster than alternatives like window.structuredClone and Lodash.cloneDeep.

    Here's a Bolt sandbox if you'd like to run the benchmarks yourself.

                               ┌─────────────────┐
    Average
    ┌──────────────────────────┼─────────────────┤
    window.structuredClone │ 14.82x faster
    ├──────────────────────────┼─────────────────┤
    Lodash.cloneDeep │ 18.86x faster
    └──────────────────────────┴─────────────────┘

    This article goes into more detail about what makes ark.deepClone so fast.

    import { type } from 'arktype'
    import { deepClone, deepEqual } from '@traversable/arktype'

    const Address = type({
    street1: 'string',
    "street2?": 'string',
    city: 'string'
    })

    const cloneAddress = deepClone(Address)
    const addressEquals = deepEqual(Address)

    const sherlock = { street1: '221 Baker St', street2: '#B', city: 'London' }
    const harry = { street1: '4 Privet Dr', city: 'Little Whinging' }

    const sherlockCloned = cloneAddress(sherlock)
    const harryCloned = cloneAddress(harry)

    addressEquals(sherlockCloned, sherlock) // => true
    sherlock === sherlockCloned // => false

    addressEquals(harryCloned, harry) // => true
    harry === harryCloned // => false

    ark.deepClone.writeable lets users derive a specialized "deep clone" function that works with values that have been already validated.

    Compared to ark.deepClone, ark.deepClone.writeable returns the clone function in stringified ("writeable") form.

    import { type } from 'arktype'
    import { deepClone } from '@traversable/arktype'

    const cloneAddress = deepClone.writeable(
    type({
    street1: 'string',
    "street2?": 'string',
    city: 'string'
    }),
    { typeName: 'Address' }
    )

    console.log(cloneAddress)
    // =>
    // type Address = { street1: string; street2?: string; city: string; }
    // function deepClone(prev: Address): Address {
    // return {
    // street1: prev.street1,
    // ...prev.street2 !== undefined && { street2: prev.street2 },
    // city: prev.city
    // }
    // }

    ark.deepEqual lets users derive a specialized "deep equal" function that works with values that have been already validated.

    Because the values have already been validated, comparison times are significantly faster than alternatives like NodeJS.isDeepStrictEqual and Lodash.isEqual.

    Here's a Bolt sandbox if you'd like to run the benchmarks yourself.

                                 ┌─────────────────┐
    Average
    ┌────────────────────────────┼─────────────────┤
    NodeJS.isDeepStrictEqual │ 23.45x faster
    ├────────────────────────────┼─────────────────┤
    Lodash.isEqual │ 49.29x faster
    └────────────────────────────┴─────────────────┘

    This article goes into more detail about what makes ark.deepEqual so fast.

    • Best performance
    • Works in any environment that supports defining functions using the Function constructor, including (as of May 2025) Cloudflare workers 🎉
    import { type } from 'arktype'
    import { deepEqual } from '@traversable/arktype'

    const addressEquals = deepEqual(
    type({
    street1: 'string',
    "street2?": 'string',
    city: 'string'
    })
    )

    addressEquals(
    { street1: '221 Baker St', street2: '#B', city: 'London' },
    { street1: '221 Baker St', street2: '#B', city: 'London' }
    ) // => true

    addressEquals(
    { street1: '221 Baker St', street2: '#B', city: 'London' },
    { street1: '4 Privet Dr', city: 'Little Whinging' }
    ) // => false

    ark.deepEqual.writeable lets users derive a specialized "deep equal" function that works with values that have been already validated.

    Compared to ark.deepEqual, ark.deepEqual.writeable returns the deep equal function in stringified ("writeable") form.

    • Useful when you're consuming a set of ArkType schemas and writing all them to disc somewhere
    • Also useful for testing purposes or for troubleshooting, since it gives you a way to "see" exactly what the deepEqual functions are doing
    import { type } from 'arktype'
    import { deepEqual } from '@traversable/arktype'

    const addressEquals = deepEqual.writeable(
    type({
    street1: 'string',
    "street2?": 'string',
    city: 'string'
    }),
    { typeName: 'Address' }
    )

    console.log(addressEquals)
    // =>
    // type Address = { street1: string; street2?: string; city: string; }
    // function deepEqual(x: Address, y: Address) {
    // if (x === y) return true;
    // if (x.street1 !== y.street1) return false;
    // if (x.street2 !== y.street2) return false;
    // if (x.city !== y.city) return false;
    // return true;
    // }

    Namespaces

    ark
    deepClone
    deepEqual

    Type Aliases

    VERSION

    Variables

    VERSION

    Functions

    deepClone
    deepEqual