docs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10
Build a validation utility for custom MJML component attributes that enforces type constraints and validates attribute values.
Your validator should support the following validation rules:
Validate that attribute values contain specific units and proper formatting:
unit(px,%) which requires values to have px or % unitsunit(px,%){1,4} which accepts 1-4 space-separated values with the specified unitsValidate that attribute values match one of a predefined set of allowed values:
enum(value1,value2,value3) patterns that restrict values to specific optionsValidate color values in various formats:
The validator should return validation results with:
unit(px) pattern accepts "10px" but rejects "10" and "10em" @testunit(px,%){1,4} pattern accepts "10px 20px" and "5% 10% 15% 20%" but rejects "10px 20em" @testenum(left,center,right) pattern accepts "center" but rejects "middle" @test/**
* Validates an attribute value against a type pattern.
*
* @param {string} value - The attribute value to validate
* @param {string} typePattern - The type pattern (e.g., "unit(px,%)", "enum(a,b,c)", "color")
* @returns {Object} Validation result with { valid: boolean, error?: string, value?: string }
*/
function validateAttribute(value, typePattern) {
// IMPLEMENTATION HERE
}
/**
* Parses a unit pattern and extracts allowed units and value count.
*
* @param {string} pattern - The unit pattern (e.g., "unit(px,%){1,4}")
* @returns {Object} Parsed pattern with { units: string[], minCount: number, maxCount: number }
*/
function parseUnitPattern(pattern) {
// IMPLEMENTATION HERE
}
/**
* Parses an enum pattern and extracts allowed values.
*
* @param {string} pattern - The enum pattern (e.g., "enum(left,center,right)")
* @returns {string[]} Array of allowed values
*/
function parseEnumPattern(pattern) {
// IMPLEMENTATION HERE
}
module.exports = {
validateAttribute,
parseUnitPattern,
parseEnumPattern
};Provides email template markup language support.