@lowdefy/operators 3.22.0 → 4.0.0-alpha.1
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/common/and.js +8 -24
- package/dist/common/args.js +10 -31
- package/dist/common/array.js +244 -153
- package/dist/common/change_case.js +114 -160
- package/dist/common/date.js +33 -54
- package/dist/common/divide.js +16 -36
- package/dist/common/eq.js +10 -28
- package/dist/common/function.js +27 -59
- package/dist/common/get.js +21 -46
- package/dist/common/gt.js +10 -28
- package/dist/common/gte.js +10 -28
- package/dist/common/if.js +9 -26
- package/dist/common/if_none.js +13 -32
- package/dist/common/index.js +39 -53
- package/dist/common/json.js +53 -57
- package/dist/common/log.js +5 -18
- package/dist/common/lt.js +10 -28
- package/dist/common/lte.js +10 -28
- package/dist/common/math.js +255 -194
- package/dist/common/mql.js +93 -102
- package/dist/common/ne.js +10 -28
- package/dist/common/not.js +3 -16
- package/dist/common/number.js +130 -108
- package/dist/common/nunjucks.js +24 -44
- package/dist/common/object.js +89 -98
- package/dist/common/operator.js +33 -44
- package/dist/common/or.js +8 -24
- package/dist/common/product.js +11 -29
- package/dist/common/random.js +74 -109
- package/dist/common/regex.js +26 -49
- package/dist/common/string.js +270 -171
- package/dist/common/subtract.js +13 -32
- package/dist/common/sum.js +11 -29
- package/dist/common/switch.js +30 -0
- package/dist/common/type.js +36 -67
- package/dist/common/uri.js +29 -46
- package/dist/common/user.js +10 -35
- package/dist/common/uuid.js +48 -59
- package/dist/common/yaml.js +56 -63
- package/dist/getFromArray.js +22 -44
- package/dist/getFromObject.js +25 -70
- package/dist/index.js +14 -20
- package/dist/node/base64.js +31 -48
- package/dist/node/diff.js +30 -47
- package/dist/node/hash.js +55 -71
- package/dist/node/index.js +6 -14
- package/dist/{web/list_contexts.js → node/payload.js} +9 -16
- package/dist/node/secret.js +32 -53
- package/dist/nodeParser.js +95 -146
- package/dist/runClass.js +57 -82
- package/dist/runInstance.js +60 -84
- package/dist/web/_index.js +25 -0
- package/dist/web/actions.js +10 -31
- package/dist/web/base64.js +29 -46
- package/dist/{common/_index.js → web/event.js} +10 -30
- package/dist/web/event_log.js +10 -35
- package/dist/web/format.js +15 -37
- package/dist/web/global.js +25 -0
- package/dist/web/index.js +17 -21
- package/dist/{common/event.js → web/input.js} +10 -31
- package/dist/web/js.js +10 -30
- package/dist/web/location.js +44 -59
- package/dist/web/media.js +46 -75
- package/dist/web/menu.js +10 -28
- package/dist/web/request.js +19 -40
- package/dist/web/request_details.js +10 -35
- package/dist/web/state.js +25 -0
- package/dist/web/url_query.js +25 -0
- package/dist/webParser.js +115 -157
- package/package.json +16 -15
- package/dist/common/global.js +0 -50
- package/dist/common/input.js +0 -50
- package/dist/common/state.js +0 -50
- package/dist/common/url_query.js +0 -50
- package/dist/getFromOtherContext.js +0 -96
package/dist/common/string.js
CHANGED
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _runInstance = _interopRequireDefault(require("../runInstance"));
|
|
9
|
-
|
|
10
|
-
var _helpers = require("@lowdefy/helpers");
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
1
|
/*
|
|
15
2
|
Copyright 2020-2021 Lowdefy, Inc
|
|
16
3
|
|
|
@@ -25,164 +12,276 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
25
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
26
13
|
See the License for the specific language governing permissions and
|
|
27
14
|
limitations under the License.
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
15
|
+
*/ import { type } from '@lowdefy/helpers';
|
|
16
|
+
import runInstance from '../runInstance.js';
|
|
17
|
+
const prepRegex = (regexIndex, flagsIndex)=>(args)=>{
|
|
18
|
+
if (args[regexIndex]) {
|
|
19
|
+
args[regexIndex] = new RegExp(args[regexIndex], args[flagsIndex]);
|
|
20
|
+
}
|
|
21
|
+
if (type.isNone(args[0])) {
|
|
22
|
+
args[0] = '';
|
|
23
|
+
}
|
|
24
|
+
return args;
|
|
25
|
+
}
|
|
26
|
+
;
|
|
27
|
+
const prep = (args)=>{
|
|
28
|
+
if (type.isNone(args[0])) {
|
|
29
|
+
args[0] = '';
|
|
30
|
+
}
|
|
31
|
+
return args;
|
|
39
32
|
};
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
33
|
+
const meta = {
|
|
34
|
+
charAt: {
|
|
35
|
+
namedArgs: [
|
|
36
|
+
'on',
|
|
37
|
+
'index'
|
|
38
|
+
],
|
|
39
|
+
prep,
|
|
40
|
+
validTypes: [
|
|
41
|
+
'array',
|
|
42
|
+
'object'
|
|
43
|
+
]
|
|
44
|
+
},
|
|
45
|
+
// 'charCodeAt',
|
|
46
|
+
concat: {
|
|
47
|
+
prep,
|
|
48
|
+
validTypes: [
|
|
49
|
+
'array'
|
|
50
|
+
]
|
|
51
|
+
},
|
|
52
|
+
endsWith: {
|
|
53
|
+
namedArgs: [
|
|
54
|
+
'on',
|
|
55
|
+
'searchString',
|
|
56
|
+
'length'
|
|
57
|
+
],
|
|
58
|
+
prep,
|
|
59
|
+
validTypes: [
|
|
60
|
+
'array',
|
|
61
|
+
'object'
|
|
62
|
+
]
|
|
63
|
+
},
|
|
64
|
+
includes: {
|
|
65
|
+
namedArgs: [
|
|
66
|
+
'on',
|
|
67
|
+
'searchString',
|
|
68
|
+
'position'
|
|
69
|
+
],
|
|
70
|
+
prep,
|
|
71
|
+
validTypes: [
|
|
72
|
+
'array',
|
|
73
|
+
'object'
|
|
74
|
+
]
|
|
75
|
+
},
|
|
76
|
+
indexOf: {
|
|
77
|
+
namedArgs: [
|
|
78
|
+
'on',
|
|
79
|
+
'searchValue',
|
|
80
|
+
'fromIndex'
|
|
81
|
+
],
|
|
82
|
+
prep,
|
|
83
|
+
validTypes: [
|
|
84
|
+
'array',
|
|
85
|
+
'object'
|
|
86
|
+
]
|
|
87
|
+
},
|
|
88
|
+
lastIndexOf: {
|
|
89
|
+
namedArgs: [
|
|
90
|
+
'on',
|
|
91
|
+
'searchValue',
|
|
92
|
+
'fromIndex'
|
|
93
|
+
],
|
|
94
|
+
prep,
|
|
95
|
+
validTypes: [
|
|
96
|
+
'array',
|
|
97
|
+
'object'
|
|
98
|
+
]
|
|
99
|
+
},
|
|
100
|
+
// 'localeCompare',
|
|
101
|
+
match: {
|
|
102
|
+
namedArgs: [
|
|
103
|
+
'on',
|
|
104
|
+
'regex',
|
|
105
|
+
'regexFlags'
|
|
106
|
+
],
|
|
107
|
+
prep: prepRegex(1, 2),
|
|
108
|
+
validTypes: [
|
|
109
|
+
'array',
|
|
110
|
+
'object'
|
|
111
|
+
]
|
|
112
|
+
},
|
|
113
|
+
// 'matchAll',
|
|
114
|
+
normalize: {
|
|
115
|
+
namedArgs: [
|
|
116
|
+
'on',
|
|
117
|
+
'form'
|
|
118
|
+
],
|
|
119
|
+
prep,
|
|
120
|
+
validTypes: [
|
|
121
|
+
'array',
|
|
122
|
+
'object'
|
|
123
|
+
]
|
|
124
|
+
},
|
|
125
|
+
padEnd: {
|
|
126
|
+
namedArgs: [
|
|
127
|
+
'on',
|
|
128
|
+
'targetLength',
|
|
129
|
+
'padString'
|
|
130
|
+
],
|
|
131
|
+
prep,
|
|
132
|
+
validTypes: [
|
|
133
|
+
'array',
|
|
134
|
+
'object'
|
|
135
|
+
]
|
|
136
|
+
},
|
|
137
|
+
padStart: {
|
|
138
|
+
namedArgs: [
|
|
139
|
+
'on',
|
|
140
|
+
'targetLength',
|
|
141
|
+
'padString'
|
|
142
|
+
],
|
|
143
|
+
prep,
|
|
144
|
+
validTypes: [
|
|
145
|
+
'array',
|
|
146
|
+
'object'
|
|
147
|
+
]
|
|
148
|
+
},
|
|
149
|
+
repeat: {
|
|
150
|
+
namedArgs: [
|
|
151
|
+
'on',
|
|
152
|
+
'count'
|
|
153
|
+
],
|
|
154
|
+
prep,
|
|
155
|
+
validTypes: [
|
|
156
|
+
'array',
|
|
157
|
+
'object'
|
|
158
|
+
]
|
|
159
|
+
},
|
|
160
|
+
replace: {
|
|
161
|
+
namedArgs: [
|
|
162
|
+
'on',
|
|
163
|
+
'regex',
|
|
164
|
+
'newSubstr',
|
|
165
|
+
'regexFlags'
|
|
166
|
+
],
|
|
167
|
+
prep: prepRegex(1, 3),
|
|
168
|
+
validTypes: [
|
|
169
|
+
'array',
|
|
170
|
+
'object'
|
|
171
|
+
]
|
|
172
|
+
},
|
|
173
|
+
search: {
|
|
174
|
+
namedArgs: [
|
|
175
|
+
'on',
|
|
176
|
+
'regex',
|
|
177
|
+
'regexFlags'
|
|
178
|
+
],
|
|
179
|
+
prep: prepRegex(1, 2),
|
|
180
|
+
validTypes: [
|
|
181
|
+
'array',
|
|
182
|
+
'object'
|
|
183
|
+
]
|
|
184
|
+
},
|
|
185
|
+
slice: {
|
|
186
|
+
namedArgs: [
|
|
187
|
+
'on',
|
|
188
|
+
'start',
|
|
189
|
+
'end'
|
|
190
|
+
],
|
|
191
|
+
prep,
|
|
192
|
+
validTypes: [
|
|
193
|
+
'array',
|
|
194
|
+
'object'
|
|
195
|
+
]
|
|
196
|
+
},
|
|
197
|
+
split: {
|
|
198
|
+
namedArgs: [
|
|
199
|
+
'on',
|
|
200
|
+
'separator'
|
|
201
|
+
],
|
|
202
|
+
prep,
|
|
203
|
+
validTypes: [
|
|
204
|
+
'array',
|
|
205
|
+
'object'
|
|
206
|
+
]
|
|
207
|
+
},
|
|
208
|
+
startsWith: {
|
|
209
|
+
namedArgs: [
|
|
210
|
+
'on',
|
|
211
|
+
'searchString',
|
|
212
|
+
'position'
|
|
213
|
+
],
|
|
214
|
+
prep,
|
|
215
|
+
validTypes: [
|
|
216
|
+
'array',
|
|
217
|
+
'object'
|
|
218
|
+
]
|
|
219
|
+
},
|
|
220
|
+
substring: {
|
|
221
|
+
namedArgs: [
|
|
222
|
+
'on',
|
|
223
|
+
'start',
|
|
224
|
+
'end'
|
|
225
|
+
],
|
|
226
|
+
prep,
|
|
227
|
+
validTypes: [
|
|
228
|
+
'array',
|
|
229
|
+
'object'
|
|
230
|
+
]
|
|
231
|
+
},
|
|
232
|
+
// toLocaleLowerCase: { namedArgs: ['on', 'locale'], validTypes: ['array', 'object'] },
|
|
233
|
+
// toLocaleUpperCase: { namedArgs: ['on', 'locale'], validTypes: ['array', 'object'] },
|
|
234
|
+
toLowerCase: {
|
|
235
|
+
validTypes: [
|
|
236
|
+
'string'
|
|
237
|
+
],
|
|
238
|
+
singleArg: true,
|
|
239
|
+
prep
|
|
240
|
+
},
|
|
241
|
+
toUpperCase: {
|
|
242
|
+
validTypes: [
|
|
243
|
+
'string'
|
|
244
|
+
],
|
|
245
|
+
singleArg: true,
|
|
246
|
+
prep
|
|
247
|
+
},
|
|
248
|
+
trim: {
|
|
249
|
+
validTypes: [
|
|
250
|
+
'string'
|
|
251
|
+
],
|
|
252
|
+
singleArg: true,
|
|
253
|
+
prep
|
|
254
|
+
},
|
|
255
|
+
trimEnd: {
|
|
256
|
+
validTypes: [
|
|
257
|
+
'string'
|
|
258
|
+
],
|
|
259
|
+
singleArg: true,
|
|
260
|
+
prep
|
|
261
|
+
},
|
|
262
|
+
trimStart: {
|
|
263
|
+
validTypes: [
|
|
264
|
+
'string'
|
|
265
|
+
],
|
|
266
|
+
singleArg: true,
|
|
267
|
+
prep
|
|
268
|
+
},
|
|
269
|
+
length: {
|
|
270
|
+
validTypes: [
|
|
271
|
+
'string'
|
|
272
|
+
],
|
|
273
|
+
property: true,
|
|
274
|
+
prep
|
|
275
|
+
}
|
|
169
276
|
};
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
meta,
|
|
180
|
-
methodName,
|
|
181
|
-
operator: '_string',
|
|
182
|
-
params,
|
|
183
|
-
instanceType: 'string'
|
|
184
|
-
});
|
|
277
|
+
function _string({ params , location , methodName }) {
|
|
278
|
+
return runInstance({
|
|
279
|
+
location,
|
|
280
|
+
meta,
|
|
281
|
+
methodName,
|
|
282
|
+
operator: '_string',
|
|
283
|
+
params,
|
|
284
|
+
instanceType: 'string'
|
|
285
|
+
});
|
|
185
286
|
}
|
|
186
|
-
|
|
187
|
-
var _default = _string;
|
|
188
|
-
exports.default = _default;
|
|
287
|
+
export default _string;
|
package/dist/common/subtract.js
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _helpers = require("@lowdefy/helpers");
|
|
9
|
-
|
|
10
1
|
/*
|
|
11
2
|
Copyright 2020-2021 Lowdefy, Inc
|
|
12
3
|
|
|
@@ -21,27 +12,17 @@ var _helpers = require("@lowdefy/helpers");
|
|
|
21
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
22
13
|
See the License for the specific language governing permissions and
|
|
23
14
|
limitations under the License.
|
|
24
|
-
*/
|
|
25
|
-
function _subtract(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
throw new Error("Operator Error: _subtract takes an array of length 2 as input. Received: ".concat(JSON.stringify(params), " at ").concat(location, "."));
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (!_helpers.type.isNumber(params[0]) || !_helpers.type.isNumber(params[1])) {
|
|
40
|
-
throw new Error("Operator Error: _subtract takes an array of 2 numbers. Received: ".concat(JSON.stringify(params), " at ").concat(location, "."));
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return params[0] - params[1];
|
|
15
|
+
*/ import { type } from '@lowdefy/helpers';
|
|
16
|
+
function _subtract({ params , location }) {
|
|
17
|
+
if (!type.isArray(params)) {
|
|
18
|
+
throw new Error(`Operator Error: _subtract takes an array type as input. Received: ${JSON.stringify(params)} at ${location}.`);
|
|
19
|
+
}
|
|
20
|
+
if (params.length !== 2) {
|
|
21
|
+
throw new Error(`Operator Error: _subtract takes an array of length 2 as input. Received: ${JSON.stringify(params)} at ${location}.`);
|
|
22
|
+
}
|
|
23
|
+
if (!type.isNumber(params[0]) || !type.isNumber(params[1])) {
|
|
24
|
+
throw new Error(`Operator Error: _subtract takes an array of 2 numbers. Received: ${JSON.stringify(params)} at ${location}.`);
|
|
25
|
+
}
|
|
26
|
+
return params[0] - params[1];
|
|
44
27
|
}
|
|
45
|
-
|
|
46
|
-
var _default = _subtract;
|
|
47
|
-
exports.default = _default;
|
|
28
|
+
export default _subtract;
|
package/dist/common/sum.js
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _helpers = require("@lowdefy/helpers");
|
|
9
|
-
|
|
10
1
|
/*
|
|
11
2
|
Copyright 2020-2021 Lowdefy, Inc
|
|
12
3
|
|
|
@@ -21,25 +12,16 @@ var _helpers = require("@lowdefy/helpers");
|
|
|
21
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
22
13
|
See the License for the specific language governing permissions and
|
|
23
14
|
limitations under the License.
|
|
24
|
-
*/
|
|
25
|
-
function _sum(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
location
|
|
29
|
-
} = _ref;
|
|
30
|
-
|
|
31
|
-
if (!_helpers.type.isArray(params)) {
|
|
32
|
-
throw new Error("Operator Error: _sum takes an array type as input. Received: ".concat(JSON.stringify(params), " at ").concat(location, "."));
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return params.reduce((accumulator, value) => {
|
|
36
|
-
if (_helpers.type.isNumber(value)) {
|
|
37
|
-
return accumulator + value;
|
|
15
|
+
*/ import { type } from '@lowdefy/helpers';
|
|
16
|
+
function _sum({ params , location }) {
|
|
17
|
+
if (!type.isArray(params)) {
|
|
18
|
+
throw new Error(`Operator Error: _sum takes an array type as input. Received: ${JSON.stringify(params)} at ${location}.`);
|
|
38
19
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
20
|
+
return params.reduce((accumulator, value)=>{
|
|
21
|
+
if (type.isNumber(value)) {
|
|
22
|
+
return accumulator + value;
|
|
23
|
+
}
|
|
24
|
+
return accumulator;
|
|
25
|
+
}, 0);
|
|
42
26
|
}
|
|
43
|
-
|
|
44
|
-
var _default = _sum;
|
|
45
|
-
exports.default = _default;
|
|
27
|
+
export default _sum;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2021 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import { type } from '@lowdefy/helpers';
|
|
16
|
+
function _switch({ location , params }) {
|
|
17
|
+
if (!type.isArray(params.branches)) {
|
|
18
|
+
throw new Error(`Operator Error: switch takes an array type as input for the branches. Received: ${JSON.stringify(params)} at ${location}.`);
|
|
19
|
+
}
|
|
20
|
+
for (const branch of params.branches){
|
|
21
|
+
if (!type.isBoolean(branch.if)) {
|
|
22
|
+
throw new Error(`Operator Error: switch takes a boolean type for parameter test. Received: ${JSON.stringify(params)} at ${location}.`);
|
|
23
|
+
}
|
|
24
|
+
if (branch.if === true) {
|
|
25
|
+
return branch.then;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return params.default;
|
|
29
|
+
}
|
|
30
|
+
export default _switch;
|