Détail du package

exact-mirror

elysiajs135.3kMIT0.1.2

Mirror exact value to TypeBox/OpenAPI model

elysia, exact, mirror, typebox

readme

Exact Mirror

Enforce value to TypeBox/OpenAPI model

By providing model ahead of time, the library will generate a function to mirror a value to an exact type

$ bun benchmarks/small

clk: ~3.13 GHz
cpu: Apple M1 Max
runtime: bun 1.2.4 (arm64-darwin)

summary
  Exact Mirror
   556.23x faster than TypeBox Value.Clean

Installation

# Using either one of the package manager
npm install exact-mirror
yarn add exact-mirror
pnpm add exact-mirror
bun add exact-mirror

Usage

It is designed to be used with TypeBox but an OpenAPI schema should also work.

import { Type as t } from '@sinclair/typebox'
import { createMirror } from 'exact-mirror'

const shape = t.Object({
    name: t.String(),
    id: t.Number()
})

const value = {
    id: 0,
    name: 'saltyaom',
    // @ts-expect-error
    shoudBeRemoved: true
} satisfies typeof shape.static

const mirror = createMirror(shape)

console.log(mirror(value)) // {"id":0,"name":"saltyaom"}

changelog

0.1.2 - 8 May Apr 2025

Feature:

  • add removeUnknownUnionType

0.1.1 - 24 Apr 2025

Bug fix:

  • handle reference of an union in an array

0.1.0 - 24 Apr 2025

Improvement:

  • handle recursion from t.Ref and t.Recursive

0.0.9 - 24 Apr 2025

Bug fix:

  • handle sanitize on top-level string

0.0.8 - 24 Apr 2025

Feature:

  • Add sanitize options

0.0.7 - 22 Apr 2025

Improvement:

  • Use ?. to access undefined property

0.0.6 - 27 Mar 2025

Improvement:

  • Improve array performance by avoiding unnecessary closure reference

0.0.5 - 5 Mar 2025

Feature:

  • support t.Module, t.Ref

0.0.4 - 4 Mar 2025

Bug fix:

  • handle undefined union

0.0.3 - 4 Mar 2025

Bug fix:

  • handle root array

0.0.2 - 4 Mar 2025

Feature:

  • support Record, Tuple, Union

0.0.1 - 4 Mar 2025

Bug fix:

  • incorrect array bracket limit
  • handle deep nested optional object property
  • using pointer instead of created value for

0.0.0 - 4 Mar 2025

Feature:

  • initial release