Common Expressions
This plugin exposes some basic expressions into Player content.
It also serves as a good reference to adding your own custom expressions into Player.
Install the plugin:
npm i @player-ui/common-expressions-plugin
yarn add @player-ui/common-expressions-plugin
pnpm add @player-ui/common-expressions-plugin
Add it to Player:
import { CommonExpressionsPlugin } from '@player-ui/common-expressions-plugin';
const commonExpressionsPlugin = new CommonExpressionsPlugin();const player = new Player({ plugins: [commonExpressionsPlugin] });
// Start your flowplayer.start(myFlow);
This will allow any included expressions or custom expressions to be used in the content
CocoaPods
Section titled “CocoaPods”Add the subspec to your Podfile
pod 'PlayerUI/CommonExpressionsPlugin'
Swift Usage
Section titled “Swift Usage”This plugin takes no parameters, and the configuration comes from content, it can just be added to the plugin array:
var body: some View { SwiftUIPlayer( flow: flow, plugins: [ CommonExpressionsPlugin() ], result: $resultBinding )}
General
Section titled “General”Gets the size of a value. This is the number of keys in an object, the length of a string, or the number of items in an array.
function size(value: string | array | object): number;
length
Section titled “length”Alias for
size
concat
Section titled “concat”Concatenates arrays together, or strings into 1 value
function concat(...values: Array): Array;
Strings
Section titled “Strings”Trims whitespace from the leading and trailing edges of a string
function trim(value: string): string;
upperCase
Section titled “upperCase”Transforms the string to all uppercase.
function upperCase(value: string): string;
lowerCase
Section titled “lowerCase”Transforms the string to all lowercase.
function lowerCase(value: string): string;
titleCase
Section titled “titleCase”Transforms the string to title case. Each word is capitalized.
function titleCase(value: string): string;
sentenceCase
Section titled “sentenceCase”Transforms the string to sentence case. The first word is capitalized.
function sentenceCase(value: string): string;
replace
Section titled “replace”Replaces all instances of pattern in string with replacement. The pattern can also be a regex.
function replace( value: string, pattern: string | RegExp, replacement: string,): string;
Splits a string into an array of substrings based on a separator. Optionally limits the number of splits.
function split( value: string, separator: string, limit?: number,): Array<string>;
substr
Section titled “substr”Extracts a substring from a string. Supports negative indices to count from the end of the string.
function substr( value: string, start: number, length?: number,): string;
containsAny
Section titled “containsAny”Checks if a given string contains any keywords present in the given array.
function containsAny(value: string, keywords: Array<string>): boolean;
number
Section titled “number”Converts the given value to a number if possible. Will handle removing currency modifiers and comma delimitated values.
function number(value: string): number | undefined;
Rounds the given number to the nearest integer.
function round(value: number): number;
Rounds the number down the the nearest integer
function floor(value: number): number;
Rounds the number up the the nearest integer
function ceil(value: number): number;
Sums up all arguments
function sum(...values: Array<number>): number;
Objects/Arrays
Section titled “Objects/Arrays”findPropertyIndex
Section titled “findPropertyIndex”Finds the index of the item in the given array (or array reference). Returns -1 for indexes that aren’t found
function findPropertyIndex( binding: Binding | Array, searchProperty: string, searchValue: any,): number;
findProperty
Section titled “findProperty”Finds the item in the given array that matches the search criteria. Optionally return a specific property or a fallback value if not found
function findPropertyIndex( binding: Binding | Array, searchProperty: string, searchValue: any, fallBackProperty?: string, fallBackValue?: T,): T;