HTML Script Tag

To use smile-js via the HTML script tag:

<script src="https://cdn.jsdelivr.net/npm/smile-js@0.10.1/dist/smile-js.iife.js"></script>

The module will be exported as windows.smile.

Example

Demo

<!DOCTYPE html>
<html lang="en-US">
<head>
    <title>smile-js test</title>

    <script src="https://cdn.jsdelivr.net/npm/smile-js@0.10.1/dist/smile-js.iife.js"></script>
    <script>
        function onChooseFile(e) {
            const file = e.target.files.item(0)
            file.arrayBuffer()
                .then(arrayBuffer => {
                    const data = new Uint8Array(arrayBuffer);
                    try {
                        const o = window.smile.decode(data);
                        console.log(o);
                        document.getElementById("output").innerText = JSON.stringify(o, null, 2);
                    } catch (e) {
                        alert(e);
                    }
                })
                .catch(e => {
                    alert(e);
                });
        }
    </script>
</head>
<body>
<div>
    <label for="file">Select SMILE-encoded file</label>
    <input id="file" type="file" onchange="onChooseFile(event)"/>
</div>
<div>
    <label for="output">JSON representation:</label>
    <pre id="output"></pre>
</div>
</body>
</html>