@buka/class-transformer-extra
Version:
class-transformer-extra contains methods that's aren't included in the class-transform package.
10 lines (9 loc) • 334 B
JavaScript
import { Transform } from 'class-transformer';
import dayjs from 'dayjs';
export function FormatDate(template, options) {
return Transform(function FormatDateTransform({ value }) {
if (options?.optional && value === undefined)
return undefined;
return dayjs(value).format(template);
}, options);
}