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

@b-flower/bdn-xlsx-drop

v1.1.1

Published

drop file in browser and work with it in browser (optionally click or paste)

Downloads

15

Readme

README

bdn-drop

drop file in browser and work with it on browser (optionally click or paste)

Motivation

Initialy a port of component\drop (too many browserify issues) with addition of filepicker and then adding some browser treatement to be able to read xlsx file. Thanks to file component ...

Steal inspired by component team I've added clipboard capabilities.

Parsing file in browser has been made available with wonderfull xlsx.js project.

Finally, sheetclip comes to me for clipboard parsing.

For instance I have copied all of these components - not using npm :( - because of too many issues with [browserify][8] combination.

Usage

Some html

index.html

<!DOCTYPE html>
<html>
  <head>
   <style>
      body {
        padding: 50px;
      }
      .drop { width: 400px; height: 50px; border: 1px dotted #ddd; }
      .drop:empty:after {
        content: "Click or drag xlsx file ";
        color: #eee;
        font-size: 1.5em;
        text-align: center;
        display: block;
        margin: 10px;
      }

      .drop.over {
        border: 3px dotted #ddd;
      }
    </style>
  </head>
  <body>
    <div id="drop" class="drop"></div>
    <div id="preview"></div>

    <script src="/bundle/bundle.js"></script>
  </body>
</html>

Some javascript

Example below use browserify and make jquery global object (window.$ must be available to use jab-drop)

// test.js
// jquery installed with bower
require('./bower_components/jquery');

var _ = require('lodash');

require('bdn-drop');
require('bdn-drop/parser/xlsx');

var el = document.querySelector('#drop');

// $.jabdrop.parser.xlsx provided by jab-drop/parser/xlsx

var parser = $.bdndrop.parser.xlsx;


$(el).bdndrop({
  callback: processItem
, filter: filterItem
, accept: '.xlsx'
// filepicker make el click opening file dialog selection
, filepicker: true
// paste_on_document make clipboard operation possible
, paste_on_document: true
});


// filter xlsx file
function isXlsxFile(item) {
  return item.kind == 'file' && item.type == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
}


// filter string text/plain only
// copy/paste from excel to browser create 4 items available
//   - image (.png)
//   - string (text/plain)
//   - string (text/html)
//   - string (text/rtf) - but empty (???)
function isStringTextPlain(item) {
  return item.kind == 'string' && item.type == 'text/plain';
}


function filterItem(item) {
  return isXlsxFile(item) || isStringTextPlain(item);
}


function processItem(e) {
  // receive only filtered items
  var item = e.items.length && e.items[0]
    , parse;

  if (!item) return;

  if ( isXlsxFile(item) ) {
    // create fromFile parser
    parse = new parser.fromFile({
        // parser xlsx file options
        // worksheet_filter
        worksheet_filter: function(worksheet) {
          return worksheet.maxRow > 1 && worksheet.maxCol > 1;
        }

      // these options limit result
      // limit the number of cols to return
      , col_limit: 2

      // limit the number of rows to return
      , row_limit: 100


    // these options block process
    // if file size is bigger return error or false to bypass test
    , max_file_size: 400000 // in byte

    // if sheet rows is bigger return error or false to bypass test
    , max_rows: false

    // if sheet cols is bigger return error or false to bypass test
    , max_cols: false
      });
  }

  if ( isStringTextPlain(item) ) {
    // clipboard parser
    // you can receive same options as fromFile but worksheet_filter & max_file_size will be ignored
    parse = parser.fromClipboard({
        col_limit: 2
      , row_limit: 100
      , max_rows: false
      , max_cols: false
      });
  }

  parse && parse.toArray(item, function(err, arr) {
    // once parsed make some stuff with array
    if (!err) processFinalRows(arr);
  });
}



function processFinalRows(rows) {
  var res = _.map(rows, rowToHtml );

  $('#preview').html(['<table>', res.join(''), '</table>'].join(''));
}

function rowToHtml(row) {
  if (!row) return '';
  return '<tr>' +
         _.reduce(row, function(str, col) { return str + '<td>' + col + '</td>'; }, '') +
         '</tr>';
}