From 87de2f57b23f08159b110110978ad3152e84c380 Mon Sep 17 00:00:00 2001 From: Gavin McDonald Date: Fri, 4 Jul 2025 14:30:42 -0400 Subject: [PATCH] fix typo --- tools/log.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 tools/log.ts diff --git a/tools/log.ts b/tools/log.ts new file mode 100644 index 0000000..54ba25d --- /dev/null +++ b/tools/log.ts @@ -0,0 +1,19 @@ +/** + * A logging utility designed to be inserted into functional chains. + * Logs all parameters with an optional prefix, then returns the first argument unchanged. + * + * @param {string} [prefix=''] - A label or message to prepend to the logged output. + * @returns {(value: any, ...rest: any[]) => any} - A function that logs its arguments and returns the first one. + * + * @example + * const result = [1, 2, 3] + * .map((n) => n * 2) + * .map(log('doubled:')) + * .filter((n) => n > 2); + */ +export const log = + (prefix: string = ''): ((value: any, ...rest: any[]) => any) => + (...args: any[]) => { + console.log(prefix, ...args); + return args[0]; + };