@legalplace/prerenderx 2.5.2 → 2.5.4
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/dist/libs/OutputParser.d.ts +2 -0
- package/dist/libs/OutputParser.js +39 -1
- package/dist/libs/Prerender.js +10 -9
- package/model.json +1 -0
- package/model.ts +1 -0
- package/ovc.json +1 -0
- package/package.json +3 -3
- package/src/benchmark.ts +6 -0
- package/src/libs/ConditionsRunner.ts +40 -1
- package/src/libs/OutputParser.ts +60 -0
- package/src/libs/Prerender.ts +10 -9
- package/test.html +1 -0
- package/test.json +1 -0
- package/test.ts +14 -0
|
@@ -6,4 +6,6 @@ export declare const getRelatedVariablesValues: getRelatedVarsT;
|
|
|
6
6
|
declare type autonumsType = [string, string, number, string | null][];
|
|
7
7
|
declare type parseOutputT = (output: string, index: number, variables: relVarsValsT, autonums: autonumsType) => string;
|
|
8
8
|
export declare const parseOutputWithVariables: parseOutputT;
|
|
9
|
+
declare type TParseDocumentNameWithVariables = (text: string, ovc: OVC_TYPE, references: Types.ReferencesType, fallback?: string) => string;
|
|
10
|
+
export declare const parseDocumentNameWithVariables: TParseDocumentNameWithVariables;
|
|
9
11
|
export {};
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __spreadArrays = (this && this.__spreadArrays) || function () {
|
|
3
|
+
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
|
4
|
+
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
5
|
+
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
6
|
+
r[k] = a[j];
|
|
7
|
+
return r;
|
|
8
|
+
};
|
|
2
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseOutputWithVariables = exports.getRelatedVariablesValues = void 0;
|
|
10
|
+
exports.parseDocumentNameWithVariables = exports.parseOutputWithVariables = exports.getRelatedVariablesValues = void 0;
|
|
4
11
|
exports.getRelatedVariablesValues = function (optionId, index, variables, ovc, references) {
|
|
5
12
|
var variablesValues = {};
|
|
6
13
|
variables.forEach(function (currentVariableId) {
|
|
@@ -49,3 +56,34 @@ exports.parseOutputWithVariables = function (output, index, variables, autonums)
|
|
|
49
56
|
});
|
|
50
57
|
return parsedOutput;
|
|
51
58
|
};
|
|
59
|
+
exports.parseDocumentNameWithVariables = function (text, ovc, references, fallback) {
|
|
60
|
+
var tagsMatch = text.match(/\[var:([0-9]+)\]/gi);
|
|
61
|
+
var variables = [];
|
|
62
|
+
if (tagsMatch !== null) {
|
|
63
|
+
var variablesTags = __spreadArrays(tagsMatch);
|
|
64
|
+
variables = variablesTags.map(function (current) {
|
|
65
|
+
var outputVariableMatch = current.match(/([0-9]+)/);
|
|
66
|
+
if (outputVariableMatch === null)
|
|
67
|
+
return 0;
|
|
68
|
+
return parseInt(outputVariableMatch[0], 10);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
variables = variables.filter(function (c, i) { return variables.indexOf(c) === i; });
|
|
72
|
+
variables = variables.filter(function (c) { return ovc !== undefined || references.variables[c] !== undefined; });
|
|
73
|
+
var variablesValues = {};
|
|
74
|
+
variables.forEach(function (variableId) {
|
|
75
|
+
var _a;
|
|
76
|
+
var value = ((_a = ovc.variables[variableId]) === null || _a === void 0 ? void 0 : _a[0]) || '';
|
|
77
|
+
variablesValues[variableId] = value.toString();
|
|
78
|
+
});
|
|
79
|
+
var parsedText = "" + text;
|
|
80
|
+
variables.forEach(function (variableId) {
|
|
81
|
+
var value = variablesValues[variableId];
|
|
82
|
+
if (value.trim().length === 0 && fallback)
|
|
83
|
+
parsedText = fallback;
|
|
84
|
+
if (parsedText === fallback && fallback)
|
|
85
|
+
return;
|
|
86
|
+
parsedText = parsedText.replace(new RegExp("\\[var:" + variableId + "\\]", 'gi'), value);
|
|
87
|
+
});
|
|
88
|
+
return parsedText;
|
|
89
|
+
};
|
package/dist/libs/Prerender.js
CHANGED
|
@@ -11,6 +11,7 @@ var OvcConverter_1 = __importDefault(require("./OvcConverter"));
|
|
|
11
11
|
var NumAuto_1 = __importDefault(require("./NumAuto"));
|
|
12
12
|
var InputsInitiator_1 = __importDefault(require("./InputsInitiator"));
|
|
13
13
|
var FillPdfForm_1 = __importDefault(require("./FillPdfForm"));
|
|
14
|
+
var OutputParser_1 = require("./OutputParser");
|
|
14
15
|
var Prerender = (function () {
|
|
15
16
|
function Prerender(model, ovc) {
|
|
16
17
|
this.documentsIndex = {};
|
|
@@ -37,21 +38,21 @@ var Prerender = (function () {
|
|
|
37
38
|
};
|
|
38
39
|
Prerender.prototype.generateDocumentNamesHash = function () {
|
|
39
40
|
var _this = this;
|
|
40
|
-
Object.keys(this.model.documents).forEach(function (
|
|
41
|
+
Object.keys(this.model.documents).forEach(function (slug) {
|
|
41
42
|
var _a, _b;
|
|
42
|
-
var document = _this.model.documents[
|
|
43
|
-
var documentParams = _this.model.documents[
|
|
44
|
-
var conditionObject = _this.references.conditions.documents[
|
|
43
|
+
var document = _this.model.documents[slug];
|
|
44
|
+
var documentParams = _this.model.documents[slug].params;
|
|
45
|
+
var conditionObject = _this.references.conditions.documents[slug];
|
|
45
46
|
var condition = conditionObject === undefined ? true : _this.conditions.executeCondition(conditionObject, 0, 0, 'documents');
|
|
46
47
|
if (condition === true) {
|
|
47
48
|
var hash = crypto_1.default
|
|
48
49
|
.createHash('sha1')
|
|
49
|
-
.update(
|
|
50
|
+
.update(slug)
|
|
50
51
|
.digest('hex');
|
|
51
52
|
if (typeof document.pdf === 'object' && typeof document.pdf.id === 'string' && typeof document.pdf.form === 'object') {
|
|
52
53
|
_this.documentsIndex[hash] = {
|
|
53
|
-
name: document.name,
|
|
54
|
-
slug:
|
|
54
|
+
name: OutputParser_1.parseDocumentNameWithVariables(document.name, _this.ovc, _this.references, document.fallbackName),
|
|
55
|
+
slug: slug,
|
|
55
56
|
form: true,
|
|
56
57
|
fdf: {
|
|
57
58
|
id: '',
|
|
@@ -61,8 +62,8 @@ var Prerender = (function () {
|
|
|
61
62
|
}
|
|
62
63
|
else {
|
|
63
64
|
_this.documentsIndex[hash] = {
|
|
64
|
-
name: document.name,
|
|
65
|
-
slug:
|
|
65
|
+
name: OutputParser_1.parseDocumentNameWithVariables(document.name, _this.ovc, _this.references, document.fallbackName),
|
|
66
|
+
slug: slug,
|
|
66
67
|
pdf: ((_a = documentParams === null || documentParams === void 0 ? void 0 : documentParams.formats) === null || _a === void 0 ? void 0 : _a.pdf) === undefined ? true : documentParams.formats.pdf,
|
|
67
68
|
docx: ((_b = documentParams === null || documentParams === void 0 ? void 0 : documentParams.formats) === null || _b === void 0 ? void 0 : _b.docx) === undefined ? true : documentParams.formats.docx
|
|
68
69
|
};
|