Comparing version 1.3.0 to 1.4.0
@@ -254,2 +254,25 @@ --- | ||
* ## qrstr | ||
Returns the proper str to transform into a QR code to be able to scan items with the drivers app | ||
```liquid | ||
{% raw %} {%- qrstr reservation -%} {% endraw %} //"https://{{ctx.environments.providerPreferences.domain}}/r/t/{{reservation.urlTicketCode}}" | ||
``` | ||
```liquid | ||
{% raw %} {%- qrstr ticket -%} {% endraw %} //"https://{{ctx.environments.providerPreferences.domain}}/r/t/{{ticket.urlTicketCode}}" | ||
``` | ||
Parameters | ||
| name | definition | required | default | | ||
|------|------------|----------|---------| | ||
| type | The type of object we will be generating the string for the qrcode | N | ticket | ||
### Valid types | ||
reservation, ticket, paid_in, parcel, flexpass, ssr, redeemableItem | ||
* ## dateTime | ||
@@ -320,3 +343,3 @@ | ||
| item | An object in the data given to the liquid template | N | ticket | ||
| propName | The name of the property of the item (it should be a BzDate object) | N | createdAt | ||
| propName | The name of the property of the item (it should be a BzDate object or a time string) | N | createdAt | ||
@@ -327,2 +350,17 @@ ```liquid | ||
* ## expDate | ||
Convenience method that will calculate the expiration date for a reservation | ||
Parameters | ||
| name | definition | required | default | | ||
|------|------------|----------|---------| | ||
| item | An object in the data given to the liquid template | N | ticket | ||
| format | A format object | N | providerPreferences defaults (see prereqs) | ||
```liquid | ||
{% raw %} {%- expDate reservation -%} {% endraw %} //"12/21/2021 11:38 AM" | ||
``` | ||
* ## humanDate | ||
@@ -329,0 +367,0 @@ |
{ | ||
"name": "btrz-pdf", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "Generates pdf documents based on a liquid template", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -14,12 +14,20 @@ const {timezones, BzDate} = require("bz-date"); | ||
function getDate(envs, item, propName, format) { | ||
function formatBzDate(bzDate, format, envs) { | ||
const lang = shortLang(envs.lang); | ||
const timeFormat = envs.providerPreferences.preferences.timeFormat; | ||
const timeZone = envs.providerPreferences.preferences.timeZone; | ||
const lang = shortLang(envs.lang); | ||
const date = new BzDate(envs[item][propName]); | ||
const offset = timezones.getOffset(timeZone, date); | ||
const createdLocal = date.addMinutes(offset); | ||
const offset = timezones.getOffset(timeZone, bzDate); | ||
const createdLocal = bzDate.addMinutes(offset); | ||
return `${formatter.dateFormat(createdLocal.toString(`'yyyy-mm-dd' ${timeFormat}`), `${format}`, false, lang)}`; | ||
} | ||
function getDate(envs, item, propName, format) { | ||
const date = new BzDate(envs[item][propName]); | ||
return formatBzDate(date, format, envs); | ||
} | ||
function getTimeFromString(timeString, format) { | ||
return formatter.timeFormat(timeString, format); | ||
}; | ||
function HumanDateTime(engine) { | ||
@@ -113,2 +121,6 @@ this.registerTag("humanDateTime", { | ||
const format = ctx.environments.providerPreferences.preferences.timeFormat; | ||
if (ctx.environments[this.item][this.propName].toUpperCase) { | ||
return getTimeFromString(ctx.environments[this.item][this.propName], format); | ||
} | ||
return getDate(ctx.environments, this.item, this.propName, format); | ||
@@ -121,5 +133,41 @@ } | ||
function ExpDate(engine) { | ||
this.registerTag("expDate", { | ||
parse: function(tagToken, remainTokens) { | ||
const args = tagToken.args.split(" "); | ||
this.item = args[0] || "ticket"; | ||
if (args.length > 1) { | ||
this.format = args.slice(2).join(" ") || ""; | ||
} | ||
}, | ||
render: async function(ctx) { | ||
if (ctx && ctx.environments && ctx.environments.providerPreferences && ctx.environments.providerPreferences.preferences && | ||
ctx.environments[this.item] && ctx.environments[this.item].expirationDate) { | ||
const item = ctx.environments[this.item]; | ||
let expireDate = new BzDate(item.expirationDate); | ||
if (item.departureTime) { | ||
const timeParts = item.departureTime.split(":"); | ||
expireDate.addHours(timeParts[0]); | ||
expireDate.addMinutes(timeParts[1]); | ||
} | ||
if (item.expire && item.expire > 0) { | ||
if (item.expireUnit === "minutes") { | ||
expireDate = expireDate.addMinutes(item.expire); | ||
} else { | ||
expireDate = expireDate.addDays(item.expire); | ||
} | ||
} | ||
const format = this.format || `${ctx.environments.providerPreferences.preferences.dateFormat} ${ctx.environments.providerPreferences.preferences.timeFormat}`; | ||
return formatBzDate(expireDate, format, ctx.environments); | ||
} | ||
return "PNA"; | ||
} | ||
}); | ||
} | ||
module.exports = { | ||
DateF, | ||
DateTime, | ||
ExpDate, | ||
HumanDate, | ||
@@ -126,0 +174,0 @@ HumanDateTime, |
function getBoldToken(token) { | ||
const txt = token.replace(/<\/b>/ig, '<b>').replace(/<b>/ig, ''); | ||
const txt = token.replace(/<\/b>/ig, '<b>').replace(/<b>/ig, '').replace(/"/ig, '``'); | ||
return `{"bold": true, "text": "${txt}"}`; | ||
@@ -7,3 +7,3 @@ } | ||
function getItalicToken(token) { | ||
const txt = token.replace(/<\/i>/ig, '<i>').replace(/<i>/ig, ''); | ||
const txt = token.replace(/<\/i>/ig, '<i>').replace(/<i>/ig, '').replace(/"/ig, '``'); | ||
return `{"italics": true, "text": "${txt}"}`; | ||
@@ -19,3 +19,4 @@ } | ||
.replace(/<h3>/ig, '<h>') | ||
.replace(/<h>/ig, ''); | ||
.replace(/<h>/ig, '') | ||
.replace(/"/ig, '``'); | ||
if (size === '1') { | ||
@@ -39,7 +40,7 @@ return `{"style": "header", "text": "${txt}"}`; | ||
if (token.indexOf('<h3>') !== -1) { return getHeaderToken(token, '3'); } | ||
return `{"text": "${token.trim()}"}`; | ||
return `{"text": "${token.trim().replace(/"/ig, '``')}"}`; | ||
} | ||
function parseLine(line) { | ||
if (!line) { return [getTokenInfo(line)]; } | ||
if (!line) { return [getTokenInfo(line || "")]; } | ||
const htmls = line.match(/<.>.*?<\/.>/ig); | ||
@@ -52,4 +53,4 @@ const parsed = []; | ||
parts = line.split(token); | ||
parsed.push(getTokenInfo(parts[0])); | ||
parsed.push(getTokenInfo(token)); | ||
parsed.push(getTokenInfo(parts[0] || "")); | ||
parsed.push(getTokenInfo(token || "")); | ||
if (parts.length > 1) { | ||
@@ -61,3 +62,3 @@ line = parts[1]; | ||
if (line) { | ||
parsed.push(getTokenInfo(line)); | ||
parsed.push(getTokenInfo(line || "")); | ||
} | ||
@@ -64,0 +65,0 @@ return parsed; |
@@ -7,4 +7,5 @@ const {Liquid} = require("liquidjs"); | ||
const {Money, CurcySymbol, CurcyIso, MoneyReduce} = require("./money.js"); | ||
const {DateF, TimeF, DateTime, HumanDate, HumanDateTime} = require("./dateFormat.js"); | ||
const {DateF, TimeF, DateTime, HumanDate, HumanDateTime, ExpDate} = require("./dateFormat.js"); | ||
const {Text} = require("./text.js"); | ||
const {QrString} = require("./qrstr.js"); | ||
const {createPdfBinary, createPdfKitDocument, defaultDocumentDefinition} = require("./pdf.js"); | ||
@@ -78,2 +79,4 @@ const pdfjs = require("pdfjs"); | ||
engine.plugin(Text); | ||
engine.plugin(ExpDate); | ||
engine.plugin(QrString); | ||
const str = await engine.parseAndRender(liquidTemplate, data); | ||
@@ -80,0 +83,0 @@ // console.log(str); |
function getLines(str, style) { | ||
if (!str || !str.replace) { return ""; } | ||
const lines = str.replace(/\r\n/g, '<br/>') | ||
@@ -6,2 +7,3 @@ .replace(/\n/g, '<br/>') | ||
.replace(/<br>/ig, '<br/>') | ||
.replace(/"/ig, '``') | ||
.split('<br/>'); | ||
@@ -8,0 +10,0 @@ return lines.map((line) => { |
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
50441
17
983