@traversable/schema
    Preparing search index...
    writeable: (schematic: TSchema, options?: deepClone.Options) => string

    Type declaration

      • (schematic: TSchema, options?: deepClone.Options): string
      • Derive a "writeable" (stringified) deep clone function from a JSON Schema spec.

        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 cloneDeep:

        • ~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 box.deepClone.writeable assumes that both values have already been validated. Passing invalid data to the clone function will result in undefined behavior. You don't have to worry about this as long as you

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

        See also:

        Parameters

        Returns string

        import { box } from '@traversable/typebox'

        const deepClone = box.deepClone.writeable({
        T.Object({
        street1: T.String(),
        street2: T.Optional(T.String()),
        city: T.String(),
        })
        }, { typeName: 'Type' })

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