2022-06-01 23:52:21 +02:00
|
|
|
import { config } from '@/config';
|
2023-04-05 23:30:44 +02:00
|
|
|
import { isAfter, subWeeks } from 'date-fns';
|
2022-12-17 01:30:02 +01:00
|
|
|
import type { Tool } from './tools.types';
|
2022-06-01 23:52:21 +02:00
|
|
|
|
|
|
|
type WithOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
|
|
|
|
|
|
export function defineTool(
|
2022-12-17 01:30:02 +01:00
|
|
|
tool: WithOptional<Tool, 'isNew'>,
|
2022-06-01 23:52:21 +02:00
|
|
|
{ newTools }: { newTools: string[] } = { newTools: config.tools.newTools },
|
|
|
|
) {
|
2023-04-05 23:30:44 +02:00
|
|
|
const isInNewToolConfig = newTools.includes(tool.name);
|
|
|
|
const isRecentTool = tool.createdAt ? isAfter(tool.createdAt, subWeeks(new Date(), 2)) : false;
|
|
|
|
|
|
|
|
const isNew = isInNewToolConfig || isRecentTool;
|
2022-06-01 23:52:21 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
isNew,
|
|
|
|
...tool,
|
|
|
|
};
|
|
|
|
}
|