diff --git a/README.md b/README.md index eca95d4..839f585 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,8 @@ jwt-decode=# | date-to-timestamp, d2t | Covert date to unix timestamp | | jwt-decode | Decode [JWT](https://jwt.io/) | | md5 | Computes the checksum | +| url-encode | Encode url | +| url-decode | Decode url | | rand-string | Generate random string of given length (characters: a-z, A-Z, 0-9) | | count | Get the characters length | | camel-case | Coverts string to [camel case](https://en.wikipedia.org/wiki/Camel_case) | diff --git a/cmd/root.go b/cmd/root.go index 539aba2..4238af2 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -34,6 +34,8 @@ func commands() []*cobra.Command { dateToTimestampCmd, jwtDecodeCmd, md5Cmd, + urlEncodeCmd, + urlDecodeCmd, randStringCmd, countCmd, CamelCaseCmd, diff --git a/cmd/url.go b/cmd/url.go new file mode 100644 index 0000000..efc2ebc --- /dev/null +++ b/cmd/url.go @@ -0,0 +1,32 @@ +package cmd + +import ( + "fmt" + "net/url" + + "github.com/spf13/cobra" +) + +var urlEncodeCmd = &cobra.Command{ + Use: "url-encode [text]", + Short: "Encode url", + Args: cobra.ExactArgs(1), + DisableFlagsInUseLine: true, + Run: func(cmd *cobra.Command, args []string) { + fmt.Println(url.QueryEscape(args[0])) + }, +} + +var urlDecodeCmd = &cobra.Command{ + Use: "url-decode [text]", + Short: "Decode url", + Args: cobra.ExactArgs(1), + DisableFlagsInUseLine: true, + Run: func(cmd *cobra.Command, args []string) { + s, err := url.QueryUnescape(args[0]) + if err != nil { + fmt.Println("Invalid query") + } + fmt.Println(s) + }, +}