A website written in Go using WebAssembly and Vugu that converts strings to and from various encodings.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.8 KiB

<div class="container has-text-centered">
<p class="title">
Wasm Hex Converter
</p>
<div vg-if="c.TextToHex">
<textarea vg-content='c.PlainText' @keyup="c.ToHex(event)" placeholder="Plaintext" rows="4" cols="50"></textarea>
<div style="margin-bottom: 0.5rem;"></div>
<textarea vg-content='c.HexString' placeholder="Hex" rows="4" cols="50"></textarea>
</div>
<div vg-if="c.HexToText">
<textarea vg-content='c.HexString' @keyup="c.ToString(event)" placeholder="Hex" rows="4" cols="50"></textarea>
<div style="margin-bottom: 0.5rem;"></div>
<textarea vg-content='c.PlainText' placeholder="Plaintext" rows="4" cols="50"></textarea>
</div>
<a class="button is-light" @click="c.Swap(event)" style="margin-top: 0.5rem;">
<span class="iconify" data-icon="heroicons-solid:refresh"></span>&nbsp;Swap
</a>
</div>
<script type="application/x-go">
import (
"encoding/hex"
)
type Hex struct {
HexString string `vugu:"data"`
PlainText string `vugu:"data"`
TextToHex bool `vugu:"data"`
HexToText bool `vugu:"data"`
}
func (c *Hex) Init() {
c.TextToHex = true
}
func (c *Hex) ToHex(event vugu.DOMEvent) {
plaintext := event.PropString("target", "value")
hexString := hex.EncodeToString([]byte(plaintext))
c.PlainText = plaintext
c.HexString = hexString
}
func (c *Hex) ToString(event vugu.DOMEvent) {
hexString := event.PropString("target", "value")
plain, _ := hex.DecodeString(hexString)
c.PlainText = string(plain)
c.HexString = hexString
}
func (c *Hex) Swap(event vugu.DOMEvent) {
c.TextToHex, c.HexToText = !c.TextToHex, !c.HexToText
}
</script>