-
-
Notifications
You must be signed in to change notification settings - Fork 220
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
Parsing from snake_case to camelCase #981
Comments
Great idea! Thank you for creating this issue. I think this only works in the pipeline of your object. But it will be challenging to get the types right. A package like import { objectToSnake } from 'ts-case-convert';
import * as v from 'valibot';
// With `ts-case-convert`
const Schema = v.pipe(
v.object({ productCount: v.number() }),
v.transform(objectToSnake)
);
// With a `toSnakeCase` action (not implemented yet)
const Schema = v.pipe(
v.object({ productCount: v.number() }),
v.toSnakeCase()
); |
Thanks for the recommendation! The only issue I see when using Screen.Recording.2024-12-19.at.20.06.05.movThat said, how should I implement this for a recursive schema? I'm encountering some issues:
|
Here is an example: import { objectToSnake, ObjectToSnake } from "ts-case-convert";
import * as v from "valibot";
type InputType = {
fooBar: number;
nested: InputType;
};
type OutputType = ObjectToSnake<InputType>;
const Schema: v.GenericSchema<InputType, OutputType> = v.pipe(
v.object({
fooBar: v.number(),
nested: v.lazy(() => Schema),
}),
v.transform(objectToSnake)
);
type Input = v.InferInput<typeof Schema>;
type Output = v.InferOutput<typeof Schema>; |
Probably after v1 is out we will investigate the implementation of a |
Thanks! Works as expected! |
Hey.
Is it possible to define the key for specific entries like
productCount: v.pipe(v.key('product_count'), v.number(), v.integer())
so it would be parsed asproduct_count
intoproductCount
?Or maybe something similar like yup which has camelCase().
The text was updated successfully, but these errors were encountered: