aboutsummaryrefslogtreecommitdiff
path: root/src/tools/tool.ts
blob: 3bf4e4cc68285f723faa95bd612dc29bbf14e9e0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
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,
  };
}