Convert from JS/TS arguments in DFX call to candid arguments

I’ve been looking for a way to parse a JS/TS style dfx call into a candid style call that you would use in the dfx command line for example to convert from

TS:

{ Init: { display_name: "my_name" } }

to Candid:

(variant {Init=record {display_name="my_name"}})

I don’t want to build a parser if one already exists, but I’ve been looking around and haven’t been able to find anything. Would anyone know if there is already a library for doing this? Thanks!

If you know the JS binding of the candid type, you can use this function: agent-js/packages/candid/src/idl.ts at main · dfinity/agent-js · GitHub