@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/type.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,62 +12,40 @@ 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 _type(
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return _helpers.type.isNumber(on);
|
|
60
|
-
|
|
61
|
-
case 'integer':
|
|
62
|
-
return _helpers.type.isInt(on);
|
|
63
|
-
|
|
64
|
-
case 'null':
|
|
65
|
-
return _helpers.type.isNull(on);
|
|
66
|
-
|
|
67
|
-
case 'undefined':
|
|
68
|
-
return _helpers.type.isUndefined(on);
|
|
69
|
-
|
|
70
|
-
case 'none':
|
|
71
|
-
return _helpers.type.isNone(on);
|
|
72
|
-
|
|
73
|
-
case 'primitive':
|
|
74
|
-
return _helpers.type.isPrimitive(on);
|
|
75
|
-
|
|
76
|
-
default:
|
|
77
|
-
throw new Error("Operator Error: \"".concat(typeName, "\" is not a valid _type test. Received: ").concat(JSON.stringify(params), " at ").concat(location, "."));
|
|
78
|
-
}
|
|
15
|
+
*/ import { get, type } from '@lowdefy/helpers';
|
|
16
|
+
function _type({ location , params , state }) {
|
|
17
|
+
const typeName = type.isObject(params) ? params.type : params;
|
|
18
|
+
if (!type.isString(typeName)) {
|
|
19
|
+
throw new Error(`Operator Error: _type.type must be a string. Received: ${JSON.stringify(params)} at ${location}.`);
|
|
20
|
+
}
|
|
21
|
+
const on = Object.prototype.hasOwnProperty.call(params, 'on') ? params.on : get(state, get(params, 'key', {
|
|
22
|
+
default: location
|
|
23
|
+
}));
|
|
24
|
+
switch(typeName){
|
|
25
|
+
case 'string':
|
|
26
|
+
return type.isString(on);
|
|
27
|
+
case 'array':
|
|
28
|
+
return type.isArray(on);
|
|
29
|
+
case 'date':
|
|
30
|
+
return type.isDate(on); // Testing for date is problematic due to stringify
|
|
31
|
+
case 'object':
|
|
32
|
+
return type.isObject(on);
|
|
33
|
+
case 'boolean':
|
|
34
|
+
return type.isBoolean(on);
|
|
35
|
+
case 'number':
|
|
36
|
+
return type.isNumber(on);
|
|
37
|
+
case 'integer':
|
|
38
|
+
return type.isInt(on);
|
|
39
|
+
case 'null':
|
|
40
|
+
return type.isNull(on);
|
|
41
|
+
case 'undefined':
|
|
42
|
+
return type.isUndefined(on);
|
|
43
|
+
case 'none':
|
|
44
|
+
return type.isNone(on);
|
|
45
|
+
case 'primitive':
|
|
46
|
+
return type.isPrimitive(on);
|
|
47
|
+
default:
|
|
48
|
+
throw new Error(`Operator Error: "${typeName}" is not a valid _type test. Received: ${JSON.stringify(params)} at ${location}.`);
|
|
49
|
+
}
|
|
79
50
|
}
|
|
80
|
-
|
|
81
|
-
var _default = _type;
|
|
82
|
-
exports.default = _default;
|
|
51
|
+
export default _type;
|
package/dist/common/uri.js
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _runClass = _interopRequireDefault(require("../runClass"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
1
|
/*
|
|
13
2
|
Copyright 2020-2021 Lowdefy, Inc
|
|
14
3
|
|
|
@@ -23,45 +12,39 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
23
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
24
13
|
See the License for the specific language governing permissions and
|
|
25
14
|
limitations under the License.
|
|
26
|
-
*/
|
|
15
|
+
*/ import runClass from '../runClass.js';
|
|
27
16
|
function decode(input) {
|
|
28
|
-
|
|
17
|
+
return decodeURIComponent(input);
|
|
29
18
|
}
|
|
30
|
-
|
|
31
19
|
function encode(input) {
|
|
32
|
-
|
|
20
|
+
return encodeURIComponent(input);
|
|
33
21
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
decode
|
|
22
|
+
const functions = {
|
|
23
|
+
encode,
|
|
24
|
+
decode
|
|
38
25
|
};
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
26
|
+
const meta = {
|
|
27
|
+
encode: {
|
|
28
|
+
singleArg: true,
|
|
29
|
+
validTypes: [
|
|
30
|
+
'string'
|
|
31
|
+
]
|
|
32
|
+
},
|
|
33
|
+
decode: {
|
|
34
|
+
singleArg: true,
|
|
35
|
+
validTypes: [
|
|
36
|
+
'string'
|
|
37
|
+
]
|
|
38
|
+
}
|
|
48
39
|
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
location,
|
|
59
|
-
meta,
|
|
60
|
-
methodName,
|
|
61
|
-
operator: '_uri',
|
|
62
|
-
params
|
|
63
|
-
});
|
|
40
|
+
function _uri({ params , location , methodName }) {
|
|
41
|
+
return runClass({
|
|
42
|
+
functions,
|
|
43
|
+
location,
|
|
44
|
+
meta,
|
|
45
|
+
methodName,
|
|
46
|
+
operator: '_uri',
|
|
47
|
+
params
|
|
48
|
+
});
|
|
64
49
|
}
|
|
65
|
-
|
|
66
|
-
var _default = _uri;
|
|
67
|
-
exports.default = _default;
|
|
50
|
+
export default _uri;
|
package/dist/common/user.js
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _getFromObject = _interopRequireDefault(require("../getFromObject"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
1
|
/*
|
|
13
2
|
Copyright 2020-2021 Lowdefy, Inc
|
|
14
3
|
|
|
@@ -23,28 +12,14 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
23
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
24
13
|
See the License for the specific language governing permissions and
|
|
25
14
|
limitations under the License.
|
|
26
|
-
*/
|
|
27
|
-
function _user(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
user
|
|
36
|
-
} = _ref;
|
|
37
|
-
return (0, _getFromObject.default)({
|
|
38
|
-
arrayIndices,
|
|
39
|
-
context,
|
|
40
|
-
contexts,
|
|
41
|
-
env,
|
|
42
|
-
location,
|
|
43
|
-
object: user,
|
|
44
|
-
operator: '_user',
|
|
45
|
-
params
|
|
46
|
-
});
|
|
15
|
+
*/ import getFromObject from '../getFromObject.js';
|
|
16
|
+
function _user({ arrayIndices , location , params , user }) {
|
|
17
|
+
return getFromObject({
|
|
18
|
+
arrayIndices,
|
|
19
|
+
location,
|
|
20
|
+
object: user,
|
|
21
|
+
operator: '_user',
|
|
22
|
+
params
|
|
23
|
+
});
|
|
47
24
|
}
|
|
48
|
-
|
|
49
|
-
var _default = _user;
|
|
50
|
-
exports.default = _default;
|
|
25
|
+
export default _user;
|
package/dist/common/uuid.js
CHANGED
|
@@ -1,18 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _uuid2 = require("uuid");
|
|
9
|
-
|
|
10
|
-
var _helpers = require("@lowdefy/helpers");
|
|
11
|
-
|
|
12
|
-
var _runClass = _interopRequireDefault(require("../runClass"));
|
|
13
|
-
|
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
16
1
|
/*
|
|
17
2
|
Copyright 2020-2021 Lowdefy, Inc
|
|
18
3
|
|
|
@@ -27,50 +12,54 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
27
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
28
13
|
See the License for the specific language governing permissions and
|
|
29
14
|
limitations under the License.
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
15
|
+
*/ import { v1, v3, v4, v5 } from 'uuid';
|
|
16
|
+
import { type } from '@lowdefy/helpers';
|
|
17
|
+
import runClass from '../runClass.js';
|
|
18
|
+
const meta = {
|
|
19
|
+
v1: {
|
|
20
|
+
noArgs: true
|
|
21
|
+
},
|
|
22
|
+
v3: {
|
|
23
|
+
namedArgs: [
|
|
24
|
+
'name',
|
|
25
|
+
'namespace'
|
|
26
|
+
],
|
|
27
|
+
validTypes: [
|
|
28
|
+
'array',
|
|
29
|
+
'object'
|
|
30
|
+
]
|
|
31
|
+
},
|
|
32
|
+
v4: {
|
|
33
|
+
noArgs: true
|
|
34
|
+
},
|
|
35
|
+
v5: {
|
|
36
|
+
namedArgs: [
|
|
37
|
+
'name',
|
|
38
|
+
'namespace'
|
|
39
|
+
],
|
|
40
|
+
validTypes: [
|
|
41
|
+
'array',
|
|
42
|
+
'object'
|
|
43
|
+
]
|
|
44
|
+
}
|
|
46
45
|
};
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
const functions = {
|
|
47
|
+
v1,
|
|
48
|
+
v3,
|
|
49
|
+
v4,
|
|
50
|
+
v5
|
|
52
51
|
};
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return (0, _runClass.default)({
|
|
66
|
-
functions: functions,
|
|
67
|
-
location,
|
|
68
|
-
meta,
|
|
69
|
-
methodName,
|
|
70
|
-
operator: '_uuid',
|
|
71
|
-
params
|
|
72
|
-
});
|
|
52
|
+
function _uuid({ params , location , methodName }) {
|
|
53
|
+
if (type.isNone(methodName) && (type.isNone(params) || params === true)) {
|
|
54
|
+
return v4();
|
|
55
|
+
}
|
|
56
|
+
return runClass({
|
|
57
|
+
functions: functions,
|
|
58
|
+
location,
|
|
59
|
+
meta,
|
|
60
|
+
methodName,
|
|
61
|
+
operator: '_uuid',
|
|
62
|
+
params
|
|
63
|
+
});
|
|
73
64
|
}
|
|
74
|
-
|
|
75
|
-
var _default = _uuid;
|
|
76
|
-
exports.default = _default;
|
|
65
|
+
export default _uuid;
|
package/dist/common/yaml.js
CHANGED
|
@@ -1,70 +1,63 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
19
|
-
|
|
20
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
21
|
-
|
|
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 YAML from 'js-yaml';
|
|
16
|
+
import { serializer } from '@lowdefy/helpers';
|
|
17
|
+
import runClass from '../runClass.js';
|
|
22
18
|
function parse(input) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return _helpers.serializer.deserialize(loaded);
|
|
19
|
+
if (input === 'undefined') return undefined;
|
|
20
|
+
const loaded = YAML.load(input);
|
|
21
|
+
return serializer.deserialize(loaded);
|
|
28
22
|
}
|
|
29
|
-
|
|
30
23
|
function stringify(input, options) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
24
|
+
return YAML.dump(serializer.serialize(input, {
|
|
25
|
+
isoStringDates: true
|
|
26
|
+
}), {
|
|
27
|
+
sortKeys: true,
|
|
28
|
+
...options
|
|
29
|
+
});
|
|
36
30
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
stringify
|
|
31
|
+
const functions = {
|
|
32
|
+
parse,
|
|
33
|
+
stringify
|
|
41
34
|
};
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
35
|
+
const meta = {
|
|
36
|
+
stringify: {
|
|
37
|
+
namedArgs: [
|
|
38
|
+
'on',
|
|
39
|
+
'options'
|
|
40
|
+
],
|
|
41
|
+
validTypes: [
|
|
42
|
+
'object',
|
|
43
|
+
'array'
|
|
44
|
+
]
|
|
45
|
+
},
|
|
46
|
+
parse: {
|
|
47
|
+
singleArg: true,
|
|
48
|
+
validTypes: [
|
|
49
|
+
'string'
|
|
50
|
+
]
|
|
51
|
+
}
|
|
51
52
|
};
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
location,
|
|
62
|
-
meta,
|
|
63
|
-
methodName,
|
|
64
|
-
operator: '_yaml',
|
|
65
|
-
params
|
|
66
|
-
});
|
|
53
|
+
function _yaml({ params , location , methodName }) {
|
|
54
|
+
return runClass({
|
|
55
|
+
functions,
|
|
56
|
+
location,
|
|
57
|
+
meta,
|
|
58
|
+
methodName,
|
|
59
|
+
operator: '_yaml',
|
|
60
|
+
params
|
|
61
|
+
});
|
|
67
62
|
}
|
|
68
|
-
|
|
69
|
-
var _default = _yaml;
|
|
70
|
-
exports.default = _default;
|
|
63
|
+
export default _yaml;
|
package/dist/getFromArray.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,41 +12,28 @@ 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 getFromArray(
|
|
26
|
-
|
|
27
|
-
params
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
operator,
|
|
31
|
-
location
|
|
32
|
-
} = _ref;
|
|
33
|
-
if (params === true) return array;
|
|
34
|
-
|
|
35
|
-
if (_helpers.type.isString(params)) {
|
|
36
|
-
return array.find(item => item[key] === params);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (_helpers.type.isNumber(params)) {
|
|
40
|
-
return array[params];
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (_helpers.type.isObject(params)) {
|
|
44
|
-
if (params.all === true) return array;
|
|
45
|
-
if (_helpers.type.isString(params.value)) return array.find(item => item[key] === params.value);
|
|
46
|
-
if (_helpers.type.isNumber(params.index)) return array[params.index];
|
|
47
|
-
|
|
48
|
-
if (!_helpers.type.isNone(params.value) && !_helpers.type.isString(params.value)) {
|
|
49
|
-
throw new Error("Operator Error: ".concat(operator, ".value must be of type string. Received: ").concat(JSON.stringify(params), " at ").concat(location, "."));
|
|
15
|
+
*/ import { type } from '@lowdefy/helpers';
|
|
16
|
+
function getFromArray({ params , array , key , operator , location }) {
|
|
17
|
+
if (params === true) return array;
|
|
18
|
+
if (type.isString(params)) {
|
|
19
|
+
return array.find((item)=>item[key] === params
|
|
20
|
+
);
|
|
50
21
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
throw new Error("Operator Error: ".concat(operator, ".index must be of type number. Received: ").concat(JSON.stringify(params), " at ").concat(location, "."));
|
|
22
|
+
if (type.isNumber(params)) {
|
|
23
|
+
return array[params];
|
|
54
24
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
25
|
+
if (type.isObject(params)) {
|
|
26
|
+
if (params.all === true) return array;
|
|
27
|
+
if (type.isString(params.value)) return array.find((item)=>item[key] === params.value
|
|
28
|
+
);
|
|
29
|
+
if (type.isNumber(params.index)) return array[params.index];
|
|
30
|
+
if (!type.isNone(params.value) && !type.isString(params.value)) {
|
|
31
|
+
throw new Error(`Operator Error: ${operator}.value must be of type string. Received: ${JSON.stringify(params)} at ${location}.`);
|
|
32
|
+
}
|
|
33
|
+
if (!type.isNone(params.index) && !type.isNumber(params.index)) {
|
|
34
|
+
throw new Error(`Operator Error: ${operator}.index must be of type number. Received: ${JSON.stringify(params)} at ${location}.`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
throw new Error(`Operator Error: ${operator} must be of type string, number or object. Received: ${JSON.stringify(params)} at ${location}.`);
|
|
58
38
|
}
|
|
59
|
-
|
|
60
|
-
var _default = getFromArray;
|
|
61
|
-
exports.default = _default;
|
|
39
|
+
export default getFromArray;
|