This repository has been archived by the owner on Aug 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
54 lines (47 loc) · 1.5 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
module.exports = {
deDot: function (obj) {
for (const k in obj) {
if (k.indexOf('.') > 0) {
const nk = k.replaceAll('.', '~');
delete Object.assign(obj, { [nk]: obj[k] })[k];
}
if (obj[k] instanceof Object) {
this.deDot(obj[k]);
}
}
},
keyHasValue: function (node, params, key) {
const name = node.name || node.conf.name || node.type;
if (typeof params[key] !== 'string' || params[key].length < 1) {
node.status({ fill: 'red', shape: 'ring', text: 'input-error: ' + key });
const err = name + ' is missing ' + key;
node.error(err, {
es: {
node: name,
error: err,
},
});
return false;
}
return true;
},
slateStatusClear: function (node) {
clearTimeout(node.pending_status_clear);
node.pending_status_clear = setTimeout(() => {
node.status({});
}, 60000);
},
prepData: function (node, msg) {
const data = { ...msg };
if (node.conf.loadContexts) {
data._ = {};
const c = node.context();
const lc = node.conf.loadContexts.split(',');
for (const i in lc) {
const k = lc[i].trim();
data._[k] = c.get(k) || c.flow.get(k) || c.global.get(k);
}
}
return data;
},
};