@appsemble/utils 0.32.1-test.16 → 0.32.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/README.md +3 -3
- package/api/components/schemas/FlowPageActionsDefinition.js +4 -0
- package/api/components/schemas/PageActionsDefinition.js +1 -1
- package/examples.js +11 -0
- package/iterApp.js +2 -2
- package/package.json +2 -2
- package/reference-schemas/remappers/unsorted.js +15 -0
- package/remap.js +30 -0
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
#  Appsemble Utilities
|
|
2
2
|
|
|
3
3
|
> Internal utility functions used across multiple Appsemble projects.
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@appsemble/utils)
|
|
6
|
-
[](https://gitlab.com/appsemble/appsemble/-/releases/0.32.1)
|
|
7
7
|
[](https://prettier.io)
|
|
8
8
|
|
|
9
9
|
## Table of Contents
|
|
@@ -26,5 +26,5 @@ not guaranteed.
|
|
|
26
26
|
|
|
27
27
|
## License
|
|
28
28
|
|
|
29
|
-
[LGPL-3.0-only](https://gitlab.com/appsemble/appsemble/-/blob/0.32.1
|
|
29
|
+
[LGPL-3.0-only](https://gitlab.com/appsemble/appsemble/-/blob/0.32.1/LICENSE.md) ©
|
|
30
30
|
[Appsemble](https://appsemble.com)
|
|
@@ -14,6 +14,10 @@ export const FlowPageActionsDefinition = {
|
|
|
14
14
|
A flow is finished when \`flow.finish\` gets called, or when \`flow.next\` gets called on the final
|
|
15
15
|
subpage. This action has a special property in which the cumulative input data from each previous subpage gets sent, instead of the individual block that triggered this action.`,
|
|
16
16
|
},
|
|
17
|
+
onLoad: {
|
|
18
|
+
$ref: '#/components/schemas/ActionDefinition',
|
|
19
|
+
description: 'This action is fired when a page loads, highly helpful in loading data for the page',
|
|
20
|
+
},
|
|
17
21
|
},
|
|
18
22
|
};
|
|
19
23
|
//# sourceMappingURL=FlowPageActionsDefinition.js.map
|
package/examples.js
CHANGED
|
@@ -894,6 +894,17 @@ export const examples = {
|
|
|
894
894
|
},
|
|
895
895
|
result: [true, true, true, false, false],
|
|
896
896
|
},
|
|
897
|
+
maths: {
|
|
898
|
+
input: { version: 0 },
|
|
899
|
+
remapper: {
|
|
900
|
+
maths: {
|
|
901
|
+
a: { prop: 'version' },
|
|
902
|
+
b: { static: 1 },
|
|
903
|
+
operation: 'add',
|
|
904
|
+
},
|
|
905
|
+
},
|
|
906
|
+
result: 1,
|
|
907
|
+
},
|
|
897
908
|
};
|
|
898
909
|
/**
|
|
899
910
|
* @param remapper The remapper example to use.
|
package/iterApp.js
CHANGED
|
@@ -19,8 +19,8 @@ export function iterAction(action, callbacks, prefix = []) {
|
|
|
19
19
|
return true;
|
|
20
20
|
}
|
|
21
21
|
if (action.type === 'condition') {
|
|
22
|
-
return Boolean(iterAction(action.then, callbacks, [...prefix, 'then']) ||
|
|
23
|
-
iterAction(action.else, callbacks, [...prefix, 'else']));
|
|
22
|
+
return Boolean(iterAction(action.then ?? { type: 'noop' }, callbacks, [...prefix, 'then']) ||
|
|
23
|
+
iterAction(action.else ?? { type: 'noop' }, callbacks, [...prefix, 'else']));
|
|
24
24
|
}
|
|
25
25
|
if (action.type === 'each') {
|
|
26
26
|
return iterAction(action.do, callbacks, [...prefix, 'do']);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appsemble/utils",
|
|
3
|
-
"version": "0.32.1
|
|
3
|
+
"version": "0.32.1",
|
|
4
4
|
"description": "Utility functions used in Appsemble internally",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"app",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"test": "vitest"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@appsemble/types": "0.32.1
|
|
42
|
+
"@appsemble/types": "0.32.1",
|
|
43
43
|
"@odata/parser": "^0.2.14",
|
|
44
44
|
"axios": "^1.0.0",
|
|
45
45
|
"cron-parser": "^4.0.0",
|
|
@@ -257,5 +257,20 @@ For example:
|
|
|
257
257
|
${schemaExample('xml.parse', { result: 'pretty' })}`,
|
|
258
258
|
$ref: '#/components/schemas/RemapperDefinition',
|
|
259
259
|
},
|
|
260
|
+
maths: {
|
|
261
|
+
description: `This can be used to perform a mathematical operation on two numbers
|
|
262
|
+
|
|
263
|
+
For example:
|
|
264
|
+
|
|
265
|
+
${schemaExample('maths', { result: 'pretty' })}`,
|
|
266
|
+
additionalProperties: false,
|
|
267
|
+
properties: {
|
|
268
|
+
a: { $ref: '#/components/schemas/RemapperDefinition' },
|
|
269
|
+
b: { $ref: '#/components/schemas/RemapperDefinition' },
|
|
270
|
+
operation: {
|
|
271
|
+
enum: ['add', 'divide', 'mod', 'multiply', 'subtract'],
|
|
272
|
+
},
|
|
273
|
+
},
|
|
274
|
+
},
|
|
260
275
|
};
|
|
261
276
|
//# sourceMappingURL=unsorted.js.map
|
package/remap.js
CHANGED
|
@@ -24,6 +24,9 @@ function isEqualArray(a, b) {
|
|
|
24
24
|
}
|
|
25
25
|
return a.every((val, i) => val === b[i]);
|
|
26
26
|
}
|
|
27
|
+
function isNumber(a) {
|
|
28
|
+
return a !== undefined && a != null && a !== '' && !Number.isNaN(Number(a));
|
|
29
|
+
}
|
|
27
30
|
export function remap(remapper, input, context) {
|
|
28
31
|
if (typeof remapper === 'string' ||
|
|
29
32
|
typeof remapper === 'number' ||
|
|
@@ -625,5 +628,32 @@ const mapperImplementations = {
|
|
|
625
628
|
const remapped = remap(value, input, context);
|
|
626
629
|
return remapped !== undefined && remapped != null;
|
|
627
630
|
},
|
|
631
|
+
maths(value, input, context) {
|
|
632
|
+
const { a, b, operation } = value;
|
|
633
|
+
const aRemapped = remap(a, input, context);
|
|
634
|
+
const bRemapped = remap(b, input, context);
|
|
635
|
+
if (!isNumber(aRemapped) || !isNumber(bRemapped)) {
|
|
636
|
+
return -1;
|
|
637
|
+
}
|
|
638
|
+
const na = Number(aRemapped);
|
|
639
|
+
const nb = Number(bRemapped);
|
|
640
|
+
switch (operation) {
|
|
641
|
+
case 'add':
|
|
642
|
+
return na + nb;
|
|
643
|
+
case 'subtract':
|
|
644
|
+
return na - nb;
|
|
645
|
+
case 'multiply':
|
|
646
|
+
return na * nb;
|
|
647
|
+
case 'divide':
|
|
648
|
+
if (nb === 0) {
|
|
649
|
+
return -1;
|
|
650
|
+
}
|
|
651
|
+
return na / nb;
|
|
652
|
+
case 'mod':
|
|
653
|
+
return na % nb;
|
|
654
|
+
default:
|
|
655
|
+
return -1;
|
|
656
|
+
}
|
|
657
|
+
},
|
|
628
658
|
};
|
|
629
659
|
//# sourceMappingURL=remap.js.map
|