Common Types
This plugin exposes some basic DataTypes, validations, and formats into Player content.
It also serves as a good reference to adding your own custom types into Player.
Install the plugin:
npm i @player-ui/common-types-pluginyarn add @player-ui/common-types-pluginpnpm add @player-ui/common-types-pluginAdd it to Player:
import { CommonTypesPlugin } from '@player-ui/common-types-plugin';
const commonTypesPlugin = new CommonTypesPlugin();const player = new Player({ plugins: [commonTypesPlugin] });
// Start your flowplayer.start(myFlow);This will allow any DataTypes, formats, validations and custom data types to be used in the content
Formats
Section titled “Formats”commaNumber
Section titled “commaNumber”- format: Formats a number (or string containing only numbers) into a comma delineated string.
- deformat: Converts a comma delineated string into a number
Options:
{ precision?: number}integer
Section titled “integer”- deformat: converts a string containing only integers to an integer
- format: Formats a string of numbers into a slash separated date
Options:
{ mask?: string}currency
Section titled “currency”- format: Formats a number of string into a currency value
- deformat: Converts a currency value into a number
Options:
{ precision?: number; currencySymbol?: string; useParensForNeg?: boolean;}- format: Formats the value as a phone number
Options:
{ mask?: string;}Validations
Section titled “Validations”required
Section titled “required”Asserts that a value is not
null,undefined, or an empty string
Options:
{ /** An expression to limit the assertion only if the expression evaluates to truthy **/ if?: Expression;
/** An expression to limit the assertion only if the expression evaluates to falsy **/ ifNot?: Expression;}Constants Support:
- namespace:
constants - path:
validation.required - message: “A value is required”
expression
Section titled “expression”Uses an expression to evaluate the validation assertion
Options:
{ /** The expression to evaluate. If truthy, the value/validation passes. If falsy, it does not. **/ exp: Expression;}Constants Support:
- namespace:
constants - path:
validation.expression - message: “Expression evaluation failed”
readonly
Section titled “readonly”Asserts that the value cannot change
Constants Support:
- namespace:
constants - path:
validation.readonly - message: “Value cannot be modified”
string
Section titled “string”Asserts that the value is a string
Constants Support:
- namespace:
constants - path:
validation.string - message: “Value must be a string”
- parameters:
type: the type of value being validated
integer
Section titled “integer”Asserts that the value is an integer
Constants Support:
- namespace:
constants - path:
validation.integer - message: “Value must be an integer”
- parameters:
type: the type of value being validatedflooredValue: the floored value of the value being validated
collection
Section titled “collection”Asserts that the value is an array
Constants Support:
- namespace:
constants - path:
validation.collection - message: “Cannot set collection to non-array”
Asserts that the value is one of the pre-defined accepted values
Options:
{ options?: Array;}Constants Support:
- namespace:
constants - path:
validation.oneof - message: “Cannot set collection to non-array”
Asserts that the value matches the provided regular expression
Options:
{ regex: RegExp;}Constants Support:
- namespace:
constants - path:
validation.regex
length
Section titled “length”Asserts that the value matches the given length criteria. Uses character counts for strings, and key-length for objects, and array length for arrays.
Options:
{ min?: number; max?: number; exact?: number;}Constants Support:
- namespace:
constants - path:
validation.minimum,validation.maximum - message: “At least ${min} items needed”, “Up to ${max} items allowed”
- parameters:
validationLength: Returns the length of the value being validated
Assets that the numeric value is at least as large as the target
Options:
{ value: number;}Constants Support:
- namespace:
constants - path:
validation.min - message: “Must be at least ${value}“
Assets that the numeric value is at no larger the target
Options:
{ value: number;}Constants Support:
- namespace:
constants - path:
validation.max - message: “Cannot exceed ${value}“
Asserts that the value follows an email pattern
Constants Support:
- namespace:
constants - path:
validation.email - message: “Improper email format”
Asserts that the value follows an phone number pattern
Constants Support:
- namespace:
constants - path:
validation.phone - message: “Invalid phone number”
Asserts that the value follows an zip-code pattern
Constants Support:
- namespace:
constants - path:
validation.zip - message: “Invalid zip code”
Data Types
Section titled “Data Types”BooleanType
Section titled “BooleanType”A true or false value.
- validations:
oneOf([true, false])
IntegerType
Section titled “IntegerType”An integer value
- validations:
integer - format:
integer
IntegerPosType
Section titled “IntegerPosType”An integer value greater than 0
- validations:
integer,min(1) - format:
integer
StringType
Section titled “StringType”A string value
- validations:
string
CollectionType
Section titled “CollectionType”An array of items
- validations:
collection
DateType
Section titled “DateType”A value representing a date
- format:
date
PhoneType
Section titled “PhoneType”A value representing a phone number
- validations:
phone - format:
phone((###) ###-####)