import { isObject } from '../../Types'; import { momentToDateString } from '../momentToDateString'; type AnyType = { [key: string]: any; }; /** * 格式化对象中所有moment类型的值转化为dataString 函数 * * @category Utils * @desc : 若传入的值不是object类型,则直接原样返回 * @param momentObj : 需要格式化的对象 * @returns : 格式化之后的对象值 */ export const momentTransferForObj = (momentObj: AnyType) => { if (!isObject(momentObj)) { return momentObj; } const newDateObj: AnyType = {}; Object.entries(momentObj).forEach(ele => { const [key, value] = ele; const newValue = momentToDateString(value); newDateObj[key] = newValue; }); return newDateObj; };