Comparing version 1.13.0 to 1.15.0
@@ -236,3 +236,5 @@ --- | ||
| width | The barcode width | N | 200 | ||
| margin | A list of 4 values for the margin | N | 0,0,0,0 | ||
It will use the value of ticket.code to generate the barcode with all the defaults | ||
@@ -247,3 +249,3 @@ | ||
```liquid | ||
{% raw %} {% barcode 1234 code11 50 300 %} {% endraw %} | ||
{% raw %} {% barcode 1234 code11 50 300 20,20,20,0 %} {% endraw %} | ||
``` | ||
@@ -250,0 +252,0 @@ |
{ | ||
"name": "btrz-pdf", | ||
"version": "1.13.0", | ||
"version": "1.15.0", | ||
"description": "Generates pdf documents based on a liquid template", | ||
@@ -30,2 +30,3 @@ "main": "src/index.js", | ||
"pdfmake": "^0.2.4", | ||
"svg-to-pdfkit": "^0.1.8", | ||
"symbology": "^3.0.8", | ||
@@ -32,0 +33,0 @@ "written-number": "^0.11.1" |
@@ -16,2 +16,3 @@ const {SymbologyType, createStream, OutputType} = require("symbology"); | ||
this.width = args[3] || 200; | ||
this.margin = args[4] || "0,0,0,0"; | ||
} catch (err) { | ||
@@ -22,8 +23,7 @@ this.content = "not-content-given"; | ||
this.width = args[3] || 200; | ||
this.margin = args[4] || "0,0,0,0"; | ||
} | ||
}, | ||
render: async function(ctx) { | ||
// console.log(this.content); | ||
let content = await this.liquid.evalValue(this.content, ctx) || this.content; | ||
// console.log("content", content); | ||
let result = await createStream({ | ||
@@ -35,6 +35,18 @@ symbology: getCode(this.type), | ||
}, String(content), OutputType.PNG); | ||
// console.log("RESULT:", result); | ||
let margin = [0,0,0,0]; | ||
try { | ||
margin = this.margin.split(",").map((i) => { | ||
return parseInt(i,10); | ||
}); | ||
if (margin.length !== 4) { | ||
margin = [0,0,0,0]; | ||
} | ||
} catch (err) { | ||
console.log("ERROR:", err); | ||
margin = [0,0,0,0]; | ||
} | ||
return `{ | ||
"image": "${result.data}", | ||
"width": ${this.width || 200} | ||
"width": ${this.width || 200}, | ||
"margin": [${margin.join(",")}] | ||
}`; | ||
@@ -41,0 +53,0 @@ } |
@@ -364,2 +364,31 @@ describe("index.js", () => { | ||
it("should parse barcode", async () => { | ||
const pdf = require("../src/index"); | ||
const template = `{ | ||
"content": [ | ||
{%- barcode -%}, | ||
{%- barcode 1234 code128 10 2 10,5,2,4 -%}, | ||
{%- barcode 1234 code128 10 2 10,5 -%} | ||
] | ||
}`; | ||
const documentDefinition = await pdf.toDocumentDefinition(template, data); | ||
expect(documentDefinition).to.be.eql({ | ||
"content": [ | ||
{ | ||
"image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA3gAAAB4CAYAAACghlDTAAAAAklEQVR4AewaftIAAAPmSURBVO3BsW0EQQwEsJH673mcbnSA8ZlAcpI0H9rmNTN5tc2XmcmrbX4xM/nSNr+Ymbza5jUzebXNl5nJq23+Y2byi7Z5zUxebfOambza5svM5Bdt85qZvNrmy8zk1TZfZiZf2uY1M/mPtvkyM3m1zS9mJq+2ec1MvrTNl5nJq23+Y2byi7Z5zUxebfOamXxpm1/MTF5t85qZvNrmy8zk1TZfZia/aJvXzOTVNl9mJq+2ec1MvrTNl5nJq21+MTP50ja/mJm82uY1M3m1zZeZyattvsxMftE2r5nJq22+zExebfNlZvKlbV4zk/9omy8zk1fbfJmZfGmb18zk1Ta/mJm82uYXM5MvbfOambza5svM5Bdt85qZvNrmy8zk1TZfZiavtnnNTL60zZeZyattfjEz+dI2v5iZvNrmNTN5tc2XmcmXtvkyM/nSNl9mJl/a5jUz+dI2/zEz+Y+2ec1MXm3zmpl82QAAAHDCBgAAgBM2AAAAnLABAADghA0AAAAnbAAAADhhAwAAwAkbAAAATtgAAABwwgYAAIATNgAAAJywAQAA4IQNAAAAJ2wAAAA4YQMAAMAJGwAAAE7YAAAAcMIGAACAEzYAAACcsAEAAOCEDQAAACdsAAAAOGEDAADACRsAAABO2AAAAHDCBgAAgBM2AAAAnLABAADghA0AAAAnbAAAADhhAwAAwAkbAAAATtgAAABwwgYAAIATNgAAAJywAQAA4IQNAAAAJ2wAAAA4YQMAAMAJG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||
"width": 2, | ||
"margin": [10,5,2,4] | ||
},{ | ||
"image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOQAAAAoCAYAAADufVZCAAAAAklEQVR4AewaftIAAADcSURBVO3BsY0EQRDDQKrzz1nvjrXA4R0ZrApQPrTllYRXW74k4Rdt+ZKEV1teSfjSli9J+EVbviTh1ZZfJOHVllcSvrTlF0l4teVLEl5t+ZKE/2jLKwlf2vKLJPyiLa8kvNrySsKXQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMPxSXLk+8Qj8BAAAAAElFTkSuQmCC", | ||
"width": 2, | ||
"margin": [0,0,0,0] | ||
} | ||
] | ||
}); | ||
}); | ||
it("should return a parsed liquidTemplate", async () => { | ||
@@ -381,3 +410,3 @@ const pdf = require("../src/index"); | ||
{%- barcode -%}, | ||
{%- barcode 1234 code128 10 2 2 -%}, | ||
{%- barcode 1234 code128 10 2 10,5,2,4 -%}, | ||
{%- h 'html' -%}, | ||
@@ -410,6 +439,8 @@ "{%- money ticket total -%}", | ||
"image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA3gAAAB4CAYAAACghlDTAAAAAklEQVR4AewaftIAAAPmSURBVO3BsW0EQQwEsJH673mcbnSA8ZlAcpI0H9rmNTN5tc2XmcmrbX4xM/nSNr+Ymbza5jUzebXNl5nJq23+Y2byi7Z5zUxebfOambza5svM5Bdt85qZvNrmy8zk1TZfZiZf2uY1M/mPtvkyM3m1zS9mJq+2ec1MvrTNl5nJq23+Y2byi7Z5zUxebfOamXxpm1/MTF5t85qZvNrmy8zk1TZfZia/aJvXzOTVNl9mJq+2ec1MvrTNl5nJq21+MTP50ja/mJm82uY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
"width": 200, | ||
"margin": [0,0,0,0] | ||
},{ | ||
"image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOQAAAAoCAYAAADufVZCAAAAAklEQVR4AewaftIAAADcSURBVO3BsY0EQRDDQKrzz1nvjrXA4R0ZrApQPrTllYRXW74k4Rdt+ZKEV1teSfjSli9J+EVbviTh1ZZfJOHVllcSvrTlF0l4teVLEl5t+ZKE/2jLKwlf2vKLJPyiLa8kvNrySsKXQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMQ9KMPxSXLk+8Qj8BAAAAAElFTkSuQmCC", | ||
"width": 2 | ||
"width": 2, | ||
"margin": [10,5,2,4] | ||
},{"style": "header", "text": "Hello"},{"text": ""},{"text": "something"},{"text": ""},{"bold": true, "text": "html"},{"text": ""},{"italics": true, "text": "Italix"}, | ||
@@ -416,0 +447,0 @@ "28.36", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
65569
1336
9
3
+ Addedsvg-to-pdfkit@^0.1.8
+ Added@swc/helpers@0.3.17(transitive)
+ Addedarray-buffer-byte-length@1.0.1(transitive)
+ Addedavailable-typed-arrays@1.0.7(transitive)
+ Addedbase64-js@0.0.8(transitive)
+ Addedclone@2.1.2(transitive)
+ Addeddeep-equal@2.2.3(transitive)
+ Addedes-get-iterator@1.1.3(transitive)
+ Addedfontkit@1.9.0(transitive)
+ Addedfor-each@0.3.3(transitive)
+ Addedhas-bigints@1.0.2(transitive)
+ Addedinternal-slot@1.0.7(transitive)
+ Addedis-array-buffer@3.0.4(transitive)
+ Addedis-bigint@1.0.4(transitive)
+ Addedis-boolean-object@1.1.2(transitive)
+ Addedis-callable@1.2.7(transitive)
+ Addedis-map@2.0.3(transitive)
+ Addedis-number-object@1.0.7(transitive)
+ Addedis-set@2.0.3(transitive)
+ Addedis-shared-array-buffer@1.0.3(transitive)
+ Addedis-string@1.0.7(transitive)
+ Addedis-symbol@1.0.4(transitive)
+ Addedis-weakmap@2.0.2(transitive)
+ Addedis-weakset@2.0.3(transitive)
+ Addedisarray@2.0.5(transitive)
+ Addedlinebreak@1.1.0(transitive)
+ Addedobject-inspect@1.13.3(transitive)
+ Addedobject.assign@4.1.5(transitive)
+ Addedpdfkit@0.15.1(transitive)
+ Addedpossible-typed-array-names@1.0.0(transitive)
+ Addedrestructure@2.0.1(transitive)
+ Addedside-channel@1.0.6(transitive)
+ Addedstop-iteration-iterator@1.0.0(transitive)
+ Addedsvg-to-pdfkit@0.1.8(transitive)
+ Addedtslib@2.8.1(transitive)
+ Addedwhich-boxed-primitive@1.0.2(transitive)
+ Addedwhich-collection@1.0.2(transitive)
+ Addedwhich-typed-array@1.1.15(transitive)