it-tools/src/tools/tool.ts

14 lines
365 B
TypeScript
Raw Normal View History

2023-04-05 23:30:44 +02:00
import { isAfter, subWeeks } from 'date-fns';
import type { Tool } from './tools.types';
type WithOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
export function defineTool(tool: WithOptional<Tool, 'isNew'>) {
const isNew = tool.createdAt ? isAfter(tool.createdAt, subWeeks(new Date(), 2)) : false;
return {
isNew,
...tool,
};
}