Skip to Main Content
Player Logo
PlayerPlugins

Common Expressions Plugin

This plugin exposes some basic expressions into Player content.
It also serves as a good reference to adding your own custom expressions into Player.

Usage

Install the plugin:
yarn add @player-ui/common-types-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 flow
player.start(myFlow);
This will allow any included expressions or custom expressions to be used in the content

General

size

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

Alias for size

concat

Concatenates arrays together, or strings into 1 value
function concat(...values: Array): Array

Strings

trim

Trims whitespace from the leading and trailing edges of a string
function trim(value: string): string

upperCase

Transforms the string to all uppercase.
function upperCase(value: string): string

lowerCase

Transforms the string to all lowercase.
function lowerCase(value: string): string

titleCase

Transforms the string to title case. Each word is capitalized.
function titleCase(value: string): string

sentenceCase

Transforms the string to sentence case. The first word is capitalized.
function sentenceCase(value: string): string

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

containsAny

Checks if a given string contains any keywords present in the given array.
function containsAny(value: string, keywords: Array<string>): boolean

Math

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

round

Rounds the given number to the nearest integer.
function round(value: number): number

floor

Rounds the number down the the nearest integer
function floor(value: number): number

ceil

Rounds the number up the the nearest integer
function ceil(value: number): number

sum

Sums up all arguments
function sum(...values: Array<number>): number

Objects/Arrays

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

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