@traversable/schema
    Preparing search index...
    writeable: <S extends BaseSchema<unknown, unknown, any>>(
        baseSchema: S,
        options?: deepClone.Options,
    ) => string

    Type declaration

      • <S extends BaseSchema<unknown, unknown, any>>(
            baseSchema: S,
            options?: deepClone.Options,
        ): string
      • Derive a "writeable" (stringified) "deep clone" function from a valibot schema.

        The generated cloning function is significantly faster than JavaScript's built-in structuredClone structuredClone:

        • ~3x faster with shallow schemas
        • ~10x faster with large schemas

        It's even faster when compared with Lodash's deepCloneDeep:

        • ~9x faster with shallow schemas
        • ~25x faster with large schemas

        This is possible because the cloning function knows the shape of your data ahead of time, and will do the minimum amount of work necessary to create a new copy of your data.

        Note that the deep clone function generated by vx.deepClone.writeable assumes that both values have already been validated. Passing invalid data to the deepClone function will result in undefined behavior. You don't have to worry about this as long as you

        vx.deepClone.writeable accepts an optional configuration object as its second argument; documentation for those options are available via hover on autocompletion.

        See also:

        Type Parameters

        • S extends BaseSchema<unknown, unknown, any>

        Parameters

        Returns string

        import * as v from 'valibot'
        import { vx } from '@traversable/valibot'

        const deepClone = vx.deepClone.writeable(
        v.object({
        street1: v.string(),
        street2: v.optional(v.string()),
        city: v.string(),
        }), { typeName: 'Address' }
        )

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