diff --git a/shared/utility/decorator.mjs b/shared/utility/decorator.mjs new file mode 100644 index 0000000..6cffe45 --- /dev/null +++ b/shared/utility/decorator.mjs @@ -0,0 +1,10 @@ +/** + * Applies an array of decorators to a given function in a right-to-left order. + * + * @param {Function[]} decorators - An array of decorator functions to apply. + * @param {Function} func - The original function to decorate. + * @returns {Function} - The decorated function after applying all the decorators. + */ +export function applyDecorators(decorators, func) { + return decorators.reduceRight((acc, dec) => dec(acc), func); +}