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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

56 lines
1.8 KiB

<div class="container has-text-centered">
<p class="title">
Wasm Base64 Converter
</p>
<div vg-if="c.TextToB64">
<textarea vg-content='c.PlainText' @keyup="c.ToB64(event)" placeholder="Plaintext" rows="4" cols="50"></textarea>
<div style="margin-bottom: 0.5rem;"></div>
<textarea vg-content='c.B64String' placeholder="Base64" rows="4" cols="50"></textarea>
</div>
<div vg-if="c.B64ToText">
<textarea vg-content='c.B64String' @keyup="c.ToString(event)" placeholder="Base64" 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/base64"
)
type Base64 struct {
B64String string `vugu:"data"`
PlainText string `vugu:"data"`
TextToB64 bool `vugu:"data"`
B64ToText bool `vugu:"data"`
}
func (c *Base64) Init() {
c.TextToB64 = true
}
func (c *Base64) ToB64(event vugu.DOMEvent) {
plaintext := event.PropString("target", "value")
b64String := base64.StdEncoding.EncodeToString([]byte(plaintext))
c.PlainText = plaintext
c.B64String = b64String
}
func (c *Base64) ToString(event vugu.DOMEvent) {
b64String := event.PropString("target", "value")
plain, _ := base64.StdEncoding.DecodeString(b64String)
c.PlainText = string(plain)
c.B64String = b64String
}
func (c *Base64) Swap(event vugu.DOMEvent) {
c.TextToB64, c.B64ToText = !c.TextToB64, !c.B64ToText
}
</script>