1. applyCalc.applyCalc(oldVal, newVal, context = {})
Applies transformations to a value (oldVal) based on the input (newVal). Supports:
- Numbers: arithmetic, percentage changes, math expressions, increments/decrements.
- Dates: adding/subtracting days, months, years, hours, minutes, or seconds.
- Strings: modifiers like trim, upper/lowercase, capitalize, title case, reverse, append, prepend, slice, padding, repeat, and regex replacement.
- Objects & Arrays: recursive updates, deletion, merging, pushing/popping/shifting/unshifting array items, deduplication, and conditional fallback.
Example:
1const oldVal = 10;2const newVal = "++5"; // increment by 53const result = applyCalc.applyCalc(oldVal, newVal);4console.log(result); // 15
1const date = new Date("2025-01-01");2const newDate = applyCalc.applyCalc(date, "++10d");3console.log(newDate); // 2025-01-11
1const str = "hello";2const modified = applyCalc.applyCalc(str, " | upper | reverse");3console.log(modified); // "OLLEH"
1const obj = { a: 1, b: 2 };2const updated = applyCalc.applyCalc(obj, { b: "__DELETE__", c: 3 });3console.log(updated); // { a: 1, c: 3 }