@player-ui/common-expressions-plugin 0.7.4-next.4 → 0.7.5--canary.434.14868

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 (43) hide show
  1. package/dist/CommonExpressionsPlugin.native.js +11332 -0
  2. package/dist/CommonExpressionsPlugin.native.js.map +1 -0
  3. package/dist/cjs/index.cjs +199 -0
  4. package/dist/cjs/index.cjs.map +1 -0
  5. package/dist/index.legacy-esm.js +180 -0
  6. package/dist/index.mjs +180 -0
  7. package/dist/index.mjs.map +1 -0
  8. package/package.json +24 -58
  9. package/src/expressions/__tests__/expressions.test.ts +373 -0
  10. package/src/expressions/__tests__/toNum.test.ts +56 -0
  11. package/src/expressions/index.ts +33 -30
  12. package/src/expressions/toNum.ts +4 -4
  13. package/src/index.test.ts +31 -0
  14. package/src/index.ts +7 -7
  15. package/types/expressions/index.d.ts +39 -0
  16. package/types/expressions/toNum.d.ts +5 -0
  17. package/types/index.d.ts +32 -0
  18. package/dist/common-expressions-plugin.dev.js +0 -10782
  19. package/dist/common-expressions-plugin.prod.js +0 -2
  20. package/dist/index.cjs.js +0 -167
  21. package/dist/index.d.ts +0 -72
  22. package/dist/index.esm.js +0 -163
  23. package/dist/xlr/ceil.json +0 -33
  24. package/dist/xlr/concat.json +0 -19
  25. package/dist/xlr/containsAny.json +0 -44
  26. package/dist/xlr/findProperty.json +0 -92
  27. package/dist/xlr/findPropertyIndex.json +0 -70
  28. package/dist/xlr/floor.json +0 -33
  29. package/dist/xlr/isEmpty.json +0 -26
  30. package/dist/xlr/isNotEmpty.json +0 -26
  31. package/dist/xlr/length.json +0 -24
  32. package/dist/xlr/lowerCase.json +0 -24
  33. package/dist/xlr/manifest.js +0 -31
  34. package/dist/xlr/manifest.json +0 -36
  35. package/dist/xlr/number.json +0 -31
  36. package/dist/xlr/replace.json +0 -37
  37. package/dist/xlr/round.json +0 -33
  38. package/dist/xlr/sentenceCase.json +0 -24
  39. package/dist/xlr/size.json +0 -24
  40. package/dist/xlr/sum.json +0 -27
  41. package/dist/xlr/titleCase.json +0 -24
  42. package/dist/xlr/trim.json +0 -24
  43. package/dist/xlr/upperCase.json +0 -24
@@ -2,17 +2,17 @@
2
2
  * Convert a string that might contain formatting (such as commas and a currency symbol) to a number
3
3
  */
4
4
  export function toNum(val: unknown, coerceTo0?: boolean): number | undefined {
5
- if (typeof val === 'number') {
5
+ if (typeof val === "number") {
6
6
  return val;
7
7
  }
8
8
 
9
- if (typeof val === 'string' && val.length > 0) {
9
+ if (typeof val === "string" && val.length > 0) {
10
10
  // Trim whitespace
11
11
  let newVal = val.trim();
12
12
  // Remove all commas
13
- newVal = newVal.replace(/,/g, '');
13
+ newVal = newVal.replace(/,/g, "");
14
14
  // Remove up to 1 commonly-used currency symbol
15
- newVal = newVal.replace(/[¥£$€]/, '');
15
+ newVal = newVal.replace(/[¥£$€]/, "");
16
16
  const nVal = Number(newVal);
17
17
 
18
18
  // ignore hex, binary, octal, and values that don't parse
@@ -0,0 +1,31 @@
1
+ import { expect, test } from "vitest";
2
+ import type { InProgressState } from "@player-ui/player";
3
+ import { Player } from "@player-ui/player";
4
+ import { makeFlow } from "@player-ui/make-flow";
5
+ import { CommonExpressionsPlugin } from ".";
6
+
7
+ test("works in real life", () => {
8
+ const flow = makeFlow({
9
+ id: "view-1",
10
+ type: "info",
11
+ fields: {
12
+ asset: {
13
+ id: "input-1",
14
+ type: "text",
15
+ value: "@[titleCase('hello world')]@",
16
+ },
17
+ },
18
+ });
19
+
20
+ const player = new Player({
21
+ plugins: [new CommonExpressionsPlugin()],
22
+ });
23
+
24
+ player.start(flow);
25
+
26
+ const state = player.getState() as InProgressState;
27
+
28
+ expect(
29
+ state.controllers.view.currentView?.lastUpdate?.fields.asset.value,
30
+ ).toBe("Hello World");
31
+ });
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
1
- import type { ExtendedPlayerPlugin, Player } from '@player-ui/player';
2
- import { ExpressionPlugin } from '@player-ui/expression-plugin';
3
- import * as Expressions from './expressions';
1
+ import type { ExtendedPlayerPlugin, Player } from "@player-ui/player";
2
+ import { ExpressionPlugin } from "@player-ui/expression-plugin";
3
+ import * as Expressions from "./expressions";
4
4
  import type {
5
5
  size,
6
6
  length,
@@ -21,7 +21,7 @@ import type {
21
21
  findPropertyIndex,
22
22
  findProperty,
23
23
  containsAny,
24
- } from './expressions';
24
+ } from "./expressions";
25
25
  /**
26
26
  * Exposes a lot of expressions to Player.
27
27
  */
@@ -49,15 +49,15 @@ export class CommonExpressionsPlugin
49
49
  typeof sum,
50
50
  typeof findPropertyIndex,
51
51
  typeof findProperty,
52
- typeof containsAny
52
+ typeof containsAny,
53
53
  ]
54
54
  >
55
55
  {
56
- name = 'CommonExpressions';
56
+ name = "CommonExpressions";
57
57
 
58
58
  apply(player: Player) {
59
59
  player.registerPlugin(
60
- new ExpressionPlugin(new Map(Object.entries(Expressions)))
60
+ new ExpressionPlugin(new Map(Object.entries(Expressions))),
61
61
  );
62
62
  }
63
63
  }
@@ -0,0 +1,39 @@
1
+ import type { ExpressionHandler, Binding } from "@player-ui/player";
2
+ /** Generic Types */
3
+ export declare const size: ExpressionHandler<[val: unknown], number>;
4
+ export declare const length: ExpressionHandler<[val: unknown], number>;
5
+ /** Checks to see if the given value is empty */
6
+ export declare const isEmpty: ExpressionHandler<[unknown], boolean>;
7
+ /** Checks to see if the given value is not empty */
8
+ export declare const isNotEmpty: ExpressionHandler<[unknown], boolean>;
9
+ export declare const concat: ExpressionHandler<unknown[], unknown>;
10
+ /** String Types */
11
+ export declare const trim: ExpressionHandler<[arg: unknown], unknown>;
12
+ export declare const upperCase: ExpressionHandler<[arg: unknown], unknown>;
13
+ export declare const lowerCase: ExpressionHandler<[arg: unknown], unknown>;
14
+ export declare const replace: ExpressionHandler<[str: unknown, pattern: unknown, replacement?: unknown], unknown>;
15
+ export declare const titleCase: ExpressionHandler<[arg: unknown], unknown>;
16
+ export declare const sentenceCase: ExpressionHandler<[arg: unknown], unknown>;
17
+ /** Math Types */
18
+ export declare const number: ExpressionHandler<[val: unknown, coerceTo0?: boolean | undefined], number | undefined>;
19
+ export declare const round: ExpressionHandler<[string | number], number>;
20
+ export declare const floor: ExpressionHandler<[string | number], number>;
21
+ export declare const ceil: ExpressionHandler<[string | number], number>;
22
+ export declare const sum: ExpressionHandler<(string | number)[], number>;
23
+ /** Array Operations */
24
+ /** Finds the property in an array of objects */
25
+ export declare const findPropertyIndex: ExpressionHandler<[
26
+ Array<any> | Binding | undefined,
27
+ string | undefined,
28
+ any
29
+ ], number>;
30
+ /** Searches an array for an object matching the criteria. Returns the target prop from that object */
31
+ export declare const findProperty: ExpressionHandler<[
32
+ Array<any> | Binding,
33
+ string | undefined,
34
+ any,
35
+ string | undefined,
36
+ any
37
+ ], any>;
38
+ export declare const containsAny: ExpressionHandler<[string, string | string[]], boolean>;
39
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Convert a string that might contain formatting (such as commas and a currency symbol) to a number
3
+ */
4
+ export declare function toNum(val: unknown, coerceTo0?: boolean): number | undefined;
5
+ //# sourceMappingURL=toNum.d.ts.map
@@ -0,0 +1,32 @@
1
+ import type { ExtendedPlayerPlugin, Player } from "@player-ui/player";
2
+ import type { size, length, isEmpty, isNotEmpty, concat, trim, upperCase, lowerCase, replace, titleCase, sentenceCase, number, round, floor, ceil, sum, findPropertyIndex, findProperty, containsAny } from "./expressions";
3
+ /**
4
+ * Exposes a lot of expressions to Player.
5
+ */
6
+ export declare class CommonExpressionsPlugin implements ExtendedPlayerPlugin<[
7
+ ], [
8
+ ], [
9
+ typeof size,
10
+ typeof length,
11
+ typeof isEmpty,
12
+ typeof isNotEmpty,
13
+ typeof concat,
14
+ typeof trim,
15
+ typeof upperCase,
16
+ typeof lowerCase,
17
+ typeof replace,
18
+ typeof titleCase,
19
+ typeof sentenceCase,
20
+ typeof number,
21
+ typeof round,
22
+ typeof floor,
23
+ typeof ceil,
24
+ typeof sum,
25
+ typeof findPropertyIndex,
26
+ typeof findProperty,
27
+ typeof containsAny
28
+ ]> {
29
+ name: string;
30
+ apply(player: Player): void;
31
+ }
32
+ //# sourceMappingURL=index.d.ts.map