diff --git a/renderers/web_core/src/v0_9/basic_catalog/functions/basic_functions.ts b/renderers/web_core/src/v0_9/basic_catalog/functions/basic_functions.ts index 4f04c819f..402195c5d 100644 --- a/renderers/web_core/src/v0_9/basic_catalog/functions/basic_functions.ts +++ b/renderers/web_core/src/v0_9/basic_catalog/functions/basic_functions.ts @@ -52,18 +52,34 @@ import { import {A2uiExpressionError} from '../../errors.js'; // Arithmetic +/** + * Implementation of the addition function. + * Adds two numbers 'a' and 'b'. + */ export const AddImplementation = createFunctionImplementation( AddApi, args => args.a + args.b, ); +/** + * Implementation of the subtraction function. + * Subtracts 'b' from 'a'. + */ export const SubtractImplementation = createFunctionImplementation( SubtractApi, args => args.a - args.b, ); +/** + * Implementation of the multiplication function. + * Multiplies 'a' and 'b'. + */ export const MultiplyImplementation = createFunctionImplementation( MultiplyApi, args => args.a * args.b, ); +/** + * Implementation of the division function. + * Divides 'a' by 'b'. Returns NaN if inputs are invalid, and Infinity if dividing by zero. + */ export const DivideImplementation = createFunctionImplementation( DivideApi, args => { @@ -85,50 +101,94 @@ export const DivideImplementation = createFunctionImplementation( ); // Comparison +/** + * Implementation of the equality comparison. + * Checks if 'a' is strictly equal to 'b'. + */ export const EqualsImplementation = createFunctionImplementation( EqualsApi, args => args.a === args.b, ); +/** + * Implementation of the inequality comparison. + * Checks if 'a' is not strictly equal to 'b'. + */ export const NotEqualsImplementation = createFunctionImplementation( NotEqualsApi, args => args.a !== args.b, ); +/** + * Implementation of the greater-than comparison. + * Checks if 'a' is greater than 'b'. + */ export const GreaterThanImplementation = createFunctionImplementation( GreaterThanApi, args => args.a > args.b, ); +/** + * Implementation of the less-than comparison. + * Checks if 'a' is less than 'b'. + */ export const LessThanImplementation = createFunctionImplementation( LessThanApi, args => args.a < args.b, ); // Logical +/** + * Implementation of the logical AND function. + * Returns true if all values in the array are truthy. + */ export const AndImplementation = createFunctionImplementation(AndApi, args => { return args.values.every((v: unknown) => !!v); }); +/** + * Implementation of the logical OR function. + * Returns true if at least one value in the array is truthy. + */ export const OrImplementation = createFunctionImplementation(OrApi, args => { return args.values.some((v: unknown) => !!v); }); +/** + * Implementation of the logical NOT function. + * Returns the negation of the value. + */ export const NotImplementation = createFunctionImplementation( NotApi, args => !args.value, ); // String +/** + * Implementation of the string contains function. + * Checks if 'string' contains 'substring'. + */ export const ContainsImplementation = createFunctionImplementation( ContainsApi, args => args.string.includes(args.substring), ); +/** + * Implementation of the string starts-with function. + * Checks if 'string' starts with 'prefix'. + */ export const StartsWithImplementation = createFunctionImplementation( StartsWithApi, args => args.string.startsWith(args.prefix), ); +/** + * Implementation of the string ends-with function. + * Checks if 'string' ends with 'suffix'. + */ export const EndsWithImplementation = createFunctionImplementation( EndsWithApi, args => args.string.endsWith(args.suffix), ); // Validation +/** + * Implementation of the required validation function. + * Checks if the value is not null, undefined, empty string, or empty array. + */ export const RequiredImplementation = createFunctionImplementation( RequiredApi, args => { @@ -139,6 +199,11 @@ export const RequiredImplementation = createFunctionImplementation( return true; }, ); +/** + * Implementation of the regex validation function. + * Checks if the value matches the regular expression pattern. + * Throws A2uiExpressionError if the pattern is invalid. + */ export const RegexImplementation = createFunctionImplementation( RegexApi, args => { @@ -153,6 +218,10 @@ export const RegexImplementation = createFunctionImplementation( } }, ); +/** + * Implementation of the length validation function. + * Checks if the length of the string or array is within [min, max] range. + */ export const LengthImplementation = createFunctionImplementation( LengthApi, args => { @@ -168,6 +237,10 @@ export const LengthImplementation = createFunctionImplementation( return true; }, ); +/** + * Implementation of the numeric validation function. + * Checks if the value is a number and within [min, max] range. + */ export const NumericImplementation = createFunctionImplementation( NumericApi, args => { @@ -179,6 +252,11 @@ export const NumericImplementation = createFunctionImplementation( return true; }, ); +/** + * Implementation of the email validation function. + * Uses a simple regex to check if the value looks like an email address. + * Note: This is a basic check and not fully compliant with all email standards. + */ export const EmailImplementation = createFunctionImplementation( EmailApi, args => { @@ -190,6 +268,11 @@ export const EmailImplementation = createFunctionImplementation( ); // Formatting +/** + * Implementation of the string formatting function. + * Parses a template string and resolves any embedded expressions using the provided context. + * Returns a computed signal that updates when referenced signals change. + */ export const FormatStringImplementation = createFunctionImplementation( FormatStringApi, (args, context) => { @@ -219,6 +302,10 @@ export const FormatStringImplementation = createFunctionImplementation( }); }, ); +/** + * Implementation of the number formatting function. + * Formats a number using Intl.NumberFormat with specified decimals and grouping. + */ export const FormatNumberImplementation = createFunctionImplementation( FormatNumberApi, args => { @@ -230,6 +317,11 @@ export const FormatNumberImplementation = createFunctionImplementation( }).format(args.value); }, ); +/** + * Implementation of the currency formatting function. + * Formats a number as currency using Intl.NumberFormat. + * Falls back to toFixed if formatting fails. + */ export const FormatCurrencyImplementation = createFunctionImplementation( FormatCurrencyApi, args => { @@ -247,6 +339,10 @@ export const FormatCurrencyImplementation = createFunctionImplementation( } }, ); +/** + * Implementation of the date formatting function. + * Formats a date using date-fns or returns ISO string. + */ export const FormatDateImplementation = createFunctionImplementation( FormatDateApi, args => { @@ -263,15 +359,23 @@ export const FormatDateImplementation = createFunctionImplementation( } }, ); +/** + * Implementation of the pluralization function. + * Selects the appropriate plural form based on the value using Intl.PluralRules. + */ export const PluralizeImplementation = createFunctionImplementation( PluralizeApi, args => { const rule = new Intl.PluralRules('en-US').select(args.value); - return String((args as any)[rule] || args.other || ''); + return String((args as Record)[rule] ?? args.other ?? ''); }, ); // Actions +/** + * Implementation of the open URL action. + * Opens the specified URL in a new window/tab. + */ export const OpenUrlImplementation = createFunctionImplementation( OpenUrlApi, args => {