Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

html-to-xlsx

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

html-to-xlsx - npm Package Compare versions

Comparing version 0.3.1 to 0.3.2

2

lib/conversion.js

@@ -126,4 +126,2 @@ var path = require("path"),

options.timeout = options.timeout || 10000;
options.numberOfWorkers = options.numberOfWorkers || 2;
options.pathToPhantomScript = options.pathToPhantomScript || path.join(__dirname, "phantomScript.js");
options.tmpDir = options.tmpDir || tmpDir;

@@ -130,0 +128,0 @@ options.strategy = options.strategy || "phantom-server";

2

lib/phantomScript.js

@@ -68,3 +68,3 @@ var system = require('system'),

page.setContent(req.post, "http://localhost");
page.setContent(JSON.parse(req.post), "http://localhost");
});
var Phantom = require("phantom-workers"),
fs = require("fs");
fs = require("fs"),
path = require("path");

@@ -28,2 +29,5 @@ var phantom;

module.exports = function(options, html, id, cb) {
options.numberOfWorkers = options.numberOfWorkers || 2;
options.pathToPhantomScript = options.pathToPhantomScript || path.join(__dirname, "phantomScript.js");
if (!phantom)

@@ -30,0 +34,0 @@ phantom = Phantom(options);

{
"name": "html-to-xlsx",
"version": "0.3.1",
"version": "0.3.2",
"author": {

@@ -5,0 +5,0 @@ "name": "Jan Blaha",

@@ -5,138 +5,153 @@ var should = require("should"),

tmpDir = path.join(__dirname, "temp"),
phantom = require("phantom-workers")({
tmpDir: tmpDir,
numberOfWorkers: 1,
pathToPhantomScript: path.join(__dirname, "../", "lib", "phantomScript.js")
}),
conversion = require("../lib/conversion.js")({
tmpDir: tmpDir,
numberOfWorkers: 1
});
phantomServerStrategy = require("../lib/phantomWebServerStrategy.js"),
dedicatedProcessStrategy = require("../lib/phantomScriptStrategy.js");
describe("html extraction", function () {
beforeEach(function (done) {
phantom.start(function (err) {
if (err)
return done;
options = {
tmpDir: tmpDir
};
done();
});
beforeEach(function() {
rmDir(tmpDir);
})
describe("phantom-server", function() {
common(phantomServerStrategy);
});
afterEach(function () {
phantom.kill();
describe("dedicated-process", function() {
common(dedicatedProcessStrategy);
});
it("should build simple table", function (done) {
phantom.execute("<table><tr><td>1</td></tr></table>", function (err, table) {
if (err)
return cb(err);
function common(strategy) {
it("should build simple table", function (done) {
strategy(options, "<table><tr><td>1</td></tr></table>", "", function (err, table) {
if (err)
return done(err);
table.rows.should.have.length(1);
table.rows[0].should.have.length(1);
table.rows[0][0].value.should.be.eql('1');
done();
table.rows.should.have.length(1);
table.rows[0].should.have.length(1);
table.rows[0][0].value.should.be.eql('1');
done();
});
});
});
it("should parse backgroud color", function (done) {
phantom.execute("<table><tr><td style='background-color:red'>1</td></tr></table>", function (err, table) {
if (err)
return cb(err);
it("should parse backgroud color", function (done) {
strategy(options, "<table><tr><td style='background-color:red'>1</td></tr></table>", "", function (err, table) {
if (err)
return done(err);
table.rows[0][0].backgroundColor[0].should.be.eql('255');
done();
table.rows[0][0].backgroundColor[0].should.be.eql('255');
done();
});
});
});
it("should parse foregorund color", function (done) {
phantom.execute("<table><tr><td style='color:red'>1</td></tr></table>", function (err, table) {
if (err)
return cb(err);
it("should parse foregorund color", function (done) {
strategy(options, "<table><tr><td style='color:red'>1</td></tr></table>", "", function (err, table) {
if (err)
return done(err);
table.rows[0][0].foregroundColor[0].should.be.eql('255');
done();
table.rows[0][0].foregroundColor[0].should.be.eql('255');
done();
});
});
});
it("should parse fontsize", function (done) {
phantom.execute("<table><tr><td style='font-size:19px'>1</td></tr></table>", function (err, table) {
if (err)
return cb(err);
it("should parse fontsize", function (done) {
strategy(options, "<table><tr><td style='font-size:19px'>1</td></tr></table>", "", function (err, table) {
if (err)
return done(err);
table.rows[0][0].fontSize.should.be.eql('19px');
done();
table.rows[0][0].fontSize.should.be.eql('19px');
done();
});
});
});
it("should parse verticalAlign", function (done) {
phantom.execute("<table><tr><td style='vertical-align:bottom'>1</td></tr></table>", function (err, table) {
if (err)
return cb(err);
it("should parse verticalAlign", function (done) {
strategy(options, "<table><tr><td style='vertical-align:bottom'>1</td></tr></table>", "", function (err, table) {
if (err)
return done(err);
table.rows[0][0].verticalAlign.should.be.eql('bottom');
done();
table.rows[0][0].verticalAlign.should.be.eql('bottom');
done();
});
});
});
it("should parse horizontal align", function (done) {
phantom.execute("<table><tr><td style='text-align:left'>1</td></tr></table>", function (err, table) {
if (err)
return cb(err);
it("should parse horizontal align", function (done) {
strategy(options, "<table><tr><td style='text-align:left'>1</td></tr></table>", "", function (err, table) {
if (err)
return done(err);
table.rows[0][0].horizontalAlign.should.be.eql('left');
done();
table.rows[0][0].horizontalAlign.should.be.eql('left');
done();
});
});
});
it("should parse width", function (done) {
phantom.execute("<table><tr><td style='width:19px'>1</td></tr></table>", function (err, table) {
if (err)
return cb(err);
it("should parse width", function (done) {
strategy(options, "<table><tr><td style='width:19px'>1</td></tr></table>", "", function (err, table) {
if (err)
return done(err);
table.rows[0][0].width.should.be.eql.ok;
done();
table.rows[0][0].width.should.be.eql.ok;
done();
});
});
});
it("should parse height", function (done) {
phantom.execute("<table><tr><td style='height:19px'>1</td></tr></table>", function (err, table) {
if (err)
return cb(err);
it("should parse height", function (done) {
strategy(options, "<table><tr><td style='height:19px'>1</td></tr></table>", "", function (err, table) {
if (err)
return done(err);
table.rows[0][0].height.should.be.ok;
done();
table.rows[0][0].height.should.be.ok;
done();
});
});
});
it("should parse border", function (done) {
phantom.execute("<table><tr><td style='border-style:solid;'>1</td></tr></table>", function (err, table) {
if (err)
return cb(err);
it("should parse border", function (done) {
strategy(options, "<table><tr><td style='border-style:solid;'>1</td></tr></table>", "", function (err, table) {
if (err)
return done(err);
table.rows[0][0].border.left.should.be.eql('solid');
table.rows[0][0].border.right.should.be.eql('solid');
table.rows[0][0].border.bottom.should.be.eql('solid');
table.rows[0][0].border.top.should.be.eql('solid');
done();
table.rows[0][0].border.left.should.be.eql('solid');
table.rows[0][0].border.right.should.be.eql('solid');
table.rows[0][0].border.bottom.should.be.eql('solid');
table.rows[0][0].border.top.should.be.eql('solid');
done();
});
});
});
it("should parse backgroud color from styles with line endings", function (done) {
strategy(options, "<style> td { \n background-color: red \n } </style><table><tr><td>1</td></tr></table>", "", function (err, table) {
if (err)
return done(err);
table.rows[0][0].backgroundColor[0].should.be.eql('255');
done();
});
});
}
});
describe("html to xlsx conversion in phantom", function () {
describe("phantom-server", function () {
common("phantom-server");
commonConversion("phantom-server");
});
describe("dedicated-process", function () {
common("dedicated-process");
commonConversion("dedicated-process");
});
function common(strategy) {
function commonConversion(strategyName) {
var conversion;
beforeEach(function () {
rmDir(tmpDir);
conversion.options.strategy = strategy;
conversion = require("../lib/conversion.js")({
tmpDir: tmpDir,
numberOfWorkers: 1,
strategy: strategyName
});
});

@@ -143,0 +158,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc