@iebh/polyglot 4.5.0 → 4.6.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/.ignore +1 -1
- package/.vscode/launch.json +36 -0
- package/LICENSE +20 -20
- package/README.md +282 -262
- package/lib/data/fieldCodesObject.js +1 -3
- package/lib/data/fieldCodesParse.js +0 -2
- package/lib/data/meshObject.js +1 -3
- package/lib/data/meshTranslationsObject.js +1 -3
- package/lib/data/meshTranslationsParse.js +0 -2
- package/lib/index.js +42 -59
- package/lib/modules/engines/generic.js +30 -90
- package/lib/modules/engines.js +18 -18
- package/lib/modules/global.js +11 -12
- package/lib/modules/parse.js +270 -320
- package/lib/modules/tools.js +99 -134
- package/package.json +59 -54
package/lib/modules/tools.js
CHANGED
|
@@ -4,46 +4,43 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports["default"] = void 0;
|
|
7
|
-
|
|
8
7
|
var _global = _interopRequireDefault(require("./global.js"));
|
|
9
|
-
|
|
10
8
|
var _lodash = _interopRequireDefault(require("lodash"));
|
|
11
|
-
|
|
12
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
*
|
|
16
|
-
* @var {Object}
|
|
10
|
+
/**
|
|
11
|
+
* Collection of utility functions to apply common behaviour to a compiled tree
|
|
12
|
+
* @var {Object}
|
|
17
13
|
*/
|
|
18
14
|
var tools = {
|
|
19
|
-
/**
|
|
20
|
-
* Visit the given node types within a deeply nested tree and run a function
|
|
21
|
-
* This function may mutate the input tree depending on the actions of the callbacks
|
|
22
|
-
* NOTE: If the return value of the callback is `"DEL"` the node is deleted
|
|
23
|
-
* @param {array} tree The tree sturcture to operate on
|
|
24
|
-
* @param {null|array} types Node filter to apply to (if falsy all are used)
|
|
25
|
-
* @param {function} callback The callback to call with each node. Called as (node, path)
|
|
26
|
-
* @return {array} The input tree
|
|
15
|
+
/**
|
|
16
|
+
* Visit the given node types within a deeply nested tree and run a function
|
|
17
|
+
* This function may mutate the input tree depending on the actions of the callbacks
|
|
18
|
+
* NOTE: If the return value of the callback is `"DEL"` the node is deleted
|
|
19
|
+
* @param {array} tree The tree sturcture to operate on
|
|
20
|
+
* @param {null|array} types Node filter to apply to (if falsy all are used)
|
|
21
|
+
* @param {function} callback The callback to call with each node. Called as (node, path)
|
|
22
|
+
* @return {array} The input tree
|
|
27
23
|
*/
|
|
28
24
|
visit: function visit(tree, types, callback) {
|
|
29
25
|
var removals = []; // Stack of removal paths we are performing when done
|
|
30
26
|
|
|
31
27
|
var treeWalker = function treeWalker(tree, path) {
|
|
32
28
|
tree.forEach(function (branch, branchKey) {
|
|
33
|
-
var nodePath = path.concat(branchKey);
|
|
29
|
+
var nodePath = path.concat(branchKey);
|
|
34
30
|
|
|
31
|
+
// Fire callback if it matches
|
|
35
32
|
if (!types || _lodash["default"].includes(types, branch.type)) {
|
|
36
33
|
var result = callback(branch, nodePath);
|
|
37
34
|
if (result === 'DEL') removals.push(nodePath);
|
|
38
|
-
}
|
|
39
|
-
|
|
35
|
+
}
|
|
40
36
|
|
|
37
|
+
// Walk down nodes if its a group
|
|
41
38
|
if (branch.type == 'group' || branch.type == 'line') treeWalker(branch.nodes, nodePath.concat(['nodes']));
|
|
42
39
|
});
|
|
43
40
|
};
|
|
41
|
+
treeWalker(tree, []);
|
|
44
42
|
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
// Crop all items marked as removals
|
|
47
44
|
removals.reverse() // Walk in reverse order so we don't screw up arrays
|
|
48
45
|
.forEach(function (path) {
|
|
49
46
|
var nodeName = path.pop();
|
|
@@ -52,14 +49,13 @@ var tools = {
|
|
|
52
49
|
});
|
|
53
50
|
return tree;
|
|
54
51
|
},
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* @param {array}
|
|
60
|
-
* @param {
|
|
61
|
-
* @
|
|
62
|
-
* @return {array} The input tree element with the replacements applied
|
|
52
|
+
/**
|
|
53
|
+
* Apply a series of text replacements to every matching node object within a tree
|
|
54
|
+
* This function mutates tree
|
|
55
|
+
* @param {array} tree The tree sturcture to operate on
|
|
56
|
+
* @param {null|array} types Type filter to apply. If falsy all are used
|
|
57
|
+
* @param {array} replacements Array of replacements to apply. Each must be of the form `{subject: STRING|REGEXP, value: STRING|FUNCTION}`
|
|
58
|
+
* @return {array} The input tree element with the replacements applied
|
|
63
59
|
*/
|
|
64
60
|
replaceContent: function replaceContent(tree, types, replacements) {
|
|
65
61
|
this.visit(tree, types, function (branch) {
|
|
@@ -74,10 +70,10 @@ var tools = {
|
|
|
74
70
|
escapeRegExp: function escapeRegExp(string) {
|
|
75
71
|
return string.replace(/[.*+?^${}()[\]\\]/g, '\\$&'); // $& means the whole matched string
|
|
76
72
|
},
|
|
73
|
+
|
|
77
74
|
// Replace multiple terms at once
|
|
78
75
|
multiReplace: function multiReplace(text, replaceObj) {
|
|
79
76
|
var template = tools.escapeRegExp(Object.keys(replaceObj).join("|"));
|
|
80
|
-
|
|
81
77
|
if (template.length > 0) {
|
|
82
78
|
var regex = new RegExp(template, "g");
|
|
83
79
|
return text.replace(regex, function (match) {
|
|
@@ -87,13 +83,12 @@ var tools = {
|
|
|
87
83
|
return text;
|
|
88
84
|
}
|
|
89
85
|
},
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
* @param {string}
|
|
95
|
-
* @
|
|
96
|
-
* @return {string} The resolved template
|
|
86
|
+
/**
|
|
87
|
+
* Retrieve the contents of a template by its ID
|
|
88
|
+
* NOTE: If the specific engine definition is not found 'default' is used (and it will be pre-parsed via .translate())
|
|
89
|
+
* @param {string} template The template to resolve
|
|
90
|
+
* @param {string} engine The current engine (used to get the correct sub-templating string)
|
|
91
|
+
* @return {string} The resolved template
|
|
97
92
|
*/
|
|
98
93
|
resolveTemplate: function resolveTemplate(template, engine) {
|
|
99
94
|
if (!_global["default"].templates[template]) return 'UNKNOWN-TEMPLATE:' + template;
|
|
@@ -102,68 +97,59 @@ var tools = {
|
|
|
102
97
|
if (!_global["default"].templates[template].engines[engine]) return "Template: \"".concat(template, "\" not found for engine: \"").concat(engine, "\"");
|
|
103
98
|
return '';
|
|
104
99
|
},
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
*
|
|
108
|
-
* @param {
|
|
109
|
-
* @
|
|
110
|
-
* @return {string} The parsed string seperated by NEXT
|
|
100
|
+
/**
|
|
101
|
+
* Structure the wild cards correctly for cochrane to ensure no wildcards appear inside quotation marks
|
|
102
|
+
* @param {string} text The text to parse
|
|
103
|
+
* @param {Boolean} highlighting Whether to assign custom fonts
|
|
104
|
+
* @return {string} The parsed string seperated by NEXT
|
|
111
105
|
*/
|
|
112
106
|
wildCardCochrane: function wildCardCochrane(text, highlighting) {
|
|
113
107
|
var wildcards = ["?", "$", "*"];
|
|
114
108
|
var words = text.split(" ");
|
|
115
109
|
var lastMatch = -1;
|
|
116
110
|
var foundMatch = false;
|
|
117
|
-
|
|
118
111
|
var _loop = function _loop(i) {
|
|
119
112
|
if (wildcards.some(function (wildcard) {
|
|
120
113
|
return words[i].includes(wildcard);
|
|
121
114
|
})) {
|
|
122
|
-
foundMatch = true;
|
|
123
|
-
|
|
115
|
+
foundMatch = true;
|
|
116
|
+
// Add quotation marks to previous word/s if the previous word was not a match
|
|
124
117
|
if (i - 1 > lastMatch) {
|
|
125
118
|
words[lastMatch + 1] = highlighting ? '<font color="DarkBlue">"' + words[lastMatch + 1] : '"' + words[lastMatch + 1];
|
|
126
119
|
words[i - 1] = highlighting ? words[i - 1] + '"</font>' : words[i - 1] + '"';
|
|
127
120
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
121
|
+
lastMatch = i;
|
|
122
|
+
// Check that there is a word before and it is not a wildcard word
|
|
131
123
|
if (i > 0 && !wildcards.some(function (wildcard) {
|
|
132
124
|
return words[i - 1].includes(wildcard);
|
|
133
125
|
})) {
|
|
134
126
|
words[i] = highlighting ? '<font color="purple">NEXT</font> ' + words[i] : 'NEXT ' + words[i];
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
|
|
127
|
+
}
|
|
128
|
+
// Check that there is a word after
|
|
138
129
|
if (i < words.length - 1) {
|
|
139
130
|
words[i] = highlighting ? words[i] + ' <font color="purple">NEXT</font>' : words[i] + " NEXT";
|
|
140
131
|
}
|
|
141
132
|
}
|
|
142
133
|
};
|
|
143
|
-
|
|
144
134
|
for (var i = 0; i < words.length; i++) {
|
|
145
135
|
_loop(i);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
|
|
136
|
+
}
|
|
137
|
+
// Add quotation marks to word/s after the final match
|
|
149
138
|
if (lastMatch + 1 < words.length) {
|
|
150
139
|
words[lastMatch + 1] = highlighting ? '<font color="DarkBlue">"' + words[lastMatch + 1] : '"' + words[lastMatch + 1];
|
|
151
140
|
words[words.length - 1] = highlighting ? words[words.length - 1] + '"</font>' : words[words.length - 1] + '"';
|
|
152
141
|
}
|
|
153
|
-
|
|
154
142
|
return foundMatch ? "(".concat(words.join(" "), ")") : words.join(" ");
|
|
155
143
|
},
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
*
|
|
159
|
-
* @param {string}
|
|
160
|
-
* @
|
|
161
|
-
* @return {string} Formatted number
|
|
144
|
+
/**
|
|
145
|
+
* Print number in format defined by engine
|
|
146
|
+
* @param {string} engine Engine to use
|
|
147
|
+
* @param {string} ref Branch ref (e.g. 1)
|
|
148
|
+
* @return {string} Formatted number
|
|
162
149
|
*/
|
|
163
150
|
printNumber: function printNumber(engine, ref) {
|
|
164
151
|
// Get line number format for engine
|
|
165
152
|
var number = ref;
|
|
166
|
-
|
|
167
153
|
switch (engine) {
|
|
168
154
|
case 'PubMed full':
|
|
169
155
|
case 'PubMed abbreviation':
|
|
@@ -173,41 +159,37 @@ var tools = {
|
|
|
173
159
|
case 'WoS Advanced':
|
|
174
160
|
case 'Scopus (basic search)':
|
|
175
161
|
case 'Scopus (advanced search)':
|
|
162
|
+
//HTA
|
|
163
|
+
case 'International HTA Database':
|
|
176
164
|
number = "#" + ref;
|
|
177
165
|
break;
|
|
178
|
-
|
|
179
166
|
case 'Ovid MEDLINE':
|
|
180
167
|
case 'PsycInfo (Ovid)':
|
|
181
168
|
case 'ProQuest Health and Medical':
|
|
182
169
|
number = ref;
|
|
183
170
|
break;
|
|
184
|
-
|
|
185
171
|
case 'CINAHL (Ebsco)':
|
|
186
172
|
case 'SPORTDiscus':
|
|
187
173
|
number = "S" + ref;
|
|
188
174
|
break;
|
|
189
|
-
|
|
190
175
|
default:
|
|
191
176
|
}
|
|
192
|
-
|
|
193
177
|
return number;
|
|
194
178
|
},
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
*
|
|
198
|
-
* @param {
|
|
199
|
-
* @param {
|
|
200
|
-
* @
|
|
201
|
-
* @return {string} The phrase enclosed as needed
|
|
179
|
+
/**
|
|
180
|
+
* Determine if a phrase needs to be enclosed within speachmarks and return the result
|
|
181
|
+
* @param {Object} branch Phrase branch to examine
|
|
182
|
+
* @param {string} engine Optional engine ID to examine for other enclose methods
|
|
183
|
+
* @param {boolean} highlighting Optional bool to determine if html color styling is added
|
|
184
|
+
* @return {string} The phrase enclosed as needed
|
|
202
185
|
*/
|
|
203
186
|
quotePhrase: function quotePhrase(branch, engine, settings) {
|
|
204
187
|
var text = _lodash["default"].trimEnd(branch.content);
|
|
188
|
+
var space = /\s/.test(text);
|
|
205
189
|
|
|
206
|
-
|
|
207
|
-
|
|
190
|
+
// Apply wildcard replacements
|
|
208
191
|
if (settings.replaceWildcards) {
|
|
209
192
|
var replaceObj = {};
|
|
210
|
-
|
|
211
193
|
switch (engine) {
|
|
212
194
|
case 'PubMed full':
|
|
213
195
|
case 'PubMed abbreviation':
|
|
@@ -217,23 +199,19 @@ var tools = {
|
|
|
217
199
|
'#': settings.highlighting ? tools.createTooltip("*", "As PubMed does not single character wildcards a wildcard is used here", "highlight") : '*'
|
|
218
200
|
};
|
|
219
201
|
break;
|
|
220
|
-
|
|
221
202
|
case 'Ovid MEDLINE':
|
|
222
203
|
break;
|
|
223
204
|
// Nothing needed
|
|
224
|
-
|
|
225
205
|
case 'Cochrane Library':
|
|
226
206
|
if (space) {
|
|
227
207
|
text = tools.wildCardCochrane(text, settings.highlighting);
|
|
228
208
|
}
|
|
229
|
-
|
|
230
209
|
replaceObj = {
|
|
231
210
|
'$': settings.highlighting ? tools.createTooltip("?", "As Cochrane does not support single character truncation, the 0 or 1 character truncation is used here.", "highlight") : '?',
|
|
232
211
|
'#': '?'
|
|
233
212
|
};
|
|
234
213
|
return tools.multiReplace(text, replaceObj);
|
|
235
214
|
// Return here to prevent duplicate quotes
|
|
236
|
-
|
|
237
215
|
case 'Embase (Elsevier)':
|
|
238
216
|
case 'Web of Science':
|
|
239
217
|
case 'WoS Advanced':
|
|
@@ -243,7 +221,6 @@ var tools = {
|
|
|
243
221
|
'#': '?'
|
|
244
222
|
};
|
|
245
223
|
break;
|
|
246
|
-
|
|
247
224
|
case 'CINAHL (Ebsco)':
|
|
248
225
|
replaceObj = {
|
|
249
226
|
'$': '?',
|
|
@@ -251,7 +228,6 @@ var tools = {
|
|
|
251
228
|
'#': '?'
|
|
252
229
|
};
|
|
253
230
|
break;
|
|
254
|
-
|
|
255
231
|
case 'Scopus (basic search)':
|
|
256
232
|
case 'Scopus (advanced search)':
|
|
257
233
|
// space = true; //Always include quotes with scopus to make phrase a "loose phrase"
|
|
@@ -261,20 +237,17 @@ var tools = {
|
|
|
261
237
|
'#': '?'
|
|
262
238
|
};
|
|
263
239
|
break;
|
|
264
|
-
|
|
265
240
|
case 'PsycInfo (Ovid)':
|
|
266
241
|
replaceObj = {
|
|
267
242
|
'$': '#'
|
|
268
243
|
};
|
|
269
244
|
break;
|
|
270
|
-
|
|
271
245
|
case 'ProQuest Health and Medical':
|
|
272
246
|
replaceObj = {
|
|
273
247
|
'$': '?',
|
|
274
248
|
'#': '?'
|
|
275
249
|
};
|
|
276
250
|
break;
|
|
277
|
-
|
|
278
251
|
case 'SPORTDiscus':
|
|
279
252
|
if (!settings.testing) {
|
|
280
253
|
space = true; //Always include quotes with SPORTDiscus
|
|
@@ -285,85 +258,82 @@ var tools = {
|
|
|
285
258
|
'?': '#'
|
|
286
259
|
};
|
|
287
260
|
break;
|
|
288
|
-
|
|
289
261
|
case 'Informit Health Collection':
|
|
290
262
|
replaceObj = {
|
|
291
263
|
'$': '?',
|
|
292
264
|
'?': '*1'
|
|
293
265
|
};
|
|
294
266
|
break;
|
|
267
|
+
//HTA
|
|
268
|
+
case 'International HTA Database':
|
|
269
|
+
replaceObj = {
|
|
270
|
+
'$': settings.highlighting ? tools.createTooltip("*", "As INAHTA does not support single character truncation a wildcard is used here", "highlight") : '*',
|
|
271
|
+
'?': settings.highlighting ? tools.createTooltip("*", "As INAHTA does not support single character truncation a wildcard is used here", "highlight") : '*',
|
|
272
|
+
'#': settings.highlighting ? tools.createTooltip("*", "As INAHTA does not support single character truncation a wildcard is used here", "highlight") : '*'
|
|
273
|
+
};
|
|
274
|
+
break;
|
|
295
275
|
}
|
|
296
|
-
|
|
297
276
|
text = tools.multiReplace(text, replaceObj);
|
|
298
277
|
}
|
|
299
|
-
|
|
300
278
|
return engine == 'Embase (Elsevier)' ? space ? settings.highlighting ? "<font color='DarkBlue'>'" + text + "'</font>" : "'" + text + "'" : text : space ? settings.highlighting ? '<font color="DarkBlue">"' + text + '"</font>' : '"' + text + '"' : text;
|
|
301
279
|
},
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
* @
|
|
307
|
-
* @returns {Object} The recombined tree
|
|
280
|
+
/**
|
|
281
|
+
* Convert the '$or' / '$and' nodes within a tree into a nested structure
|
|
282
|
+
* This function will also flatten identical branches (i.e. run-on multiple $and / $or into one array)
|
|
283
|
+
* @param {Object} tree The object tree to recombine
|
|
284
|
+
* @returns {Object} The recombined tree
|
|
308
285
|
*/
|
|
309
286
|
renestConditions: function renestConditions(tree) {
|
|
310
287
|
if (!_lodash["default"].isArray(tree)) return tree; // Not an array - skip
|
|
311
|
-
// Transform arrays of the form: [X1, $or/$and, X2] => {$or/$and: [X1, X2]}
|
|
312
288
|
|
|
289
|
+
// Transform arrays of the form: [X1, $or/$and, X2] => {$or/$and: [X1, X2]}
|
|
313
290
|
return tree.reduce(function (res, branch, index, arr) {
|
|
314
291
|
var firstKey = (0, _lodash["default"])(branch).keys().first();
|
|
315
|
-
|
|
316
292
|
if (firstKey == '$or' || firstKey == '$and') {
|
|
317
293
|
// Is a combinator
|
|
318
294
|
var expression = {};
|
|
319
|
-
expression[firstKey] = [res.pop(),
|
|
295
|
+
expression[firstKey] = [res.pop(),
|
|
296
|
+
// Right side is the last thing we added to the buffer
|
|
320
297
|
arr.splice(index + 1, 1)[0] // Left side is the next thing we're going to look at in the array
|
|
321
298
|
];
|
|
299
|
+
|
|
322
300
|
res.push(expression);
|
|
323
301
|
} else {
|
|
324
302
|
// Unknown - just push to array and carry on processing
|
|
325
303
|
res.push(branch);
|
|
326
304
|
}
|
|
327
|
-
|
|
328
305
|
return res;
|
|
329
306
|
}, []);
|
|
330
307
|
},
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
*
|
|
334
|
-
*
|
|
335
|
-
* @param {Object}
|
|
336
|
-
* @param {
|
|
337
|
-
* @
|
|
338
|
-
* @
|
|
339
|
-
*
|
|
340
|
-
*
|
|
341
|
-
*
|
|
342
|
-
* {foo, joinOr, bar, joinOr, baz} => {joinOr: [foo, bar, baz]}
|
|
308
|
+
/**
|
|
309
|
+
* Combine multiple run-on $and / $or conditional branches into one branch
|
|
310
|
+
* This function is a companion function to renestConditions and should be called directly afterwards if needed
|
|
311
|
+
* @param {Object} tree The tree to traverse
|
|
312
|
+
* @param {Object} [options] Additional options to accept
|
|
313
|
+
* @param {number} [options.depth=10] The maximum depth to traverse before giving up, set to 0 to infinitely recurse
|
|
314
|
+
* @return {Object} The collapsed tree
|
|
315
|
+
* @example
|
|
316
|
+
* {left, joinAnd, right} => {joinAnd: [left, right]}
|
|
317
|
+
* @example
|
|
318
|
+
* {foo, joinOr, bar, joinOr, baz} => {joinOr: [foo, bar, baz]}
|
|
343
319
|
*/
|
|
344
320
|
combineConditions: function combineConditions(tree, options) {
|
|
345
321
|
var settings = _lodash["default"].defaults(options, {
|
|
346
322
|
depth: 10
|
|
347
323
|
});
|
|
348
|
-
|
|
349
324
|
var collapses = [];
|
|
350
|
-
|
|
351
325
|
var traverseTree = function traverseTree(branch) {
|
|
352
326
|
var path = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
353
|
-
|
|
354
327
|
// Recurse into each tree node and make a bottom-up list of nodes we need to collapse
|
|
355
328
|
_lodash["default"].forEach(branch, function (v, k) {
|
|
356
329
|
// Use _.map if its an array and _.mapValues if we're examining an object
|
|
357
330
|
if (_lodash["default"].isObject(v)) {
|
|
358
331
|
var firstKey = (0, _lodash["default"])(branch).keys().first();
|
|
359
|
-
|
|
360
332
|
if (path.length > 1 && (firstKey == '$or' || firstKey == '$and')) {
|
|
361
333
|
// Mark for cleanup later (when we can do a bottom-up traversal)
|
|
362
334
|
var lastKey = _lodash["default"].findLast(collapses, function (i) {
|
|
363
335
|
return i.key == '$and' || i.key == '$or';
|
|
364
336
|
}); // Collapse only identical keys
|
|
365
|
-
|
|
366
|
-
|
|
367
337
|
if (!lastKey || lastKey.key == firstKey) {
|
|
368
338
|
collapses.push({
|
|
369
339
|
key: firstKey,
|
|
@@ -371,48 +341,43 @@ var tools = {
|
|
|
371
341
|
});
|
|
372
342
|
}
|
|
373
343
|
}
|
|
374
|
-
|
|
375
344
|
if (settings.depth && path.length > settings.depth) return; // Stop recursing after depth has been reached
|
|
376
|
-
|
|
377
345
|
traverseTree(v, path.concat([k]));
|
|
378
346
|
}
|
|
379
347
|
});
|
|
380
348
|
};
|
|
381
|
-
|
|
382
349
|
traverseTree(tree);
|
|
383
350
|
collapses.forEach(function (collapse) {
|
|
384
351
|
var parent = _lodash["default"].get(tree, collapse.path.slice(0, -1));
|
|
385
|
-
|
|
386
352
|
var child = _lodash["default"].get(tree, collapse.path.concat([collapse.key]));
|
|
387
|
-
|
|
388
353
|
if (!child || !parent || !parent.length) return;
|
|
389
354
|
var child2 = parent[1];
|
|
390
|
-
if (child2) child.push(child2);
|
|
355
|
+
if (child2) child.push(child2);
|
|
391
356
|
|
|
357
|
+
// Wrap $or conditions (that have an '$and' parent) in an object {{{
|
|
392
358
|
var lastParent = (0, _lodash["default"])(collapse.path).slice(0, -1).findLast(_lodash["default"].isString);
|
|
393
359
|
if (lastParent && lastParent == '$and' && collapse.key == '$or') child = {
|
|
394
360
|
$or: child
|
|
395
|
-
};
|
|
361
|
+
};
|
|
362
|
+
// }}}
|
|
396
363
|
|
|
397
364
|
_lodash["default"].set(tree, collapse.path.slice(0, -1), child);
|
|
398
365
|
});
|
|
399
366
|
return tree;
|
|
400
367
|
},
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
*
|
|
404
|
-
* @param {string}
|
|
405
|
-
* @param {string}
|
|
406
|
-
* @param {string} css CSS class to use
|
|
368
|
+
/**
|
|
369
|
+
* Create a tooltip with a specified message
|
|
370
|
+
* @param {string} content Content to append tooltip to
|
|
371
|
+
* @param {string} message Message to contain inside tooltip
|
|
372
|
+
* @param {string} css CSS class to use
|
|
407
373
|
*/
|
|
408
374
|
createTooltip: function createTooltip(content, message, css) {
|
|
409
375
|
css = typeof css !== 'undefined' ? css : "black-underline";
|
|
410
376
|
return "<span class=\"" + css + '" v-tooltip="`' + message + '`">' + content + '</span>';
|
|
411
377
|
},
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
*
|
|
415
|
-
* @param {string} content Content to append popover to
|
|
378
|
+
/**
|
|
379
|
+
* Create a popover with options to replace empty field tags with specified field tag
|
|
380
|
+
* @param {string} content Content to append popover to
|
|
416
381
|
*/
|
|
417
382
|
createPopover: function createPopover(content, offset) {
|
|
418
383
|
return '<v-popover offset="8" placement="right">' + '<span class="blue-underline">' + content + '</span>' + '<template slot="popover">' + '<h3 class="popover-header">Add Field Tag</h3>' + '<input class="tooltip-content" v-model="customField" placeholder="Field tag" />' + '<div class="replace-all">' + '<input type="checkbox" id="checkbox" v-model="replaceAll">' + '<label for="checkbox">Replace All</label>' + '</div>' + '<div class="replace-buttons">' + '<button v-on:click="replaceFields(customField, replaceAll, ' + offset + ')" type="button" class="btn btn-primary">Replace</button>' + '<button v-close-popover type="button" class="btn btn-dark">Close</button>' + '</div>' + '</template>' + '</v-popover>';
|
package/package.json
CHANGED
|
@@ -1,54 +1,59 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@iebh/polyglot",
|
|
3
|
-
"version": "4.
|
|
4
|
-
"description": "IEBH-SRA tool to convert between different medical database search formats",
|
|
5
|
-
"main": "lib/index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "npm run prepare && mocha",
|
|
8
|
-
"test:old": "npm run prepare && mocha './test/**/!(v4).js'",
|
|
9
|
-
"test:new": "npm run prepare && mocha test/v4",
|
|
10
|
-
"prepare": "babel src --out-dir lib",
|
|
11
|
-
"preprocess": "cd ./data && node ./preprocess"
|
|
12
|
-
},
|
|
13
|
-
"babel": {
|
|
14
|
-
"presets": [
|
|
15
|
-
"@babel/preset-env"
|
|
16
|
-
]
|
|
17
|
-
},
|
|
18
|
-
"repository": {
|
|
19
|
-
"type": "git",
|
|
20
|
-
"url": "git+https://github.com/IEBH/sra-polyglot.git"
|
|
21
|
-
},
|
|
22
|
-
"keywords": [
|
|
23
|
-
"iebh",
|
|
24
|
-
"sra",
|
|
25
|
-
"search",
|
|
26
|
-
"translation",
|
|
27
|
-
"syntax",
|
|
28
|
-
"conversion",
|
|
29
|
-
"polyglot",
|
|
30
|
-
"medical",
|
|
31
|
-
"research"
|
|
32
|
-
],
|
|
33
|
-
"author":
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"
|
|
40
|
-
|
|
41
|
-
"
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@iebh/polyglot",
|
|
3
|
+
"version": "4.6.0",
|
|
4
|
+
"description": "IEBH-SRA tool to convert between different medical database search formats",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "npm run prepare && mocha",
|
|
8
|
+
"test:old": "npm run prepare && mocha './test/**/!(v4).js'",
|
|
9
|
+
"test:new": "npm run prepare && mocha test/v4",
|
|
10
|
+
"prepare": "babel src --out-dir lib",
|
|
11
|
+
"preprocess": "cd ./data && node ./preprocess"
|
|
12
|
+
},
|
|
13
|
+
"babel": {
|
|
14
|
+
"presets": [
|
|
15
|
+
"@babel/preset-env"
|
|
16
|
+
]
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/IEBH/sra-polyglot.git"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"iebh",
|
|
24
|
+
"sra",
|
|
25
|
+
"search",
|
|
26
|
+
"translation",
|
|
27
|
+
"syntax",
|
|
28
|
+
"conversion",
|
|
29
|
+
"polyglot",
|
|
30
|
+
"medical",
|
|
31
|
+
"research"
|
|
32
|
+
],
|
|
33
|
+
"author": [
|
|
34
|
+
"Matt Carter <m@ttcarter.com> (https://github.com/hash-bang)",
|
|
35
|
+
"Connor Forbes <cforbes.software@gmail.com> (https://github.com/connorf25)",
|
|
36
|
+
"Justin Cark <jclark@bond.edu.au> (https://github.com/Justin-Clarc)",
|
|
37
|
+
"Tian Liang <amethystoct2012@gmail.com> (https://github.com/Octian)"
|
|
38
|
+
],
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"bugs": {
|
|
41
|
+
"url": "https://github.com/IEBH/sra-polyglot/issues"
|
|
42
|
+
},
|
|
43
|
+
"homepage": "https://github.com/IEBH/sra-polyglot#readme",
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@babel/cli": "^7.0.0",
|
|
46
|
+
"@babel/core": "^7.0.0",
|
|
47
|
+
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
|
|
48
|
+
"@babel/preset-env": "^7.0.0",
|
|
49
|
+
"chai": "^4.2.0",
|
|
50
|
+
"mocha": "^8.4.0",
|
|
51
|
+
"xlsx": "^0.16.9"
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"lodash": "^4.17.15"
|
|
55
|
+
},
|
|
56
|
+
"engines": {
|
|
57
|
+
"node": ">=14.0.0"
|
|
58
|
+
}
|
|
59
|
+
}
|