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

csv-paster

v2.0.5

Published

csv paster is a library that allows to paste excel/csv format data into a html table on multiple input's such as checkbox,radio and select.

Downloads

27

Readme

CSV Paster

csv paster is a library that allows to paste excel/csv format data into a html table on multiple input's such as normal input,checkbox,radio and select.

Packages: https://www.npmjs.com/package/csv-paster

Demo: https://birajmainali.github.io/csv-paster/

Preview

https://www.loom.com/share/c6952f01cac34e7cbaf0b6fcd751835d

Installation

npm

npm i csv-paster

Yarn

yarn add csv-paster
  • inject import "csv-paster/csv-paster";
  1. table must have id csv
  2. add data-header attribute on table header with corresponded object key, to get after pasting the data, paster dispatch the event pasteComplete with lastest change table data object array, for that we need to add data-header.

Example for header configuration

<thead class="bg-warning">
      <tr>
      <th data-header="barcode">Barcode</th>
      <th data-header="product">Product</th>
      <th data-header="unit">Unit</th>
      <th data-header="quantity">Quantity</th>
      <th data-header="rate">Rate</th>
      <th data-header="Discount">Discount</th>
      </tr>
   </thead>

Estimated Result.

[
   {
      "barcode": "90239209302",
      "product": "1",
      "unit": "Pcs",
      "quantity": "10",
      "rate": "150",
      "Discount": "30"
   }
]
  1. add class skip-paste to skip the paste.
  2. add class watch to get the updated rows from event, if we missed class watch this does not tack the changes occured by the lastest paste, for e.g. we have an input field named barcode. if the barcode changed we might fetch product from server according to barcode, in this case we need to tack the newly updated barcode to fetch the product, in this case we need to track the newly updated barcode to fetch the product
  3. add class watch on td element we can ensure current row is watchable or not.

Custom Helping Events

  1. OnRows, This event fired when the users paste the csv content into a table. In some cases initially table may not have a avliable rows to paste. so we need handle rows by catching this event manually.

  2. pasteComplete, This event after pasting the data. this gives the lastest changed paste content. to track the latest change we need to add class watch otherwise paster just paste the without providing the changes.

Usages

const __ = document.querySelector.bind(document);
const tableElem = __('#csv');


document.addEventListener("DOMContentLoaded", cloneRow);

// this event gives the row count of pasting item, so that we can manage the unavailable rows like below.
tableElem.addEventListener("onRows", async (ev) => {
    for (let i = 0; i < ev.detail; i++) {
        cloneRow();
    }
});

// This event gives the latest change items, which is indicated by the watch
tableElem.addEventListener("pasteComplete", (ev) => {
    console.log(ev.detail);
});

function cloneRow() {
    const rowTemplate = __("#rowTemplate");
    const tbody = __("tbody");
    const row = rowTemplate.content.cloneNode(true);
    tbody.appendChild(row);
};