npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@senlinz/import-export-wasm

v0.0.1-beta.5

Published

Rust WebAssembly for import/export excel files

Downloads

20

Readme

@senlinz/import-export-wasm

@senlinz/import-export-wasm is the Rust WebAssembly core library for the @senlinz/import-export library. It provides the core logic for handling Excel data in browser environments.

Note: This library is currently in beta. Features and APIs may change.

Features

Usage

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Demo (@senlin/import-export-wasm)</title>
</head>

<button id="downloadTemplate">Download Template</button>
<button id="exportWithData">Export With Data</button>
<button id="importWithData">Import With Data</button>
<a id="download" style="display: none"></a>
<input type="file" accept=".xlsx" id="file" style="display: none">

<body>
    <script type="module">
        import initAsync, { createTemplate, exportData, importData, ExcelInfo, ExcelColumnInfo, ExcelData, ExcelRowData, ExcelColumnData } from 'https://cdn.jsdelivr.net/npm/@senlinz/import-export-wasm/pkg/imexport_wasm.js';
        await initAsync({ path: 'https://cdn.jsdelivr.net/npm/@senlinz/import-export-wasm/pkg/imexport_wasm_bg.wasm' });
        
        const downloadEl = document.getElementById('download');
        const fileEl = document.getElementById('file');

        fileEl.addEventListener('change', fileChange);
        document.getElementById('downloadTemplate').addEventListener('click', downloadTemplate);
        document.getElementById('exportWithData').addEventListener('click', exportWithData);
        document.getElementById('importWithData').addEventListener('click', importWithData);

        const res = await fetch('https://cdn.jsdelivr.net/npm/@senlinz/import-export-wasm/pkg/imexport_wasm_bg.wasm');
        const bytes = await res.arrayBuffer();

        function downloadTemplate() {
            const info = getExcelInfo();
            download(info.name, createTemplate(info));
        }

        function exportWithData() {
            const info = getExcelInfo();
            const data = new ExcelData([
                new ExcelRowData([
                    new ExcelColumnData("name", "Tom"),
                    new ExcelColumnData("age", "12"),
                    new ExcelColumnData("category", "Cat")
                ]),
                new ExcelRowData([
                    new ExcelColumnData("name", "Jerry"),
                    new ExcelColumnData("age", "10"),
                    new ExcelColumnData("category", "Mouse")
                ])
            ]);
            download(info.name, exportData(info, data));
        }

        function importWithData() {
            fileEl.click();
        }

        function fileChange(e) {
            const file = e.target.files[0];
            const reader = new FileReader();
            reader.onload = (e) => {
                const data = new Uint8Array(e.target.result);
                const info = getExcelInfo();
                const excelData = importData(info, data);
                console.log(toJson(excelData));
            };
            reader.readAsArrayBuffer(file);
        }

        function download(name, excelData) {
            const blob = new Blob([excelData], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
            const url = URL.createObjectURL(blob);
            downloadEl.download = `${name}.xlsx`;
            downloadEl.href = url;
            downloadEl.click();
            URL.revokeObjectURL(url);
        }

        function getExcelInfo() {
            const excelName = "TomAndJerry";
            const columns = [
                new ExcelColumnInfo("name", "Name", 20),
                new ExcelColumnInfo("age", "Age"),
                new ExcelColumnInfo("category", "Category")
            ];
            const info = new ExcelInfo(excelName, "sheet1", columns);
            return info;
        }

        function toJson(excelData) {
            const data = [];
            const info = getExcelInfo();
            for (let i = 0; i < excelData.rows.length; i++) {
                const item = {};
                let row = excelData.rows[i];
                for (let j = 0; j < row.columns.length; j++) {
                    let column = row.columns[j];
                    item[column.key] = column.value;
                }
                data.push(item);
            }
            return data;
        }
    </script>
</body>

</html>