Skip to content
Discussion options

You must be logged in to vote

A solution could be the following:

const schema = z.string().transform((val) => {
  const args = val.split("&");

  if (args.length === 0) {
    return null;
  }

  const map: Record<string, any> = {};
  const s = z.object({
    shipmentDate: z.object({
      gte: z.string(),
      lte: z.string(),
    }),
  });

  for (const arg of args) {
    const [name, value] = arg.split("=");
    if (name.match(/[a-zA-Z]*\[[a-zA-Z]*\]/)) {
      let [lonelyName, x] = name.split("[");
      x = x.split("]")[0];

      if (lonelyName in map) {
        map[lonelyName][x] = value;
      } else {
        map[lonelyName] = {
          [x]: value,
        };
      }
    } else {
      return null;
    }
  }

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@vresetnikov
Comment options

@nullndr
Comment options

@vresetnikov
Comment options

Answer selected by vresetnikov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants