import { cloneWith } from 'funtool';
// 在克隆过程中递增数字
const obj = { a: 1, b: 2 };
const result = cloneWith(obj, (val) => typeof val === 'number' ? val + 1 : undefined);
// result => { a: 2, b: 3 }
// 将日期转换为ISO字符串
const withDate = { created: new Date() };
const dateClone = cloneWith(withDate, (val) => val instanceof Date ? val.toISOString() : undefined);
// dateClone => { created: "2023-07-20T12:34:56.789Z" }
// 过滤掉undefined值
const data = { a: 1, b: undefined, c: 3 };
const filtered = cloneWith(data, (val) => val !== undefined ? val : undefined);
// filtered => { a: 1, c: 3 }