/**
* Wraps string manipulation logic with a dry-run mode.
*
* @param {function} originalFunction The original string manipulation function.
* @param {boolean} dryRun Whether to run in dry-run mode. If true, logs the actions without executing them.
* @returns {function} A wrapped function that can be called with string input.
*/
function wrapStringLogic(originalFunction, dryRun = false) {
return function(inputString) {
if (dryRun) {
console.log("Dry Run Mode: Logging actions...");
}
let result;
try {
const originalResult = originalFunction(inputString);
result = originalResult;
if (dryRun) {
console.log("Dry Run Mode: Result would be:", result);
}
} catch (error) {
if (dryRun) {
console.error("Dry Run Mode: Error would occur:", error.message);
}
throw error; // Re-throw the error if not in dry-run
}
return result;
};
}
Add your comment