Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add replacer option to serializerCompiler #112

Merged
merged 6 commits into from
Sep 25, 2024

Conversation

Bram-dc
Copy link
Contributor

@Bram-dc Bram-dc commented Sep 25, 2024

This is my final addition to the type provider. I use this to serialize dates like this:

import { createSerializerCompiler } from 'fastify-type-provider-zod'

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function replacer(this: any, key: string, value: any) {
    if (this[key] instanceof Date) {
        return {
            _type: 'date',
            value,
        }
    }
    return value
}

export const serializerCompiler = createSerializerCompiler({ replacer })

src/core.ts Show resolved Hide resolved
README.md Show resolved Hide resolved
@kibertoad kibertoad merged commit 0f71161 into turkerdev:main Sep 25, 2024
6 checks passed
@kibertoad
Copy link
Collaborator

Thank you so much! I'll release 3.0.0 later today

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants