Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defmacro comment (&rest body) nil)
- (let ((test-element "<SomeComponent objProp={true} stringProp=\"Testing\" otherObjProp={true} otherStringProp=\"testing\" />")
- (replace-spec '(("<\\w+\\s-" . "{\n")
- ("\\s-*\\(\\w+\\)=\"\\(\\w+\\)\"" . "\t\\1: \\2,\n")
- ("\\s-*\\(\\w+\\)={\\(\\w+\\)}" . " \t\\1: \\2,\n")
- ("\\s-*/>" . "}"))))
- (seq-reduce (lambda (str rgx-rpl)
- (s-replace-regexp (car rgx-rpl)
- (cdr rgx-rpl)
- str))
- replace-spec
- test-element))
- (defun user/-spec-reducer (str spec)
- (s-replace-regexp (car spec) (cdr spec) str))
- (defun user/el->prop (start end)
- (interactive "r")
- (let* ((element-str (buffer-substring-no-properties start end))
- (replace-spec '(("<\\w+\\s-" . "{\n")
- ("\\s-*\\(\\w+\\)=\"\\(\\w+\\)\"" . "\t\\1: \\2,\n")
- ("\\s-*\\(\\w+\\)={\\(\\w+\\)}" . " \t\\1: \\2,\n")
- ("\\s-*/>" . "}")))
- (obj-str (seq-reduce #'user/-spec-reducer replace-spec element-str)))
- (message element-str)
- (delete-region start end)
- (insert obj-str)))
- (comment
- (s-replace-regexp "\\s-*\\(\\w+\\)=\"\\(\\w+\\)\""
- " \\1: \\2,"
- "<SomeComponent objProp={true} stringProp=\"Testing\" otherObjProp={true} otherStringProp=\"testing\" />"))
- <SomeComponent objProp={true} stringProp="Testing" otherObjProp={true} otherStringProp="testing" />
- {
- objProp: true,
- stringProp: Testing,
- otherObjProp: true,
- otherStringProp: testing,
- }
- <SomeComponent objProp={true} stringProp="Testing" otherObjProp={true} otherStringProp="testing" />
- <SomeComponent objProp={true} stringProp="Testing" otherObjProp={true} otherStringProp="testing" />
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement