Skip to content

Commit

Permalink
Merge e6826dc into 87d5b15
Browse files Browse the repository at this point in the history
  • Loading branch information
hildjj committed Mar 29, 2021
2 parents 87d5b15 + e6826dc commit 60d7c7d
Show file tree
Hide file tree
Showing 15 changed files with 686 additions and 415 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ yarn-error.log
*.dSYM/
src/cbor-cli
src/library.wat
d.js
41 changes: 32 additions & 9 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,18 @@
body {
font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
}
#result {
.computed {
font-weight: bold;
}
.error {
color: red;
}
</style>
<script src='https://unpkg.com/node-inspect-extracted@1.0.4/dist/inspect.js'></script>
<script>
let d = null
<script type='module'>
import {Decoder, Diagnose} from '../lib/cbor.mjs'
async function main() {
const cbor = await import('../lib/cbor.mjs')
d = new cbor.Decoder((er, val) => {
const d = new Decoder((er, val) => {
const r = document.querySelector('#result')
if (er) {
r.classList.add('error')
Expand All @@ -32,17 +31,41 @@
r.innerText = util.inspect(val, {depth: Infinity})
}
})
const diag = new Diagnose((er, val) => {
const r = document.querySelector('#diag')
if (er) {
r.classList.add('error')
r.innerText = er.message
} else {
r.classList.remove('error')
r.innerText += val
}
})
await d.init()
await diag.init()

const button = document.querySelector('#decode')
button.onclick = () => {
document.querySelector('#result').innerText = ''
document.querySelector('#diag').innerText = ''
const txt = document.querySelector('#input').value
d.write(txt)
diag.write(txt)
}
button.disabled = false
}
main().catch(console.error)
window.addEventListener('load', main)
</script>
<body>
<div>
<input type="text" id='input' value='fb3ff3333333333333'>
<input type="button" value='decode' onclick="d.write(document.querySelector('#input').value)">
<input type=text id=input value='fb3ff3333333333333'>
<input type=button id=decode value=decode disabled=true autocomplete=off>
</div>
<div>
Result: <span id=result class=computed></span>
</div>
<div>
Result: <span id='result'></span>
Diagnostic: <span id=diag class=computed></span>
</div>
</body>
</html>

0 comments on commit 60d7c7d

Please sign in to comment.