Last active
April 4, 2024 12:36
-
-
Save Kyure-A/77c197c81d61aa3b1fc0c91cb92592b8 to your computer and use it in GitHub Desktop.
TypeScript の Union を Zod の Union に変換する関数
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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