btrz-liquid-templates 1.9.0 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +12 -14
- package/test/index-test.js +46 -23
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "btrz-liquid-templates",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"description": "Extension and helpers for liquid templates to deal with our data and other things we need to encapsulate",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"tdd": "
|
|
8
|
-
"test": "
|
|
7
|
+
"tdd": "node --test --watch test/index-test.js",
|
|
8
|
+
"test": "node --test test/index-test.js",
|
|
9
9
|
"preversion": "npm test",
|
|
10
10
|
"postversion": "git push origin main && git push --tags",
|
|
11
11
|
"version": "git tag $1"
|
|
@@ -21,19 +21,17 @@
|
|
|
21
21
|
},
|
|
22
22
|
"homepage": "https://github.com/Betterez/btrz-liquid-templates#readme",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"axios": "
|
|
25
|
-
"btrz-formatter": "1.
|
|
26
|
-
"bz-date": "2.
|
|
27
|
-
"liquidjs": "
|
|
28
|
-
"moment": "
|
|
29
|
-
"moment-timezone": "
|
|
30
|
-
"symbology": "4.0.
|
|
31
|
-
"written-number": "
|
|
24
|
+
"axios": "1.15.2",
|
|
25
|
+
"btrz-formatter": "1.4.0",
|
|
26
|
+
"bz-date": "2.1.0",
|
|
27
|
+
"liquidjs": "10.25.6",
|
|
28
|
+
"moment": "2.30.1",
|
|
29
|
+
"moment-timezone": "0.6.1",
|
|
30
|
+
"symbology": "4.0.2",
|
|
31
|
+
"written-number": "0.11.1"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"browserify": "
|
|
35
|
-
"chai": "4.3.10",
|
|
36
|
-
"mocha": "11.1.0",
|
|
34
|
+
"browserify": "17.0.1",
|
|
37
35
|
"tinyify": "4.0.0"
|
|
38
36
|
}
|
|
39
37
|
}
|
package/test/index-test.js
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
|
+
const assert = require("node:assert/strict");
|
|
2
|
+
const {describe, it, beforeEach, afterEach} = require("node:test");
|
|
3
|
+
const http = require("node:http");
|
|
4
|
+
const https = require("node:https");
|
|
5
|
+
|
|
6
|
+
function closeAgentSockets(agent) {
|
|
7
|
+
for (const sockets of Object.values(agent.sockets)) {
|
|
8
|
+
for (const socket of sockets) {
|
|
9
|
+
socket.destroy();
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
for (const sockets of Object.values(agent.freeSockets)) {
|
|
14
|
+
for (const socket of sockets) {
|
|
15
|
+
socket.destroy();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
1
20
|
describe("index.js", () => {
|
|
2
|
-
const {expect} = require("chai");
|
|
3
21
|
let data = null;
|
|
4
22
|
beforeEach(() => {
|
|
5
23
|
data = {
|
|
@@ -179,6 +197,11 @@ and some more here`,
|
|
|
179
197
|
}
|
|
180
198
|
});
|
|
181
199
|
|
|
200
|
+
afterEach(() => {
|
|
201
|
+
closeAgentSockets(http.globalAgent);
|
|
202
|
+
closeAgentSockets(https.globalAgent);
|
|
203
|
+
});
|
|
204
|
+
|
|
182
205
|
it("should load images via https", async () => {
|
|
183
206
|
const tpl = require("../src/index");
|
|
184
207
|
const template = `{
|
|
@@ -189,7 +212,7 @@ and some more here`,
|
|
|
189
212
|
]
|
|
190
213
|
}`;
|
|
191
214
|
const documentDefinition = await tpl.processToObj(template, data);
|
|
192
|
-
|
|
215
|
+
assert.deepStrictEqual(documentDefinition, {
|
|
193
216
|
"content": [
|
|
194
217
|
{
|
|
195
218
|
"image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPoAAAAeBAMAAAD3Fx6aAAAAG1BMVEX///8/nz9fr1/f79+/379/v3+fz58fjx8AgADFQF6MAAAAAXRSTlMAQObYZgAAAAlwSFlzAAAOxAAADsQBlSsOGwAAApBJREFUSInFlj1v2zAQhmlTtjsabYBq9BAEHtUP2BrVoGg1esigUUGGenRSwNBYx0l0P7u8O1I6Sg0a0DbMgZZeyfdQ5PHlKfVKq4BbXXaf6Dhr+lM1R4fn7pMcsqY/OR3KzpOCuMWJ6Rj9yzXA5mx0nOGXM9KHsDsjPYKafhcf4aHs0/VtVV+5/3yuLrrSgXTN9JHbfRFl4lfqExyEaVt8I4fv5nImpLHL2zqYHvHMx273+fQBh18R/SfRW+kI9CFteBvSxPTpcesJOeBNJqQj0HPYK5zN+k4tKnjy6WY9ton+hVDzImz1rRJSQ+/m7Vvp+prmUPPkjiiOyLqUnbCAKdJrkweexG0NvwPotj0S9pHEOSIFvcAsw9V5aoxBStTGPKpAOn70gKYfCSuPHgMFjvB7eYk8idq6GUcI/dLcvLPzSL+C7lYUf3O2ZCnxMEJsqT1lZpRRtv2R9KiRAd+ZKuVL2PpO/TY6MvSPGJd8/W/62KebYfoSBqho6cLoFK4U9P0r9KRPp/Vf2nwNpBvMJpxuPn12ED01xLWcPkkXhY+je7XQMsBpPPrEpE3eeoefdSI20yMfFwc4TY+eYrb16doldkv3JOMTAU7j0VPjFhO7bZZXibffKy769MOdo3uS8cZ9EFxm3d44LX9DjI7iOS1N7ABPMUuX0jDIaSTdJPEU5/ODomjktKWyfQo7HNWcnZboUipCTFbSFzGNfw5wgycsntR8ZlFvhvOc4XG6aehCGoWuunRatIuJvcZvMbZbJ7Z3b2UNXUipNOtQOm42bSuWUikKmtn+E8svqqW30jHoVDJyVQkX7nJley4hd5mgt9LB9Pr+xt6bivr+ki+/VVjcco/l83uEt/RG+j/9L0R48odC2pi1AAAAAElFTkSuQmCC"
|
|
@@ -209,7 +232,7 @@ and some more here`,
|
|
|
209
232
|
]
|
|
210
233
|
}`;
|
|
211
234
|
const documentDefinition = await tpl.processToObj(template, data);
|
|
212
|
-
|
|
235
|
+
assert.deepStrictEqual(documentDefinition, {
|
|
213
236
|
"content": [
|
|
214
237
|
{
|
|
215
238
|
"image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAH0lEQVR42mP8P4PhPwMVAeOogaMGjho4auCogSPVQACqOzPNQ/wwqAAAAABJRU5ErkJggg=="
|
|
@@ -228,7 +251,7 @@ and some more here`,
|
|
|
228
251
|
]
|
|
229
252
|
}`;
|
|
230
253
|
const documentDefinition = await tpl.processToObj(template, data);
|
|
231
|
-
|
|
254
|
+
assert.deepStrictEqual(documentDefinition, {
|
|
232
255
|
"content": [
|
|
233
256
|
"DATE / HEURE D'ARRIVÉE:",
|
|
234
257
|
"THIS `` IS `` AWESOME",
|
|
@@ -254,7 +277,7 @@ and some more here`,
|
|
|
254
277
|
data.ticket.total = 0;
|
|
255
278
|
data.ticket.ssrs[0].subTotal = 0;
|
|
256
279
|
const documentDefinition = await tpl.processToObj(template, data);
|
|
257
|
-
|
|
280
|
+
assert.deepStrictEqual(documentDefinition, {
|
|
258
281
|
"content": [
|
|
259
282
|
"Q",
|
|
260
283
|
"GTQ",
|
|
@@ -282,7 +305,7 @@ and some more here`,
|
|
|
282
305
|
]
|
|
283
306
|
}`;
|
|
284
307
|
const documentDefinition = await tpl.processToObj(template, data);
|
|
285
|
-
|
|
308
|
+
assert.deepStrictEqual(documentDefinition, {
|
|
286
309
|
"content": [
|
|
287
310
|
"Veintiocho =>with treinta y seis =>cents",
|
|
288
311
|
"Doscientos ochenta y nueve",
|
|
@@ -304,7 +327,7 @@ and some more here`,
|
|
|
304
327
|
]
|
|
305
328
|
}`;
|
|
306
329
|
const documentDefinition = await tpl.processToObj(template, data);
|
|
307
|
-
|
|
330
|
+
assert.deepStrictEqual(documentDefinition, {
|
|
308
331
|
"content": [
|
|
309
332
|
{
|
|
310
333
|
"svg": "<svg height='2' width='100'><line x1='0' y1='0' x2='1000' y2='0' style='stroke:rgb(60,60,60);stroke-width:2' /></svg>",
|
|
@@ -334,10 +357,10 @@ and some more here`,
|
|
|
334
357
|
}`;
|
|
335
358
|
try {
|
|
336
359
|
await tpl.processToObj(template, data);
|
|
337
|
-
|
|
360
|
+
assert.fail("Expected processToObj to throw");
|
|
338
361
|
} catch (err) {
|
|
339
362
|
//spaces are important in this test
|
|
340
|
-
|
|
363
|
+
assert.deepStrictEqual(err.data, `{
|
|
341
364
|
"content": [{},
|
|
342
365
|
]
|
|
343
366
|
}`);
|
|
@@ -371,7 +394,7 @@ and some more here`,
|
|
|
371
394
|
]
|
|
372
395
|
}`;
|
|
373
396
|
const documentDefinition = await tpl.processToObj(template, data);
|
|
374
|
-
|
|
397
|
+
assert.deepStrictEqual(documentDefinition, {
|
|
375
398
|
"content": [
|
|
376
399
|
"Mié Ene 19, 2022 8:00 AM",
|
|
377
400
|
"Mié Ene 19, 2022",
|
|
@@ -407,7 +430,7 @@ and some more here`,
|
|
|
407
430
|
]
|
|
408
431
|
}`;
|
|
409
432
|
const documentDefinition = await tpl.processToObj(template, data);
|
|
410
|
-
|
|
433
|
+
assert.deepStrictEqual(documentDefinition, {
|
|
411
434
|
"content": [
|
|
412
435
|
{
|
|
413
436
|
"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+2ec1MXm3zmpl82QAAAHDCBgAAgBM2AAAAnLABAADghA0AAAAnbAAAADhhAwAAwAkbAAAATtgAAABwwgYAAIATNgAAAJywAQAA4IQNAAAAJ2wAAAA4YQMAAMAJGwAAAE7YAAAAcMIGAACAEzYAAACcsAEAAOCEDQAAACdsAAAAOGEDAADACRsAAABO2AAAAHDCBgAAgBM2AAAAnLABAADghA0AAAAnbAAAADhhAwAAwAkbAAAATtgAAABwwgYAAIATNgAAAJywAQAA4IQNAAAAJ2wAAAA4YQMAAMAJGwAAAE7YAAAAcMIGAACAEzYAAACcsAEAAOCEDQAAACdsAAAAOGEDAADACRsAAABO2AAAAHDCBgAAgBM2AAAAnLABAADghA0AAAAnbAAAADhhAwAAwAkbAAAATtgAAABwwgYAAIATNgAAAJywAQAA4IQNAAAAJ2wAAAA4YQMAAMAJGwAAAE7YAAAAcMIGAACAEzYAAACcsAEAAOCEDQAAACdsAAAAOGEDAADACRsAAABO2AAAAHDCBgAAgBM2AAAAnLABAADghA0AAAAnbAAAADhhAwAAwAkbAAAATtgAAABwwgYAAIATNgAAAJywAQAA4IQNAAAAJ2wAAAA4YQMAAMAJGwAAAE7YAAAAcMIGAACAEzYAAACcsAEAAOCEDQAAACdsAAAAOGEDAADACRsAAABO2AAAAHDCBgAAgBM2AAAAnLABAADghA0AAAAnbAAAADhhAwAAwAkbAAAATtgAAABwwgYAAIATNgAAAJywAQAA4IQNAAAAJ2wAAAA4YQMAAMAJGwAAAE7YAAAAcMIGAACAEzYAAACcsAEAAOCEDQAAACdsAAAAOGEDAADACX8+ALXvFMrcDQAAAABJRU5ErkJggg==",
|
|
@@ -436,7 +459,7 @@ and some more here`,
|
|
|
436
459
|
const d = {
|
|
437
460
|
}
|
|
438
461
|
const documentDefinition = await tpl.processToObj(template, d);
|
|
439
|
-
|
|
462
|
+
assert.deepStrictEqual(documentDefinition, {
|
|
440
463
|
"content": [
|
|
441
464
|
{
|
|
442
465
|
"text": ""
|
|
@@ -478,7 +501,7 @@ and some more here`,
|
|
|
478
501
|
]
|
|
479
502
|
}`;
|
|
480
503
|
const documentDefinition = await tpl.processToObj(template, data);
|
|
481
|
-
|
|
504
|
+
assert.deepStrictEqual(documentDefinition, {
|
|
482
505
|
"content": [
|
|
483
506
|
"Transaction Id: 5c9f8f8f8f8f8f8f8f8f8f8",
|
|
484
507
|
"=>h","adult and =>adult","child and =>child","person and =>person",{
|
|
@@ -542,7 +565,7 @@ and some more here`,
|
|
|
542
565
|
]
|
|
543
566
|
}`;
|
|
544
567
|
const documentDefinition = await tpl.processToObj(template, data);
|
|
545
|
-
|
|
568
|
+
assert.deepStrictEqual(documentDefinition, {
|
|
546
569
|
"content": [
|
|
547
570
|
"1",
|
|
548
571
|
"12/21/2021 11:38 AM",
|
|
@@ -577,7 +600,7 @@ and some more here`,
|
|
|
577
600
|
]
|
|
578
601
|
}`;
|
|
579
602
|
const documentDefinition = await tpl.processToObj(template, data);
|
|
580
|
-
|
|
603
|
+
assert.deepStrictEqual(documentDefinition, {
|
|
581
604
|
"content": [
|
|
582
605
|
"12/21/2021",
|
|
583
606
|
"PNA",
|
|
@@ -610,7 +633,7 @@ and some more here`,
|
|
|
610
633
|
]
|
|
611
634
|
}`;
|
|
612
635
|
const documentDefinition = await tpl.processToObj(template, data);
|
|
613
|
-
|
|
636
|
+
assert.deepStrictEqual(documentDefinition, {
|
|
614
637
|
"content": [
|
|
615
638
|
"8:53 PM",
|
|
616
639
|
"PNA",
|
|
@@ -643,7 +666,7 @@ and some more here`,
|
|
|
643
666
|
]
|
|
644
667
|
}`;
|
|
645
668
|
const documentDefinition = await tpl.processToObj(template, data);
|
|
646
|
-
|
|
669
|
+
assert.deepStrictEqual(documentDefinition, {
|
|
647
670
|
"content": [
|
|
648
671
|
"11:38 AM",
|
|
649
672
|
"PNA",
|
|
@@ -664,7 +687,7 @@ and some more here`,
|
|
|
664
687
|
]
|
|
665
688
|
}`;
|
|
666
689
|
const documentDefinition = await tpl.processToObj(template, data);
|
|
667
|
-
|
|
690
|
+
assert.deepStrictEqual(documentDefinition, {
|
|
668
691
|
"content": [
|
|
669
692
|
"Date / heure d'arrivée:"
|
|
670
693
|
]
|
|
@@ -679,7 +702,7 @@ and some more here`,
|
|
|
679
702
|
]
|
|
680
703
|
}`;
|
|
681
704
|
const documentDefinition = await tpl.processToObj(template, data);
|
|
682
|
-
|
|
705
|
+
assert.deepStrictEqual(documentDefinition, {
|
|
683
706
|
"content": [
|
|
684
707
|
{
|
|
685
708
|
"text": "\tSome text \t with tabs \t here"
|
|
@@ -696,7 +719,7 @@ and some more here`,
|
|
|
696
719
|
]
|
|
697
720
|
}`;
|
|
698
721
|
const documentDefinition = await tpl.processToObj(template, data);
|
|
699
|
-
|
|
722
|
+
assert.deepStrictEqual(documentDefinition, {
|
|
700
723
|
"content": [
|
|
701
724
|
"This `` is `` awesome"
|
|
702
725
|
]
|
|
@@ -721,7 +744,7 @@ and some more here`,
|
|
|
721
744
|
]
|
|
722
745
|
}`
|
|
723
746
|
const documentDefinition = await tpl.processToObj(template, data);
|
|
724
|
-
|
|
747
|
+
assert.deepStrictEqual(documentDefinition, {
|
|
725
748
|
"content": [
|
|
726
749
|
{
|
|
727
750
|
"key1": "isocode",
|
|
@@ -746,7 +769,7 @@ and some more here`,
|
|
|
746
769
|
{% escCondensed %}
|
|
747
770
|
{% escEject %}`;
|
|
748
771
|
const documentDefinition = await tpl.processToEscp(template, data);
|
|
749
|
-
|
|
772
|
+
assert.deepStrictEqual(documentDefinition, `\u001bia\u0000\u001b@\u001b3$\u001bM\u001bEShift location closure #: 5c9f8f8f8f8f8f8f8f8f8f8\n\u001bF\u001b\u000f\f`);
|
|
750
773
|
});
|
|
751
774
|
|
|
752
775
|
it("should return a text with unescaped characters", async () => {
|
|
@@ -758,7 +781,7 @@ and some more here`,
|
|
|
758
781
|
]
|
|
759
782
|
}`;
|
|
760
783
|
const documentDefinition = await tpl.processToObj(template, data);
|
|
761
|
-
|
|
784
|
+
assert.deepStrictEqual(documentDefinition, {
|
|
762
785
|
"content": [
|
|
763
786
|
"< > & $"
|
|
764
787
|
]
|