Skip to content

Instantly share code, notes, and snippets.

@Kyure-A
Last active April 4, 2024 12:36
Show Gist options
  • Save Kyure-A/77c197c81d61aa3b1fc0c91cb92592b8 to your computer and use it in GitHub Desktop.
Save Kyure-A/77c197c81d61aa3b1fc0c91cb92592b8 to your computer and use it in GitHub Desktop.
TypeScript の Union を Zod の Union に変換する関数
(require 's)
(require 'cl-lib)
(defun zod-union-from-ts-union (region-start region-end)
(interactive "r")
(let ((str (buffer-substring region-start region-end)))
(insert "z.union([\n")
(delete-region region-start region-end)
(mapcar #'insert (mapcar #'(lambda (x) (s-concat "z.literal(" x "),\n")) (remove-if #'s-blank? (mapcar #'s-trim (s-split "|" str)))))
(insert "])")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment