btrz-liquid-templates 1.0.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/src/escp.js ADDED
@@ -0,0 +1,133 @@
1
+
2
+ // const escInitQzTray = "\x1B\x69\x61\x00\x1B\x40"; // set printer to ESC/P mode and clear memory buffer ; Inicializa la impresora
3
+ // const lineSpacing = "\x1B\x33\x18"; // Espaciado de línea (1/6 de pulgada)
4
+ // const lineSpacing2 = "\x1B\x33\x24"; // ESC 3 n (1/9 de pulgada)
5
+ // const fontSelection = "\x1B\x4D"; // Fuente pequeña (Condensed)
6
+ // const escBold = "\x1B\x45"; // Activa negrita
7
+ // const escCancelBold = "\x1B\x46"; // Cancela negrita
8
+ // const escNewLine = "\n"; // Nueva línea
9
+ // const escCut = "\x1D\x56\x00"; // Corte de papel
10
+ // const escEject = "\x0C"; // Form Feed (FF) - Expulsa la hoja
11
+ // const escCondensed = "\x1B\x0F"; // Modo comprimido (17 cpi)
12
+
13
+ function escInitQzTray(engine) {
14
+ this.registerTag("escInitQzTray", {
15
+ parse: function(tagToken, remainTokens) {
16
+ },
17
+ render: async function(ctx) {
18
+ return "\\x1B\\x69\\x61\\x00\\x1B\\x40";
19
+ }
20
+ });
21
+ }
22
+
23
+ function lineSpacing(engine) {
24
+ this.registerTag("lineSpacing", {
25
+ parse: function(tagToken, remainTokens) {
26
+
27
+ },
28
+ render: async function(ctx) {
29
+ return "\\x1B\\x33\\x18";
30
+ }
31
+ });
32
+ }
33
+
34
+ function lineSpacing2(engine) {
35
+ this.registerTag("lineSpacing2", {
36
+ parse: function(tagToken, remainTokens) {
37
+
38
+ },
39
+ render: async function(ctx) {
40
+ return "\\x1B\\x33\\x24";
41
+ }
42
+ });
43
+ }
44
+
45
+ function fontSelection(engine) {
46
+ this.registerTag("fontSelection", {
47
+ parse: function(tagToken, remainTokens) {
48
+
49
+ },
50
+ render: async function(ctx) {
51
+ return "\\x1B\\x4D";
52
+ }
53
+ });
54
+ }
55
+
56
+ function escBold(engine) {
57
+ this.registerTag("escBold", {
58
+ parse: function(tagToken, remainTokens) {
59
+
60
+ },
61
+ render: async function(ctx) {
62
+ return "\\x1B\\x45";
63
+ }
64
+ });
65
+ }
66
+
67
+ function escCancelBold(engine) {
68
+ this.registerTag("escCancelBold", {
69
+ parse: function(tagToken, remainTokens) {
70
+
71
+ },
72
+ render: async function(ctx) {
73
+ return "\\x1B\\x46";
74
+ }
75
+ });
76
+ }
77
+
78
+ function escNewLine(engine) {
79
+ this.registerTag("escNewLine", {
80
+ parse: function(tagToken, remainTokens) {
81
+
82
+ },
83
+ render: async function(ctx) {
84
+ return "\\n";
85
+ }
86
+ });
87
+ }
88
+
89
+ function escCut(engine) {
90
+ this.registerTag("escCut", {
91
+ parse: function(tagToken, remainTokens) {
92
+
93
+ },
94
+ render: async function(ctx) {
95
+ return "\\x1D\\x56\\x00";
96
+ }
97
+ });
98
+ }
99
+
100
+ function escEject(engine) {
101
+ this.registerTag("escEject", {
102
+ parse: function(tagToken, remainTokens) {
103
+
104
+ },
105
+ render: async function(ctx) {
106
+ return "\\x0C";
107
+ }
108
+ });
109
+ }
110
+
111
+ function escCondensed(engine) {
112
+ this.registerTag("escCondensed", {
113
+ parse: function(tagToken, remainTokens) {
114
+
115
+ },
116
+ render: async function(ctx) {
117
+ return "\\x1B\\x0F";
118
+ }
119
+ });
120
+ }
121
+
122
+ module.exports = {
123
+ escInitQzTray,
124
+ lineSpacing,
125
+ lineSpacing2,
126
+ fontSelection,
127
+ escBold,
128
+ escCancelBold,
129
+ escNewLine,
130
+ escCut,
131
+ escEject,
132
+ escCondensed
133
+ }
package/src/html.js ADDED
@@ -0,0 +1,97 @@
1
+ function getBoldToken(token) {
2
+ const txt = token.replace(/<\/b>/ig, '<b>').replace(/<b>/ig, '').replace(/"/ig, '``');
3
+ return `{"bold": true, "text": "${txt}"}`;
4
+ }
5
+
6
+ function getItalicToken(token) {
7
+ const txt = token.replace(/<\/i>/ig, '<i>').replace(/<i>/ig, '').replace(/"/ig, '``');
8
+ return `{"italics": true, "text": "${txt}"}`;
9
+ }
10
+
11
+ function getHeaderToken(token, size) {
12
+ const txt = token.replace(/<\/h1>/ig, '<h>')
13
+ .replace(/<\/h2>/ig, '<h>')
14
+ .replace(/<\/h3>/ig, '<h>')
15
+ .replace(/<h1>/ig, '<h>')
16
+ .replace(/<h2>/ig, '<h>')
17
+ .replace(/<h3>/ig, '<h>')
18
+ .replace(/<h>/ig, '')
19
+ .replace(/"/ig, '``');
20
+ if (size === '1') {
21
+ return `{"style": "header", "text": "${txt}"}`;
22
+ }
23
+ if (size === '2') {
24
+ return `{"style": "subheader", "text": "${txt}"}`;
25
+ }
26
+ if (size === '3') {
27
+ return `{"style": "innerheader", "text": "${txt}"}`;
28
+ }
29
+ return `{"text": "${txt}"}`;
30
+ }
31
+
32
+ function getTokenInfo(token) {
33
+ if (token.indexOf('<b>') !== -1) { return getBoldToken(token); }
34
+ if (token.indexOf('<i>') !== -1) { return getItalicToken(token); }
35
+ if (token.indexOf('<h1>') !== -1) { return getHeaderToken(token, '1'); }
36
+ if (token.indexOf('<h2>') !== -1) { return getHeaderToken(token, '2'); }
37
+ if (token.indexOf('<h3>') !== -1) { return getHeaderToken(token, '3'); }
38
+ return `{"text": "${token.trim().replace(/"/ig, '``')}"}`;
39
+ }
40
+
41
+ function parseLine(line) {
42
+ if (!line) { return [getTokenInfo(line || "")]; }
43
+ const htmls = line.match(/<.>.*?<\/.>/ig);
44
+ const parsed = [];
45
+ let parts = [];
46
+
47
+ if (htmls) {
48
+ htmls.forEach((token) => {
49
+ parts = line.split(token);
50
+ parsed.push(getTokenInfo(parts[0] || ""));
51
+ parsed.push(getTokenInfo(token || ""));
52
+ if (parts.length > 1) {
53
+ line = parts[1];
54
+ }
55
+ });
56
+ }
57
+ if (line) {
58
+ parsed.push(getTokenInfo(line || ""));
59
+ }
60
+ return parsed;
61
+ }
62
+
63
+ function getLines(str) {
64
+ if (str && str.replace) {
65
+ const lines = str.replace(/\r\n/g, '<br/>')
66
+ .replace(/\n/g, '<br/>')
67
+ .replace(/\r/g, '<br/>')
68
+ .replace(/<br>/ig, '<br/>')
69
+ .split('<br/>');
70
+ return lines.map((line) => {
71
+ return parseLine(line);
72
+ }).join(",");
73
+ }
74
+ return `{"text": ""}`;
75
+ }
76
+
77
+ function Html(engine) {
78
+ this.registerTag("h", {
79
+ parse: function(tagToken, remainTokens) {
80
+ this.str = tagToken.args;
81
+ },
82
+ render: async function(ctx) {
83
+ let str = await this.liquid.evalValue(this.str, ctx);
84
+
85
+ if (ctx && ctx.environments && ctx.environments.localizer && ctx.environments.localizer.get) {
86
+ return getLines(ctx.environments.localizer.get(str).replace(/[\t]/g, '\\t'));
87
+ }
88
+ return getLines(str);
89
+ }
90
+ });
91
+ }
92
+
93
+ module.exports = {
94
+ Html
95
+ };
96
+
97
+
package/src/httpimg.js ADDED
@@ -0,0 +1,34 @@
1
+ const axios = require("axios");
2
+
3
+ function getPrefix(url) {
4
+ const extention = url.split(".").pop();
5
+ if (extention.toLowerCase() === "png") {
6
+ return "data:image/png;base64,";
7
+ }
8
+ return "data:image/jpeg;base64,";
9
+ }
10
+
11
+ function HttpImg(engine) {
12
+ this.registerTag("httpImg", {
13
+ parse: function(tagToken, remainTokens) {
14
+ this.str = tagToken.args
15
+ },
16
+ render: async function(ctx) {
17
+ const url = await this.liquid.evalValue(this.str, ctx);
18
+ try {
19
+ const response = await axios.get(url, {
20
+ responseType: "arraybuffer"
21
+ });
22
+ return `${getPrefix(url)}${Buffer.from(response.data, "binary").toString("base64")}`;
23
+ } catch (e) {
24
+ console.log(e);
25
+ return "";
26
+ }
27
+ }
28
+ });
29
+ }
30
+
31
+ module.exports = {
32
+ HttpImg
33
+ };
34
+
package/src/index.js ADDED
@@ -0,0 +1,121 @@
1
+ const {Liquid} = require("liquidjs");
2
+ const {Localizer} = require("./localizer.js");
3
+ const {HorizontalLine} = require("./lines.js");
4
+ const {Barcode} = require("./barcode.js");
5
+ const {Html} = require("./html.js");
6
+ const {Money, CurcySymbol, CurcyIso, CurcyName, MoneyReduce} = require("./money.js");
7
+ const {DateF, TimeF, DateTime, HumanDate, HumanDateTime, ExpDate, HumanArrivalDateTime, HumanDepartureDateTime,
8
+ DepartureDateTime, ArrivalDateTime, DepartureDate, ArrivalDate, DepartureTime, ArrivalTime, HumanArrivalDate,
9
+ HumanDepartureDate
10
+ } = require("./dateFormat.js");
11
+ const {Text} = require("./text.js");
12
+ const {QrString} = require("./qrstr.js");
13
+ const {ToLetters} = require("./toletters.js");
14
+ const {HttpImg} = require("./httpimg.js");
15
+ const {Keys} = require("./object.js");
16
+ const {
17
+ escInitQzTray,
18
+ lineSpacing,
19
+ lineSpacing2,
20
+ fontSelection,
21
+ escBold,
22
+ escCancelBold,
23
+ escCondensed,
24
+ escNewLine,
25
+ escCut,
26
+ escEject
27
+ } = require("./escp.js");
28
+
29
+ function getEngine() {
30
+ const engine = new Liquid({
31
+ layouts: ["/nowhere/"],
32
+ root: ["/nowhere/"],
33
+ partials: ["/nowhere/"],
34
+ extname: ".liquid",
35
+ dynamicPartials: false,
36
+ outputEscape: (val) => {
37
+ // if (typeof val === "string") {
38
+ // return val.replace(/[\\]/g, '\\\\')
39
+ // .replace(/[\"]/g, '\\"')
40
+ // .replace(/[\/]/g, '\\/')
41
+ // .replace(/[\b]/g, '\\b')
42
+ // .replace(/[\f]/g, '\\f')
43
+ // .replace(/[\n]/g, '\\n')
44
+ // .replace(/[\r]/g, '\\r')
45
+ // .replace(/[\t]/g, '\\t');
46
+ // }
47
+ return val;
48
+ }
49
+ });
50
+ engine.plugin(Localizer);
51
+ engine.plugin(Html);
52
+ engine.plugin(HorizontalLine);
53
+ engine.plugin(Barcode);
54
+ engine.plugin(Money);
55
+ engine.plugin(CurcySymbol);
56
+ engine.plugin(CurcyIso);
57
+ engine.plugin(CurcyName);
58
+ engine.plugin(MoneyReduce);
59
+ engine.plugin(DateF);
60
+ engine.plugin(TimeF);
61
+ engine.plugin(DateTime);
62
+ engine.plugin(HumanDate);
63
+ engine.plugin(HumanDateTime);
64
+ engine.plugin(HumanArrivalDateTime);
65
+ engine.plugin(HumanDepartureDateTime);
66
+ engine.plugin(DepartureDateTime);
67
+ engine.plugin(ArrivalDateTime);
68
+ engine.plugin(DepartureDate);
69
+ engine.plugin(ArrivalDate);
70
+ engine.plugin(DepartureTime);
71
+ engine.plugin(ArrivalTime);
72
+ engine.plugin(HumanArrivalDate);
73
+ engine.plugin(HumanDepartureDate);
74
+ engine.plugin(Text);
75
+ engine.plugin(ExpDate);
76
+ engine.plugin(QrString);
77
+ engine.plugin(ToLetters);
78
+ engine.plugin(HttpImg);
79
+ engine.plugin(Keys);
80
+ return engine;
81
+ }
82
+
83
+ module.exports = {
84
+ async processToObj(liquidTemplate, data) {
85
+ try {
86
+ const str = await this.processToString(liquidTemplate, data);
87
+ const obj = JSON.parse(str);
88
+ return obj;
89
+ } catch (err) {
90
+ err.data = liquidTemplate;
91
+ throw err;
92
+ }
93
+ },
94
+ async processToEscp(liquidTemplate, data) {
95
+ const engine = getEngine();
96
+ engine.plugin(escInitQzTray);
97
+ engine.plugin(lineSpacing);
98
+ engine.plugin(lineSpacing2);
99
+ engine.plugin(fontSelection);
100
+ engine.plugin(escBold);
101
+ engine.plugin(escCancelBold);
102
+ engine.plugin(escCondensed);
103
+ engine.plugin(escNewLine);
104
+ engine.plugin(escCut);
105
+ engine.plugin(escEject);
106
+ let str = await engine.parseAndRender(liquidTemplate, data);
107
+ str = str.split(/\n/).map((line) => {
108
+ return line.trim();
109
+ }).filter((line) => {
110
+ return line.length > 0;
111
+ })
112
+ .join(",");
113
+ // console.log(str);
114
+ return str;
115
+ },
116
+ async processToString(liquidTemplate, data) {
117
+ const engine = getEngine();
118
+ const str = await engine.parseAndRender(liquidTemplate, data);
119
+ return str;
120
+ }
121
+ };
package/src/lines.js ADDED
@@ -0,0 +1,40 @@
1
+ function hexToRgb(hex) {
2
+ var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
3
+ return result ? `${parseInt(result[1], 16)},${parseInt(result[2], 16)},${parseInt(result[3], 16)}` : null;
4
+ }
5
+
6
+ function HorizontalLine(engine) {
7
+ this.registerTag("hline", {
8
+ parse: function(tagToken, remainTokens) {
9
+ //width = 500, weight = 1, rgb = "0,0,0"
10
+ try {
11
+ const args = (tagToken.args || "").split(" ");
12
+ this.width = args[0] || 500;
13
+ this.weight = args[1] || 1;
14
+ this.rgb = args[2] || "0,0,0";
15
+ } catch (err) {
16
+ this.width = 500;
17
+ this.weight = 1;
18
+ this.rgb = "0,0,0";
19
+ }
20
+ },
21
+ render: async function(ctx) {
22
+ let rgb = this.rgb;
23
+ if (this.rgb.indexOf(".") > -1) {
24
+ rgb = await this.liquid.evalValue(this.rgb, ctx);
25
+ }
26
+ if (rgb.indexOf("#") === 0) {
27
+ rgb = hexToRgb(rgb);
28
+ }
29
+ return `{
30
+ "svg": "<svg height='2' width='100'><line x1='0' y1='0' x2='1000' y2='0' style='stroke:rgb(${rgb});stroke-width:${this.weight}' /></svg>",
31
+ "width": ${this.width}
32
+ }`;
33
+ }
34
+ });
35
+ }
36
+
37
+ module.exports = {
38
+ HorizontalLine
39
+ };
40
+
@@ -0,0 +1,25 @@
1
+ function Localizer(engine) {
2
+ this.registerTag("t", {
3
+ parse: function(tagToken, remainTokens) {
4
+ const args = tagToken.args.split("|");
5
+ this.str = (args[0] || "").trim();
6
+ if (args.length > 1) {
7
+ this.tags = args.slice(1);
8
+ }
9
+ },
10
+ render: async function(ctx) {
11
+ let str = await this.liquid.evalValue(this.str, ctx);
12
+ if (ctx && ctx.environments && ctx.environments.localizer && ctx.environments.localizer.get && str !== "") {
13
+ str = ctx.environments.localizer.get(str);
14
+ }
15
+ if (this.tags) {
16
+ return await this.liquid.evalValue(`"${str.replace(/"/g, '``')}"|${this.tags}`, ctx);
17
+ }
18
+ return str.replace(/[\"]/g, '``');
19
+ }
20
+ });
21
+ }
22
+
23
+ module.exports = {
24
+ Localizer
25
+ };
package/src/money.js ADDED
@@ -0,0 +1,195 @@
1
+ const formatter = require("btrz-formatter");
2
+ function getCurrencyValue(item, propName, providerPreferences, userOptions) {
3
+ const defaultOptions = {
4
+ prefix: "displayCurrency"
5
+ };
6
+ const options = Object.assign({}, defaultOptions, userOptions);
7
+ const prefix = options.prefix;
8
+
9
+ if (!propName || !prefix || typeof propName !== "string" || typeof prefix !== "string") {
10
+ throw new Error("getCurrencyValue: propName and prefix must be strings");
11
+ }
12
+
13
+ if (providerPreferences.preferences.multiCurrency) {
14
+ const prefixedPropName = propName.replace(/^./, "".concat(prefix).concat(propName[0].toUpperCase()));
15
+ return item[prefixedPropName] || item[propName];
16
+ }
17
+
18
+ return item[propName];
19
+ }
20
+
21
+ function getCurrency(item, providerPreferences) {
22
+ const baseCurrency = providerPreferences.preferences.supportedCurrencies[0];
23
+ if (providerPreferences.preferences.multiCurrency) {
24
+ return item && item.displayCurrency && item.displayCurrency.isocode ? item.displayCurrency : baseCurrency;
25
+ }
26
+ return baseCurrency;
27
+ }
28
+
29
+ function getCurrencySymbol(isocode) {
30
+ const currencies = [
31
+ {
32
+ isocode: "USD",
33
+ symbol: "$",
34
+ printSymbol: true
35
+ },
36
+ {
37
+ isocode: "AUD",
38
+ symbol: "$",
39
+ printSymbol: true
40
+ },
41
+ {
42
+ isocode: "CAD",
43
+ symbol: "$",
44
+ printSymbol: true
45
+ },
46
+ {
47
+ isocode: "EUR",
48
+ symbol: "€",
49
+ printSymbol: true
50
+ },
51
+ {
52
+ isocode: "GBP",
53
+ symbol: "£",
54
+ printSymbol: true
55
+ },
56
+ {
57
+ isocode: "NZD",
58
+ symbol: "$",
59
+ printSymbol: true
60
+ },
61
+ {
62
+ isocode: "MXN",
63
+ symbol: "$",
64
+ printSymbol: true
65
+ },
66
+ {
67
+ isocode: "HNL",
68
+ symbol: "L",
69
+ printSymbol: true
70
+ },
71
+ {
72
+ isocode: "NIO",
73
+ symbol: "C$",
74
+ printSymbol: true
75
+ },
76
+ {
77
+ isocode: "CRC",
78
+ symbol: "₡",
79
+ printSymbol: false
80
+ },
81
+ {
82
+ isocode: "GTQ",
83
+ symbol: "Q",
84
+ printSymbol: true
85
+ },
86
+ {
87
+ isocode: "PAB",
88
+ symbol: "B/.",
89
+ printSymbol: true
90
+ }
91
+ ]
92
+ const trimIsocode = isocode ? isocode.trim() : "";
93
+ const curcy = currencies.find((cur) => {
94
+ return cur.isocode === trimIsocode;
95
+ });
96
+ return curcy && curcy.printSymbol ? curcy.symbol : " ";
97
+ }
98
+
99
+ function MoneyReduce(engine) {
100
+ this.registerTag("moneyReduce", {
101
+ parse: function(tagToken, remainTokens) {
102
+ const args = tagToken.args.split(" ");
103
+ this.item = args[0] || "ticket.taxes";
104
+ this.innerPropName = args[1] || "calculated";
105
+ },
106
+ render: async function(ctx) {
107
+ const coll = await this.liquid.evalValue(this.item, ctx);
108
+ if (ctx && ctx.environments && ctx.environments.providerPreferences && ctx.environments.providerPreferences.preferences &&
109
+ Array.isArray(coll)) {
110
+ const sum = coll.reduce((acc, item) => {
111
+ return acc + getCurrencyValue(item, this.innerPropName, ctx.environments.providerPreferences, {prefix: "display"});
112
+ }, 0);
113
+ return formatter.money(sum);
114
+ }
115
+ return "PNA";
116
+ }
117
+ });
118
+ }
119
+
120
+ function Money(engine) {
121
+ this.registerTag("money", {
122
+ parse: function(tagToken, remainTokens) {
123
+ const args = tagToken.args.split(" ");
124
+ this.item = args[0] || "ticket.total";
125
+ this.propName = args[1] || "total";
126
+ },
127
+ render: async function(ctx) {
128
+ const item = await this.liquid.evalValue(this.item, ctx);
129
+ if (ctx && ctx.environments && ctx.environments.providerPreferences && ctx.environments.providerPreferences.preferences &&
130
+ item && item[this.propName] !== undefined) {
131
+ return formatter.money(getCurrencyValue(item, this.propName, ctx.environments.providerPreferences, {prefix: "display"}));
132
+ }
133
+ return "PNA";
134
+ }
135
+ });
136
+ }
137
+
138
+ function CurcySymbol(engine) {
139
+ this.registerTag("curcySymbol", {
140
+ parse: function(tagToken, remainTokens) {
141
+ this.item = tagToken.args || "ticket";
142
+ },
143
+ render: async function(ctx) {
144
+ const item = await this.liquid.evalValue(this.item, ctx);
145
+ if (ctx && ctx.environments && ctx.environments.providerPreferences && ctx.environments.providerPreferences.preferences && item) {
146
+ const itemCurrency = getCurrency(item, ctx.environments.providerPreferences);
147
+ return getCurrencySymbol((itemCurrency || {}).isocode || " ");
148
+ }
149
+ return "";
150
+ }
151
+ });
152
+ }
153
+
154
+ function CurcyIso(engine) {
155
+ this.registerTag("curcyIso", {
156
+ parse: function(tagToken, remainTokens) {
157
+ this.item = tagToken.args || "ticket";
158
+ },
159
+ render: async function(ctx) {
160
+ const item = await this.liquid.evalValue(this.item, ctx);
161
+ if (ctx && ctx.environments && ctx.environments.providerPreferences && ctx.environments.providerPreferences.preferences && item) {
162
+ const itemCurrency = getCurrency(item, ctx.environments.providerPreferences);
163
+ return (itemCurrency || {}).isocode || " ";
164
+ }
165
+ return "";
166
+ }
167
+ });
168
+ }
169
+
170
+ function CurcyName(engine) {
171
+ this.registerTag("curcyName", {
172
+ parse: function(tagToken, remainTokens) {
173
+ this.item = tagToken.args || "ticket";
174
+ },
175
+ render: async function(ctx) {
176
+ const item = await this.liquid.evalValue(this.item, ctx);
177
+ if (ctx && ctx.environments && ctx.environments.providerPreferences && ctx.environments.providerPreferences.preferences && item) {
178
+ if (item.isocode !== undefined && item.symbol !== undefined) {
179
+ return ctx.environments.localizer.get((item || {}).isocode || " ");
180
+ }
181
+ const itemCurrency = getCurrency(item, ctx.environments.providerPreferences);
182
+ return ctx.environments.localizer.get((itemCurrency || {}).isocode || " ");
183
+ }
184
+ return "";
185
+ }
186
+ });
187
+ }
188
+
189
+ module.exports = {
190
+ CurcyIso,
191
+ CurcySymbol,
192
+ CurcyName,
193
+ Money,
194
+ MoneyReduce
195
+ };
package/src/object.js ADDED
@@ -0,0 +1,11 @@
1
+ function Keys(engine) {
2
+ this.registerFilter("keys", (value) => {
3
+ return Object.keys(value);
4
+ })
5
+ }
6
+
7
+ module.exports = {
8
+ Keys
9
+ };
10
+
11
+
package/src/qrstr.js ADDED
@@ -0,0 +1,36 @@
1
+ function QrString(engine) {
2
+ this.registerTag("qrstr", {
3
+ parse: function(tagToken, remainTokens) {
4
+ this.str = (tagToken.args || "ticket").toLowerCase();
5
+ },
6
+ render: async function(ctx) {
7
+ if (this.str === "reservation" || this.str === "ticket") {
8
+ return `https://${ctx.environments.providerPreferences.domain}/r/t/${ctx.environments[this.str].urlTicketCode}`;
9
+ }
10
+ if (this.str === "solditem") {
11
+ return `PI-${ctx.environments.soldItem._id.toString()}`;
12
+ }
13
+ if (this.str === "parcel") {
14
+ return `${ctx.environments.parcel.accountId}-PA-${ctx.environments.parcel._id.toString()}`;
15
+ }
16
+ if (this.str === "flexpass") {
17
+ return `${ctx.environments.flexPass.ticketNumber}`;
18
+ }
19
+ if (this.str === "ssr") {
20
+ return `${ctx.environments.ssr.ssrsInstanceId}`;
21
+ }
22
+ if (this.str === "redeemableitem") {
23
+ return `RI-${ctx.environments.redeemableItem._id.toString()}`;
24
+ }
25
+ if (this.str === "voucher") {
26
+ return `${ctx.environments.voucher.internalId}`;
27
+ }
28
+ return ""
29
+ }
30
+ });
31
+ }
32
+
33
+ module.exports = {
34
+ QrString
35
+ };
36
+