@lowdefy/operators-js 0.0.0-experimental-20231123101256

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.
Files changed (61) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +3 -0
  3. package/dist/index.js +17 -0
  4. package/dist/operators/build/env.js +25 -0
  5. package/dist/operators/client/_index.js +25 -0
  6. package/dist/operators/client/actions.js +25 -0
  7. package/dist/operators/client/base64.js +50 -0
  8. package/dist/operators/client/event.js +25 -0
  9. package/dist/operators/client/event_log.js +25 -0
  10. package/dist/operators/client/global.js +25 -0
  11. package/dist/operators/client/input.js +25 -0
  12. package/dist/operators/client/location.js +60 -0
  13. package/dist/operators/client/media.js +62 -0
  14. package/dist/operators/client/menu.js +25 -0
  15. package/dist/operators/client/request.js +34 -0
  16. package/dist/operators/client/request_details.js +25 -0
  17. package/dist/operators/client/state.js +25 -0
  18. package/dist/operators/client/url_query.js +30 -0
  19. package/dist/operators/server/base64.js +52 -0
  20. package/dist/operators/server/hash.js +84 -0
  21. package/dist/operators/server/payload.js +24 -0
  22. package/dist/operators/server/secret.js +32 -0
  23. package/dist/operators/shared/and.js +22 -0
  24. package/dist/operators/shared/args.js +25 -0
  25. package/dist/operators/shared/array.js +263 -0
  26. package/dist/operators/shared/date.js +449 -0
  27. package/dist/operators/shared/divide.js +31 -0
  28. package/dist/operators/shared/eq.js +25 -0
  29. package/dist/operators/shared/function.js +32 -0
  30. package/dist/operators/shared/get.js +36 -0
  31. package/dist/operators/shared/gt.js +25 -0
  32. package/dist/operators/shared/gte.js +25 -0
  33. package/dist/operators/shared/if.js +24 -0
  34. package/dist/operators/shared/if_none.js +28 -0
  35. package/dist/operators/shared/intl.js +94 -0
  36. package/dist/operators/shared/json.js +60 -0
  37. package/dist/operators/shared/log.js +20 -0
  38. package/dist/operators/shared/lt.js +25 -0
  39. package/dist/operators/shared/lte.js +25 -0
  40. package/dist/operators/shared/math.js +271 -0
  41. package/dist/operators/shared/ne.js +25 -0
  42. package/dist/operators/shared/not.js +18 -0
  43. package/dist/operators/shared/number.js +146 -0
  44. package/dist/operators/shared/object.js +129 -0
  45. package/dist/operators/shared/operator.js +38 -0
  46. package/dist/operators/shared/or.js +22 -0
  47. package/dist/operators/shared/product.js +27 -0
  48. package/dist/operators/shared/random.js +97 -0
  49. package/dist/operators/shared/regex.js +42 -0
  50. package/dist/operators/shared/string.js +292 -0
  51. package/dist/operators/shared/subtract.js +28 -0
  52. package/dist/operators/shared/sum.js +27 -0
  53. package/dist/operators/shared/switch.js +30 -0
  54. package/dist/operators/shared/type.js +51 -0
  55. package/dist/operators/shared/uri.js +50 -0
  56. package/dist/operators/shared/user.js +25 -0
  57. package/dist/operatorsBuild.js +88 -0
  58. package/dist/operatorsClient.js +62 -0
  59. package/dist/operatorsServer.js +52 -0
  60. package/dist/types.js +22 -0
  61. package/package.json +64 -0
@@ -0,0 +1,129 @@
1
+ /*
2
+ Copyright 2020-2023 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
+ import { runClass, runInstance } from '@lowdefy/operators';
17
+ const prep = (args)=>{
18
+ if (type.isNone(args[0])) {
19
+ args[0] = {};
20
+ }
21
+ return args;
22
+ };
23
+ const prepArray = (args)=>{
24
+ if (type.isNone(args[0])) {
25
+ args[0] = [];
26
+ }
27
+ return args;
28
+ };
29
+ const prepDescriptor = (args)=>{
30
+ const descriptor = args[2] || {};
31
+ if (type.isNone(descriptor.enumerable)) {
32
+ descriptor.enumerable = true;
33
+ }
34
+ if (type.isNone(descriptor.configurable)) {
35
+ descriptor.configurable = true;
36
+ }
37
+ args[2] = descriptor;
38
+ if (type.isNone(args[0])) {
39
+ args[0] = {};
40
+ }
41
+ return args;
42
+ };
43
+ const metaInstance = {
44
+ hasOwnProperty: {
45
+ namedArgs: [
46
+ 'on',
47
+ 'prop'
48
+ ],
49
+ validTypes: [
50
+ 'array',
51
+ 'object'
52
+ ],
53
+ prep
54
+ }
55
+ };
56
+ const metaClass = {
57
+ assign: {
58
+ spreadArgs: true,
59
+ validTypes: [
60
+ 'array'
61
+ ],
62
+ prep
63
+ },
64
+ defineProperty: {
65
+ namedArgs: [
66
+ 'on',
67
+ 'key',
68
+ 'descriptor'
69
+ ],
70
+ validTypes: [
71
+ 'array',
72
+ 'object'
73
+ ],
74
+ prep: prepDescriptor
75
+ },
76
+ entries: {
77
+ singleArg: true,
78
+ validTypes: [
79
+ 'object',
80
+ 'null'
81
+ ],
82
+ prep
83
+ },
84
+ fromEntries: {
85
+ singleArg: true,
86
+ validTypes: [
87
+ 'array',
88
+ 'null'
89
+ ],
90
+ prep: prepArray
91
+ },
92
+ keys: {
93
+ singleArg: true,
94
+ validTypes: [
95
+ 'object',
96
+ 'null'
97
+ ],
98
+ prep
99
+ },
100
+ values: {
101
+ singleArg: true,
102
+ validTypes: [
103
+ 'object',
104
+ 'null'
105
+ ],
106
+ prep
107
+ }
108
+ };
109
+ function _object({ params, location, methodName }) {
110
+ if (methodName === 'hasOwnProperty') {
111
+ return runInstance({
112
+ location,
113
+ meta: metaInstance,
114
+ methodName,
115
+ operator: '_object',
116
+ params,
117
+ instanceType: 'object'
118
+ });
119
+ }
120
+ return runClass({
121
+ functions: Object,
122
+ location,
123
+ meta: metaClass,
124
+ methodName,
125
+ operator: '_object',
126
+ params
127
+ });
128
+ }
129
+ export default _object;
@@ -0,0 +1,38 @@
1
+ /*
2
+ Copyright 2020-2023 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 _operator(options) {
17
+ const { operators, params, location } = options;
18
+ if (!type.isString(params.name)) {
19
+ throw new Error(`Operator Error: _operator.name must be a valid operator name as string. Received: ${JSON.stringify(params)} at ${location}.`);
20
+ }
21
+ if (params.name === '_operator') {
22
+ throw new Error(`Operator Error: _operator.name cannot be set to _operator to infinite avoid loop reference. Received: ${JSON.stringify(params)} at ${location}.`);
23
+ }
24
+ if (params.name.includes('experimental')) {
25
+ throw new Error(`Operator Error: Experimental operators cannot be used with _operator. Received: ${JSON.stringify(params)} at ${location}.`);
26
+ }
27
+ const [operator, methodName] = params.name.split('.');
28
+ if (Object.prototype.hasOwnProperty.call(operators, operator)) {
29
+ return operators[operator]({
30
+ ...options,
31
+ location,
32
+ params: params?.params,
33
+ methodName
34
+ });
35
+ }
36
+ throw new Error(`Operator Error: _operator - Invalid operator name. Received: ${JSON.stringify(params)} at ${location}.`);
37
+ }
38
+ export default _operator;
@@ -0,0 +1,22 @@
1
+ /*
2
+ Copyright 2020-2023 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 _or({ location, params }) {
17
+ if (!type.isArray(params)) {
18
+ throw new Error(`Operator Error: _or takes an array type. Received: ${JSON.stringify(params)} at ${location}.`);
19
+ }
20
+ return !!params.reduce((acc, el)=>acc || el, false);
21
+ }
22
+ export default _or;
@@ -0,0 +1,27 @@
1
+ /*
2
+ Copyright 2020-2023 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 _product({ params, location }) {
17
+ if (!type.isArray(params)) {
18
+ throw new Error(`Operator Error: _product takes an array type as input. Received: ${JSON.stringify(params)} at ${location}.`);
19
+ }
20
+ return params.reduce((accumulator, value)=>{
21
+ if (type.isNumber(value)) {
22
+ return accumulator * value;
23
+ }
24
+ return accumulator;
25
+ }, 1);
26
+ }
27
+ export default _product;
@@ -0,0 +1,97 @@
1
+ /*
2
+ Copyright 2020-2023 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
+ const typesEnum = [
17
+ 'string',
18
+ 'integer',
19
+ 'float'
20
+ ];
21
+ function generateRandomString(length, randomString = '') {
22
+ randomString += Math.random().toString(36).substr(2, length);
23
+ if (randomString.length > length) return randomString.slice(0, length);
24
+ return generateRandomString(length, randomString);
25
+ }
26
+ // Both minimum and maximum is inclusive.
27
+ function getRandomInt(min, max) {
28
+ return Math.floor(Math.random() * (Math.ceil(max) - Math.floor(min)) + Math.floor(min));
29
+ }
30
+ function getRandomFloat(min, max) {
31
+ return Math.random() * (Math.ceil(max) - Math.floor(min)) + Math.floor(min);
32
+ }
33
+ function evaluateDefaultNumber({ key, defaultValue, params, location }) {
34
+ if (type.isUndefined(params[key])) {
35
+ params[key] = defaultValue;
36
+ }
37
+ if (!type.isNumber(params[key])) {
38
+ throw new Error(`Operator Error: _random.${key} takes an number type. Received: ${JSON.stringify(params)} at ${location}.`);
39
+ }
40
+ }
41
+ function _random({ location, params }) {
42
+ if (!type.isString(params) && !type.isObject(params)) {
43
+ throw new Error(`Operator Error: _random takes an string or object type. Received: ${JSON.stringify(params)} at ${location}.`);
44
+ }
45
+ if (!type.isObject(params)) {
46
+ params = {
47
+ type: params
48
+ };
49
+ }
50
+ if (!typesEnum.includes(params.type)) {
51
+ throw new Error(`Operator Error: _random type can be either 'string', 'integer' or 'float'. Received: ${JSON.stringify(params)} at ${location}.`);
52
+ }
53
+ if (params.type === 'float') {
54
+ evaluateDefaultNumber({
55
+ key: 'min',
56
+ defaultValue: 0,
57
+ params,
58
+ location
59
+ });
60
+ evaluateDefaultNumber({
61
+ key: 'max',
62
+ defaultValue: params.min + 1,
63
+ params,
64
+ location
65
+ });
66
+ if (params.max < params.min) {
67
+ throw new Error(`Operator Error: _random.min must be less than _random.max. Received: ${JSON.stringify(params)} at ${location}.`);
68
+ }
69
+ return getRandomFloat(params.min, params.max);
70
+ }
71
+ if (params.type === 'integer') {
72
+ evaluateDefaultNumber({
73
+ key: 'min',
74
+ defaultValue: 0,
75
+ params,
76
+ location
77
+ });
78
+ evaluateDefaultNumber({
79
+ key: 'max',
80
+ defaultValue: params.min + 100,
81
+ params,
82
+ location
83
+ });
84
+ if (params.max < params.min) {
85
+ throw new Error(`Operator Error: _random.min must be less than _random.max. Received: ${JSON.stringify(params)} at ${location}.`);
86
+ }
87
+ return getRandomInt(params.min, params.max);
88
+ }
89
+ evaluateDefaultNumber({
90
+ key: 'length',
91
+ defaultValue: 8,
92
+ params,
93
+ location
94
+ });
95
+ return generateRandomString(params.length);
96
+ }
97
+ export default _random;
@@ -0,0 +1,42 @@
1
+ /*
2
+ Copyright 2020-2023 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 { get, type } from '@lowdefy/helpers';
16
+ function _regex({ location, params, state }) {
17
+ const pattern = type.isObject(params) ? params.pattern : params;
18
+ if (!type.isString(pattern)) {
19
+ throw new Error(`Operator Error: _regex.pattern must be a string. Received: ${JSON.stringify(params)} at ${location}.`);
20
+ }
21
+ let on = !type.isUndefined(params.on) ? params.on : get(state, location);
22
+ if (!type.isUndefined(params.key)) {
23
+ if (!type.isString(params.key)) {
24
+ throw new Error(`Operator Error: _regex.key must be a string. Received: ${JSON.stringify(params)} at ${location}.`);
25
+ }
26
+ on = get(state, params.key);
27
+ }
28
+ if (type.isNone(on)) {
29
+ return false;
30
+ }
31
+ if (!type.isString(on)) {
32
+ throw new Error(`Operator Error: _regex.on must be a string. Received: ${JSON.stringify(params)} at ${location}.`);
33
+ }
34
+ try {
35
+ const re = new RegExp(pattern, params.flags || 'gm');
36
+ return re.test(on);
37
+ } catch (e) {
38
+ // log e to LowdefyError
39
+ throw new Error(`Operator Error: _regex failed to execute RegExp.test. Received: ${JSON.stringify(params)} at ${location}.`);
40
+ }
41
+ }
42
+ export default _regex;
@@ -0,0 +1,292 @@
1
+ /*
2
+ Copyright 2020-2023 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
+ import { runInstance } from '@lowdefy/operators';
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
+ const prep = (args)=>{
27
+ if (type.isNone(args[0])) {
28
+ args[0] = '';
29
+ }
30
+ return args;
31
+ };
32
+ const meta = {
33
+ charAt: {
34
+ namedArgs: [
35
+ 'on',
36
+ 'index'
37
+ ],
38
+ prep,
39
+ validTypes: [
40
+ 'array',
41
+ 'object'
42
+ ]
43
+ },
44
+ // 'charCodeAt',
45
+ concat: {
46
+ prep,
47
+ validTypes: [
48
+ 'array'
49
+ ]
50
+ },
51
+ endsWith: {
52
+ namedArgs: [
53
+ 'on',
54
+ 'searchString',
55
+ 'length'
56
+ ],
57
+ prep,
58
+ validTypes: [
59
+ 'array',
60
+ 'object'
61
+ ]
62
+ },
63
+ includes: {
64
+ namedArgs: [
65
+ 'on',
66
+ 'searchString',
67
+ 'position'
68
+ ],
69
+ prep,
70
+ validTypes: [
71
+ 'array',
72
+ 'object'
73
+ ]
74
+ },
75
+ indexOf: {
76
+ namedArgs: [
77
+ 'on',
78
+ 'searchValue',
79
+ 'fromIndex'
80
+ ],
81
+ prep,
82
+ validTypes: [
83
+ 'array',
84
+ 'object'
85
+ ]
86
+ },
87
+ lastIndexOf: {
88
+ namedArgs: [
89
+ 'on',
90
+ 'searchValue',
91
+ 'fromIndex'
92
+ ],
93
+ prep,
94
+ validTypes: [
95
+ 'array',
96
+ 'object'
97
+ ]
98
+ },
99
+ // 'localeCompare',
100
+ match: {
101
+ namedArgs: [
102
+ 'on',
103
+ 'regex',
104
+ 'regexFlags'
105
+ ],
106
+ prep: prepRegex(1, 2),
107
+ validTypes: [
108
+ 'array',
109
+ 'object'
110
+ ]
111
+ },
112
+ // 'matchAll',
113
+ normalize: {
114
+ namedArgs: [
115
+ 'on',
116
+ 'form'
117
+ ],
118
+ prep,
119
+ validTypes: [
120
+ 'array',
121
+ 'object'
122
+ ]
123
+ },
124
+ padEnd: {
125
+ namedArgs: [
126
+ 'on',
127
+ 'targetLength',
128
+ 'padString'
129
+ ],
130
+ prep,
131
+ validTypes: [
132
+ 'array',
133
+ 'object'
134
+ ]
135
+ },
136
+ padStart: {
137
+ namedArgs: [
138
+ 'on',
139
+ 'targetLength',
140
+ 'padString'
141
+ ],
142
+ prep,
143
+ validTypes: [
144
+ 'array',
145
+ 'object'
146
+ ]
147
+ },
148
+ repeat: {
149
+ namedArgs: [
150
+ 'on',
151
+ 'count'
152
+ ],
153
+ prep,
154
+ validTypes: [
155
+ 'array',
156
+ 'object'
157
+ ]
158
+ },
159
+ replace: {
160
+ namedArgs: [
161
+ 'on',
162
+ 'regex',
163
+ 'newSubstr',
164
+ 'regexFlags'
165
+ ],
166
+ prep: prepRegex(1, 3),
167
+ validTypes: [
168
+ 'array',
169
+ 'object'
170
+ ]
171
+ },
172
+ search: {
173
+ namedArgs: [
174
+ 'on',
175
+ 'regex',
176
+ 'regexFlags'
177
+ ],
178
+ prep: prepRegex(1, 2),
179
+ validTypes: [
180
+ 'array',
181
+ 'object'
182
+ ]
183
+ },
184
+ slice: {
185
+ namedArgs: [
186
+ 'on',
187
+ 'start',
188
+ 'end'
189
+ ],
190
+ prep,
191
+ validTypes: [
192
+ 'array',
193
+ 'object'
194
+ ]
195
+ },
196
+ split: {
197
+ namedArgs: [
198
+ 'on',
199
+ 'separator'
200
+ ],
201
+ prep,
202
+ validTypes: [
203
+ 'array',
204
+ 'object'
205
+ ]
206
+ },
207
+ startsWith: {
208
+ namedArgs: [
209
+ 'on',
210
+ 'searchString',
211
+ 'position'
212
+ ],
213
+ prep,
214
+ validTypes: [
215
+ 'array',
216
+ 'object'
217
+ ]
218
+ },
219
+ substring: {
220
+ namedArgs: [
221
+ 'on',
222
+ 'start',
223
+ 'end'
224
+ ],
225
+ prep,
226
+ validTypes: [
227
+ 'array',
228
+ 'object'
229
+ ]
230
+ },
231
+ // toLocaleLowerCase: { namedArgs: ['on', 'locale'], validTypes: ['array', 'object'] },
232
+ // toLocaleUpperCase: { namedArgs: ['on', 'locale'], validTypes: ['array', 'object'] },
233
+ toLowerCase: {
234
+ validTypes: [
235
+ 'string',
236
+ 'null'
237
+ ],
238
+ singleArg: true,
239
+ prep
240
+ },
241
+ toUpperCase: {
242
+ validTypes: [
243
+ 'string',
244
+ 'null'
245
+ ],
246
+ singleArg: true,
247
+ prep
248
+ },
249
+ trim: {
250
+ validTypes: [
251
+ 'string',
252
+ 'null'
253
+ ],
254
+ singleArg: true,
255
+ prep
256
+ },
257
+ trimEnd: {
258
+ validTypes: [
259
+ 'string',
260
+ 'null'
261
+ ],
262
+ singleArg: true,
263
+ prep
264
+ },
265
+ trimStart: {
266
+ validTypes: [
267
+ 'string',
268
+ 'null'
269
+ ],
270
+ singleArg: true,
271
+ prep
272
+ },
273
+ length: {
274
+ validTypes: [
275
+ 'string',
276
+ 'null'
277
+ ],
278
+ property: true,
279
+ prep
280
+ }
281
+ };
282
+ function _string({ params, location, methodName }) {
283
+ return runInstance({
284
+ location,
285
+ meta,
286
+ methodName,
287
+ operator: '_string',
288
+ params,
289
+ instanceType: 'string'
290
+ });
291
+ }
292
+ export default _string;
@@ -0,0 +1,28 @@
1
+ /*
2
+ Copyright 2020-2023 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 _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];
27
+ }
28
+ export default _subtract;
@@ -0,0 +1,27 @@
1
+ /*
2
+ Copyright 2020-2023 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 _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}.`);
19
+ }
20
+ return params.reduce((accumulator, value)=>{
21
+ if (type.isNumber(value)) {
22
+ return accumulator + value;
23
+ }
24
+ return accumulator;
25
+ }, 0);
26
+ }
27
+ export default _sum;