New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

pdfmake

Package Overview
Dependencies
Maintainers
4
Versions
103
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pdfmake - npm Package Compare versions

Comparing version 0.1.66 to 0.1.67

5

package.json
{
"name": "pdfmake",
"version": "0.1.66",
"version": "0.1.67",
"description": "Client/server side PDF printing in pure JavaScript",

@@ -14,3 +14,4 @@ "main": "src/printer.js",

"pdfkit": "^0.11.0",
"svg-to-pdfkit": "^0.1.8"
"svg-to-pdfkit": "^0.1.8",
"xmldoc": "^1.1.2"
},

@@ -17,0 +18,0 @@ "devDependencies": {

@@ -70,2 +70,10 @@ 'use strict';

if (this.docDefinition.images) {
for (var image in this.docDefinition.images) {
if (this.docDefinition.images.hasOwnProperty(image)) {
urlResolver.resolve(this.docDefinition.images[image]);
}
}
}
var _this = this;

@@ -72,0 +80,0 @@

124

src/browser-extensions/URLBrowserResolver.js
'use strict';
// Internet Explorer polyfills
require('core-js/features/promise');
if (window && !window.Promise) {
require('core-js/features/promise');
}
require('core-js/es/object/values');
var fetchUrl = function (url) {
return new Promise(function (resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'arraybuffer';
return new Promise(function (resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'arraybuffer';
xhr.onreadystatechange = function () {
if (xhr.readyState !== 4) {
return;
}
xhr.onreadystatechange = function () {
if (xhr.readyState !== 4) {
return;
}
var ok = xhr.status >= 200 && xhr.status < 300;
if (!ok) {
setTimeout(function () {
reject(new TypeError('Failed to fetch (url: "' + url + '")'));
}, 0);
}
};
var ok = xhr.status >= 200 && xhr.status < 300;
if (!ok) {
setTimeout(function () {
reject(new TypeError('Failed to fetch (url: "' + url + '")'));
}, 0);
}
};
xhr.onload = function () {
var ok = xhr.status >= 200 && xhr.status < 300;
if (ok) {
resolve(xhr.response);
}
};
xhr.onload = function () {
var ok = xhr.status >= 200 && xhr.status < 300;
if (ok) {
resolve(xhr.response);
}
};
xhr.onerror = function () {
setTimeout(function () {
reject(new TypeError('Network request failed (url: "' + url + '")'));
}, 0);
};
xhr.onerror = function () {
setTimeout(function () {
reject(new TypeError('Network request failed (url: "' + url + '")'));
}, 0);
};
xhr.ontimeout = function () {
setTimeout(function () {
reject(new TypeError('Network request failed (url: "' + url + '")'));
}, 0);
};
xhr.ontimeout = function () {
setTimeout(function () {
reject(new TypeError('Network request failed (url: "' + url + '")'));
}, 0);
};
xhr.send();
});
xhr.send();
});
};
function URLBrowserResolver(fs) {
this.fs = fs;
this.resolving = {};
this.fs = fs;
this.resolving = {};
}
URLBrowserResolver.prototype.resolve = function (url) {
if (!this.resolving[url]) {
var _this = this;
this.resolving[url] = new Promise(function (resolve, reject) {
if (url.toLowerCase().indexOf('https://') === 0 || url.toLowerCase().indexOf('http://') === 0) {
fetchUrl(url).then(function (buffer) {
_this.fs.writeFileSync(url, buffer);
resolve();
}, function (result) {
reject(result);
});
} else {
// cannot be resolved
resolve();
}
});
}
if (!this.resolving[url]) {
var _this = this;
this.resolving[url] = new Promise(function (resolve, reject) {
if (url.toLowerCase().indexOf('https://') === 0 || url.toLowerCase().indexOf('http://') === 0) {
fetchUrl(url).then(function (buffer) {
_this.fs.writeFileSync(url, buffer);
resolve();
}, function (result) {
reject(result);
});
} else {
// cannot be resolved
resolve();
}
});
}
return this.resolving[url];
return this.resolving[url];
}
URLBrowserResolver.prototype.resolved = function () {
var _this = this;
return new Promise(function (resolve, reject) {
Promise.all(Object.values(_this.resolving)).then(function () {
resolve();
}, function (result) {
reject(result);
});
});
var _this = this;
return new Promise(function (resolve, reject) {
Promise.all(Object.values(_this.resolving)).then(function () {
resolve();
}, function (result) {
reject(result);
});
});
}
module.exports = URLBrowserResolver;

@@ -8,2 +8,8 @@ 'use strict';

VirtualFileSystem.prototype.existsSync = function (filename) {
filename = fixFilename(filename);
return typeof this.fileSystem[filename] !== 'undefined'
|| typeof this.dataSystem[filename] !== 'undefined';
}
VirtualFileSystem.prototype.readFileSync = function (filename, options) {

@@ -10,0 +16,0 @@ filename = fixFilename(filename);

'use strict';
var fs = require('fs');
function ImageMeasure(pdfKitDoc, imageDictionary) {

@@ -36,2 +38,6 @@ this.pdfKitDoc = pdfKitDoc;

if (fs.existsSync(img)) {
return fs.readFileSync(img);
}
var index = img.indexOf('base64,');

@@ -38,0 +44,0 @@ if (index < 0) {

'use strict';
function SVGMeasure() {
var xmldoc = require('xmldoc');
/** Strip unit postfix, parse number, but return undefined instead of NaN for bad input */
function stripUnits(textVal) {
var n = parseFloat(textVal);
if (typeof n !== 'number' || isNaN(n)) {
return undefined;
}
return n;
}
SVGMeasure.prototype.getSVGNode = function (svgString) {
// remove newlines
svgString = svgString.replace(/\r?\n|\r/g, "");
/** Make sure it's valid XML and the root tage is <svg/>, returns xmldoc DOM */
function parseSVG(svgString) {
var doc;
try {
doc = new xmldoc.XmlDocument(svgString);
} catch (err) {
throw new Error('SVGMeasure: ' + err);
}
var svgNodeMatches = svgString.match(/<svg(.*?)>/);
if (svgNodeMatches) {
// extract svg node <svg ... >
return svgNodeMatches[0];
if (doc.name !== "svg") {
throw new Error('SVGMeasure: expected <svg> document');
}
return "";
};
return doc;
}
SVGMeasure.prototype.getHeightAndWidth = function (svgString) {
var svgNode = this.getSVGNode(svgString);
function SVGMeasure() {
}
var widthMatches = svgNode.match(/width="([0-9]+(\.[0-9]+)?)(em|ex|px|in|cm|mm|pt|pc|%)?"/);
var heightMatches = svgNode.match(/height="([0-9]+(\.[0-9]+)?)(em|ex|px|in|cm|mm|pt|pc|%)?"/);
SVGMeasure.prototype.measureSVG = function (svgString) {
if (widthMatches || heightMatches) {
return {
width: widthMatches ? +widthMatches[1] : undefined,
height: heightMatches ? +heightMatches[1] : undefined
};
}
};
var doc = parseSVG(svgString);
SVGMeasure.prototype.getViewboxHeightAndWidth = function (svgString) {
var svgNode = this.getSVGNode(svgString);
var docWidth = stripUnits(doc.attr.width);
var docHeight = stripUnits(doc.attr.height);
var viewboxMatches = svgNode.match(/viewBox="([+-]?(\d*\.)?\d+(,|\s+|,\s+)[+-]?(\d*\.)?\d+(,|\s+|,\s+)[+-]?(\d*\.)?\d+(,|\s+|,\s+)[+-]?(\d*\.)?\d+)"/);
if (viewboxMatches) {
var viewboxStr = viewboxMatches[1];
var allVieboxEntries = viewboxStr.split(" ");
var viewboxEntries = []; // weeding out empty strings
for (var i = 0; i < allVieboxEntries.length; i++) {
if (allVieboxEntries[i]) {
viewboxEntries.push(allVieboxEntries[i]);
}
if ((docWidth == undefined || docHeight == undefined) && typeof doc.attr.viewBox == 'string') {
var viewBoxParts = doc.attr.viewBox.split(/[,\s]+/);
if (viewBoxParts.length !== 4) {
throw new Error("Unexpected svg viewbox format, should have 4 entries but found: '" + doc.attr.viewBox + "'");
}
if (viewboxEntries.length === 4) {
return { width: +viewboxEntries[2], height: +viewboxEntries[3] };
if (docWidth == undefined) {
docWidth = stripUnits(viewBoxParts[2]);
}
throw new Error("Unexpected svg viewbox format, should have 4 entries but found: '" + viewboxStr + "'");
if (docHeight == undefined) {
docHeight = stripUnits(viewBoxParts[3]);
}
}
};
SVGMeasure.prototype.measureSVG = function (svgString) {
var heightAndWidth = this.getHeightAndWidth(svgString);
var viewboxHeightAndWidth = this.getViewboxHeightAndWidth(svgString);
return heightAndWidth || viewboxHeightAndWidth || {};
return {
width: docWidth,
height: docHeight
};
};

@@ -67,41 +62,10 @@

var svgNode = this.getSVGNode(svgString);
var doc = parseSVG(svgString);
if (svgNode) {
doc.attr.width = "" + dimensions.width;
doc.attr.height = "" + dimensions.height;
var nodeDimensions = this.getHeightAndWidth(svgString);
if (dimensions.width) {
var newWidth = 'width="' + dimensions.width + '"';
if (nodeDimensions && nodeDimensions.width) {
// replace existing width
svgNode = svgNode.replace(/width="[0-9]+(\.[0-9]+)?(em|ex|px|in|cm|mm|pt|pc|%)?"/, newWidth);
} else {
// insert new width
svgNode = svgNode.replace(">", " " + newWidth + ">");
}
}
if (dimensions.height) {
var newHeight = 'height="' + dimensions.height + '"';
if (nodeDimensions && nodeDimensions.height) {
// replace existing height
svgNode = svgNode.replace(/height="[0-9]+(\.[0-9]+)?(em|ex|px|in|cm|mm|pt|pc|%)?"/, newHeight);
} else {
// insert new height
svgNode = svgNode.replace(">", " " + newHeight + ">");
}
}
// insert updated svg node
return svgString.replace(/<svg(.*?)>/, svgNode);
}
return svgString;
return doc.toString();
};
module.exports = SVGMeasure;

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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