Skip to content

Types Provider

Similar to the Expression Plugin, this plugin adds support for easily exposing new DataTypes, formats, and validations to Player’s content.

Example

Define a new validation type:

import { ValidatorFunction } from "@player-ui/player";
const customValidator: ValidatorFunction = (context, value) => {
if (value === "bad-value") {
return {
message: "This is a bad value.",
};
}
};

Create a new DataType that references it:

import { Schema } from "@player-ui/player";
const CustomDataType: Schema.DataType = {
name: "CustomType",
validation: [
{
type: "custom-validator",
},
],
};

Register it with Player:

import { Player } from "@player-ui/player";
import { TypesProviderPlugin } from "@player-ui/types-provider-plugin";
const player = new Player({
plugins: [
new TypesProviderPlugin({
types: [CustomDataType],
validations: [["custom-validator", customValidator]],
}),
],
});

Given a data-type reference to CustomType in the content, your new validation will be used:

{
"schema": {
"ROOT": {
"data": {
"type": "CustomDataType"
}
}
}
}