@legalplace/tagextractor 1.1.4 → 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;
|
|
@@ -98,7 +98,7 @@ var OvcConverter = (function () {
|
|
|
98
98
|
}
|
|
99
99
|
});
|
|
100
100
|
}
|
|
101
|
-
return inputs;
|
|
101
|
+
return this.pushLeftOver(inputs, references);
|
|
102
102
|
};
|
|
103
103
|
OvcConverter.prototype.isOvc = function (_obj) {
|
|
104
104
|
if (typeof _obj !== 'object' || _obj === null)
|
|
@@ -132,6 +132,42 @@ var OvcConverter = (function () {
|
|
|
132
132
|
});
|
|
133
133
|
return result;
|
|
134
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
|
+
};
|
|
135
171
|
return OvcConverter;
|
|
136
172
|
}());
|
|
137
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'
|
|
@@ -107,7 +108,8 @@ class OvcConverter {
|
|
|
107
108
|
})
|
|
108
109
|
}
|
|
109
110
|
|
|
110
|
-
|
|
111
|
+
// Pushing left over and returning inputs
|
|
112
|
+
return this.pushLeftOver(inputs, references)
|
|
111
113
|
}
|
|
112
114
|
|
|
113
115
|
public isOvc(_obj: InputsType | OvcType): _obj is OvcType {
|
|
@@ -150,6 +152,67 @@ class OvcConverter {
|
|
|
150
152
|
|
|
151
153
|
return result
|
|
152
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
|
+
}
|
|
153
216
|
}
|
|
154
217
|
|
|
155
218
|
export default new OvcConverter()
|