Skip to content

Commit

Permalink
feat: implemented javascript beautification function
Browse files Browse the repository at this point in the history
  • Loading branch information
wux1an committed Jun 14, 2023
1 parent d5526b6 commit 9176db0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -34,7 +34,7 @@ go install github.com/wux1an/wxapkg@latest

- [x] scan more information (need networking)
- [x] json beautify
- [ ] javascript beautify
- [x] javascript beautify
- [x] html beautify
- [ ] auto export uri in files

Expand Down
12 changes: 10 additions & 2 deletions cmd/unpack.go
Expand Up @@ -8,6 +8,7 @@ import (
"encoding/binary"
"errors"
"fmt"
"github.com/ditashi/jsbeautifier-go/jsbeautifier"
"github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/tidwall/pretty"
Expand Down Expand Up @@ -198,8 +199,15 @@ func fileBeautify(name string, data []byte) (result []byte) {
switch ext {
case ".json":
result = pretty.Pretty(data)
case ".html":
result = gohtml.FormatBytes(data)
case ".html": // todo beautify js code in html
result = gohtml.FormatBytes(bytes.TrimSpace(data)) // remove leading whitespace
case ".js":
var code = string(bytes.TrimSpace(data)) // remove leading whitespace
options := jsbeautifier.DefaultOptions()
beautify, err := jsbeautifier.Beautify(&code, options)
if err == nil {
result = []byte(beautify)
}
}

return result
Expand Down
1 change: 1 addition & 0 deletions go.mod
Expand Up @@ -18,6 +18,7 @@ require (
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/charmbracelet/harmonica v0.2.0 // indirect
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
github.com/ditashi/jsbeautifier-go v0.0.0-20141206144643-2520a8026a9c // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Expand Up @@ -16,6 +16,8 @@ github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkX
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 h1:q2hJAaP1k2wIvVRd/hEHD7lacgqrCPS+k8g1MndzfWY=
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81/go.mod h1:YynlIjWYF8myEu6sdkwKIvGQq+cOckRm6So2avqoYAk=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/ditashi/jsbeautifier-go v0.0.0-20141206144643-2520a8026a9c h1:+Zo5Ca9GH0RoeVZQKzFJcTLoAixx5s5Gq3pTIS+n354=
github.com/ditashi/jsbeautifier-go v0.0.0-20141206144643-2520a8026a9c/go.mod h1:HJGU9ULdREjOcVGZVPB5s6zYmHi1RxzT71l2wQyLmnE=
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
Expand Down

0 comments on commit 9176db0

Please sign in to comment.