Skip to content

Commit

Permalink
🚸 Add placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
williamchong committed Jun 28, 2024
1 parent f8b1299 commit 3b41fb5
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
</select>
</div>
</div>
<textarea id="cbor-value" @input="cborToJson" v-model="cborValue" />
<textarea id="cbor-value" @input="cborToJson" v-model="cborValue" :placeholder="cborPlaceHolder" />
</div>
<div style="flex: 1">
<label for="json-value">JSON</label>
<br />
<textarea id="json-value" @input="jsonToCbor" v-model="jsonValue" />
<textarea id="json-value" @input="jsonToCbor" v-model="jsonValue" :placeholder="jsonPlaceHolder" />
</div>
</section>
</div>
Expand All @@ -30,14 +30,17 @@ import { decode, encode } from 'cbor-x';
import { Buffer } from 'node:buffer'
const cborValue = ref('')
const jsonValue = ref(JSON.stringify({
const jsonValue = ref('')
const cborEncoding = ref('base64' as BufferEncoding)
const jsonPlaceHolder = JSON.stringify({
hello: 'world',
array: [1, 2, 3],
nested: {
key: 'value'
}
}))
const cborEncoding = ref('base64' as BufferEncoding)
})
const cborPlaceHolder = computed(() => Buffer.from(jsonPlaceHolder).toString(cborEncoding.value))
onMounted(() => {
jsonToCbor()
Expand All @@ -61,6 +64,10 @@ function cborToJson() {
function jsonToCbor() {
try {
if (!jsonValue.value) {
cborValue.value = ''
return
}
const cbor = encode(JSON.parse(jsonValue.value))
cborValue.value = Buffer.from(cbor).toString(cborEncoding.value)
} catch (e) {
Expand Down

0 comments on commit 3b41fb5

Please sign in to comment.