@legalplace/tagextractor 1.1.3 → 1.1.5
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.
|
@@ -6,6 +6,9 @@ declare class OvcConverter {
|
|
|
6
6
|
isOvc(_obj: InputsType | OvcType): _obj is OvcType;
|
|
7
7
|
isOptionsVariables(_obj: InputsType | OvcType): _obj is InputsType;
|
|
8
8
|
private pushStaticChildren;
|
|
9
|
+
private pushLeftOver;
|
|
10
|
+
private pushLeftOverOption;
|
|
11
|
+
private pushLeftOverVariable;
|
|
9
12
|
}
|
|
10
13
|
declare const _default: OvcConverter;
|
|
11
14
|
export default _default;
|
|
@@ -38,13 +38,15 @@ var OvcConverter = (function () {
|
|
|
38
38
|
currentOption.forEach(function (childId, index) {
|
|
39
39
|
var sanitizedId = typeof childId === 'string' && childId.split('_').length > 0 ? childId.split('_')[0] : childId;
|
|
40
40
|
if (!Object.prototype.hasOwnProperty.call(inputs.options, id)) {
|
|
41
|
-
|
|
41
|
+
var defaultValue = references.options[id].meta.type === 'static';
|
|
42
|
+
inputs.options[id] = new Array(occurences_1).fill(defaultValue);
|
|
42
43
|
}
|
|
43
44
|
if (typeof sanitizedId === 'string' && sanitizedId.trim().length === 0) {
|
|
44
45
|
return;
|
|
45
46
|
}
|
|
46
47
|
if (!Object.prototype.hasOwnProperty.call(inputs.options, sanitizedId)) {
|
|
47
|
-
|
|
48
|
+
var defaultValue = references.options[sanitizedId].meta.type === 'static';
|
|
49
|
+
inputs.options[sanitizedId] = new Array(occurences_1).fill(defaultValue);
|
|
48
50
|
}
|
|
49
51
|
inputs.options = __assign(__assign({}, inputs.options), _this.pushStaticChildren(inputs.options, sanitizedId, occurences_1, references));
|
|
50
52
|
inputs.options[sanitizedId][index] = true;
|
|
@@ -96,7 +98,7 @@ var OvcConverter = (function () {
|
|
|
96
98
|
}
|
|
97
99
|
});
|
|
98
100
|
}
|
|
99
|
-
return inputs;
|
|
101
|
+
return this.pushLeftOver(inputs, references);
|
|
100
102
|
};
|
|
101
103
|
OvcConverter.prototype.isOvc = function (_obj) {
|
|
102
104
|
if (typeof _obj !== 'object' || _obj === null)
|
|
@@ -125,11 +127,47 @@ var OvcConverter = (function () {
|
|
|
125
127
|
});
|
|
126
128
|
staticOptions.forEach(function (childId) {
|
|
127
129
|
if (!Object.prototype.hasOwnProperty.call(result, childId)) {
|
|
128
|
-
result[childId] = new Array(occurences).fill(
|
|
130
|
+
result[childId] = new Array(occurences).fill(true);
|
|
129
131
|
}
|
|
130
132
|
});
|
|
131
133
|
return result;
|
|
132
134
|
};
|
|
135
|
+
OvcConverter.prototype.pushLeftOver = function (inputs, references) {
|
|
136
|
+
var _this = this;
|
|
137
|
+
var result = __assign({}, inputs);
|
|
138
|
+
Object.values(references.sections).forEach(function (document) {
|
|
139
|
+
Object.values(document).forEach(function (section) {
|
|
140
|
+
section.options.forEach(function (optionId) {
|
|
141
|
+
var occurences = inputs.options[optionId] === undefined ? 1 : inputs.options[optionId].length;
|
|
142
|
+
result = _this.pushLeftOverOption(result, references, references.options[optionId], occurences);
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
return result;
|
|
147
|
+
};
|
|
148
|
+
OvcConverter.prototype.pushLeftOverOption = function (inputs, references, option, occurences) {
|
|
149
|
+
var _a;
|
|
150
|
+
var _this = this;
|
|
151
|
+
var result = __assign({}, inputs);
|
|
152
|
+
var defaultValue = !['radio', 'checkbox'].includes(option.meta.type);
|
|
153
|
+
if (!Object.prototype.hasOwnProperty.call(result.options, option.meta.id)) {
|
|
154
|
+
result = __assign(__assign({}, result), { options: __assign(__assign({}, result.options), (_a = {}, _a[option.meta.id] = new Array(occurences).fill(defaultValue), _a)) });
|
|
155
|
+
}
|
|
156
|
+
option.options.forEach(function (optionId) {
|
|
157
|
+
result = _this.pushLeftOverOption(result, references, references.options[optionId], occurences);
|
|
158
|
+
});
|
|
159
|
+
option.variables.forEach(function (variableId) {
|
|
160
|
+
result = _this.pushLeftOverVariable(result, variableId, occurences);
|
|
161
|
+
});
|
|
162
|
+
return result;
|
|
163
|
+
};
|
|
164
|
+
OvcConverter.prototype.pushLeftOverVariable = function (inputs, id, occurences) {
|
|
165
|
+
var _a;
|
|
166
|
+
if (!Object.prototype.hasOwnProperty.call(inputs.variables, id)) {
|
|
167
|
+
return __assign(__assign({}, inputs), { variables: __assign(__assign({}, inputs.variables), (_a = {}, _a[id] = new Array(occurences).fill(''), _a)) });
|
|
168
|
+
}
|
|
169
|
+
return inputs;
|
|
170
|
+
};
|
|
133
171
|
return OvcConverter;
|
|
134
172
|
}());
|
|
135
173
|
exports.default = new OvcConverter();
|
package/package.json
CHANGED
package/src/libs/OvcConverter.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { OptionV3 } from '@legalplace/models-v3-types'
|
|
1
2
|
import { Types } from '@legalplace/referencesparser'
|
|
2
3
|
import InputsType from '../types/inputs.type'
|
|
3
4
|
import OvcType from '../types/ovc.type'
|
|
@@ -29,7 +30,8 @@ class OvcConverter {
|
|
|
29
30
|
|
|
30
31
|
// Making sure the input exist
|
|
31
32
|
if (!Object.prototype.hasOwnProperty.call(inputs.options, id)) {
|
|
32
|
-
|
|
33
|
+
const defaultValue = references.options[id].meta.type === 'static'
|
|
34
|
+
inputs.options[id] = new Array(occurences).fill(defaultValue)
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
// Making sure the childId is not empty
|
|
@@ -39,7 +41,8 @@ class OvcConverter {
|
|
|
39
41
|
|
|
40
42
|
// Creating input if it doesn't exist
|
|
41
43
|
if (!Object.prototype.hasOwnProperty.call(inputs.options, sanitizedId)) {
|
|
42
|
-
|
|
44
|
+
const defaultValue = references.options[sanitizedId].meta.type === 'static'
|
|
45
|
+
inputs.options[sanitizedId] = new Array(occurences).fill(defaultValue)
|
|
43
46
|
}
|
|
44
47
|
|
|
45
48
|
// Adding static childrens
|
|
@@ -105,7 +108,8 @@ class OvcConverter {
|
|
|
105
108
|
})
|
|
106
109
|
}
|
|
107
110
|
|
|
108
|
-
|
|
111
|
+
// Pushing left over and returning inputs
|
|
112
|
+
return this.pushLeftOver(inputs, references)
|
|
109
113
|
}
|
|
110
114
|
|
|
111
115
|
public isOvc(_obj: InputsType | OvcType): _obj is OvcType {
|
|
@@ -142,12 +146,73 @@ class OvcConverter {
|
|
|
142
146
|
staticOptions.forEach(childId => {
|
|
143
147
|
// Creating input if it doesn't exist
|
|
144
148
|
if (!Object.prototype.hasOwnProperty.call(result, childId)) {
|
|
145
|
-
result[childId] = new Array(occurences).fill(
|
|
149
|
+
result[childId] = new Array(occurences).fill(true)
|
|
146
150
|
}
|
|
147
151
|
})
|
|
148
152
|
|
|
149
153
|
return result
|
|
150
154
|
}
|
|
155
|
+
|
|
156
|
+
private pushLeftOver(inputs: InputsType, references: Types.ReferencesType): InputsType {
|
|
157
|
+
let result = {
|
|
158
|
+
...inputs
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
Object.values(references.sections).forEach(document => {
|
|
162
|
+
Object.values(document).forEach(section => {
|
|
163
|
+
section.options.forEach(optionId => {
|
|
164
|
+
const occurences = inputs.options[optionId] === undefined ? 1 : inputs.options[optionId].length
|
|
165
|
+
result = this.pushLeftOverOption(result, references, references.options[optionId], occurences)
|
|
166
|
+
})
|
|
167
|
+
})
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
return result
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
private pushLeftOverOption(inputs: InputsType, references: Types.ReferencesType, option: OptionV3, occurences: number): InputsType {
|
|
174
|
+
let result = {
|
|
175
|
+
...inputs
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const defaultValue = !['radio', 'checkbox'].includes(option.meta.type)
|
|
179
|
+
|
|
180
|
+
// Adding option if it doesn't exist
|
|
181
|
+
if (!Object.prototype.hasOwnProperty.call(result.options, option.meta.id)) {
|
|
182
|
+
result = {
|
|
183
|
+
...result,
|
|
184
|
+
options: {
|
|
185
|
+
...result.options,
|
|
186
|
+
[option.meta.id]: new Array(occurences).fill(defaultValue)
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Reading option's children
|
|
192
|
+
option.options.forEach(optionId => {
|
|
193
|
+
result = this.pushLeftOverOption(result, references, references.options[optionId], occurences)
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
// Reading option variables
|
|
197
|
+
option.variables.forEach(variableId => {
|
|
198
|
+
result = this.pushLeftOverVariable(result, variableId, occurences)
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
return result
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
private pushLeftOverVariable(inputs: InputsType, id: number, occurences: number): InputsType {
|
|
205
|
+
if (!Object.prototype.hasOwnProperty.call(inputs.variables, id)) {
|
|
206
|
+
return {
|
|
207
|
+
...inputs,
|
|
208
|
+
variables: {
|
|
209
|
+
...inputs.variables,
|
|
210
|
+
[id]: new Array(occurences).fill('')
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return inputs
|
|
215
|
+
}
|
|
151
216
|
}
|
|
152
217
|
|
|
153
218
|
export default new OvcConverter()
|