diff --git a/src/v2/commands/npm/index.ts b/src/v2/commands/npm/index.ts index 52a19ffd..aabcbef3 100644 --- a/src/v2/commands/npm/index.ts +++ b/src/v2/commands/npm/index.ts @@ -12,7 +12,6 @@ import { MessageEmbed, Collection, MessageActionRow, - MessageButton, MessageSelectMenu, } from 'discord.js'; import type { MessageComponentTypes } from 'discord.js/typings/enums'; @@ -42,26 +41,28 @@ const list = new (Intl as any).ListFormat(); const fetch: typeof getData = getData; const formatDateFromNow: typeof formatDistanceToNow = formatDistanceToNow; -const getFirstTenResults = pipe, NPMEmbed[]>([ - take(10), - map(({ name, date, description, links, publisher, maintainers }) => ({ - author: { - name: publisher.username, - // icon_url: publisher.avatars.small, - url: `https://www.npmjs.com/~${publisher.username}`, - }, - description, - externalUrls: { - homepage: links.homepage, - repository: links.repository, - }, - lastUpdate: `${formatDateFromNow(new Date(date))} ago`, - maintainers: maintainers.length, - name, - url: links.npm, - })), +const getFirstTenResults = pipe( + take(10), + map( + ({ name, date, description, links, publisher, maintainers }) => ({ + author: { + name: publisher.username, + // icon_url: publisher.avatars.small, + url: `https://www.npmjs.com/~${publisher.username}`, + }, + description, + externalUrls: { + homepage: links.homepage, + repository: links.repository, + }, + lastUpdate: `${formatDateFromNow(new Date(date))} ago`, + maintainers: maintainers.length, + name, + url: links.npm, + }) + ), collect, -]); +); // msg: Message, searchTerm: string const handleNpmCommand = async ( diff --git a/src/v2/commands/post/index.ts b/src/v2/commands/post/index.ts index 9ff0192a..00476b1f 100644 --- a/src/v2/commands/post/index.ts +++ b/src/v2/commands/post/index.ts @@ -160,13 +160,13 @@ const sendAlert = ( } }; -const generateFields = pipe>([ - filter( +const generateFields = pipe( + filter<[string, string]>( ([key, val]: [string, string]) => !['guidelines'].includes(key) && !(key === 'remote' && val.toLowerCase() === 'onsite') ), - map(([key, val]: [string, string]): OutputField => { + map(([key, val]): OutputField => { let value = val; switch (key) { case 'compensation': @@ -186,7 +186,7 @@ const generateFields = pipe>([ value: createMarkdownCodeBlock(value.replace(/```/gu, '')), }; }), -]); +); const createUserTag = (username: string, discriminator: string) => `${username}#${discriminator}`; diff --git a/src/v2/commands/resource/handlers/javascript.ts b/src/v2/commands/resource/handlers/javascript.ts index 6a95e12d..9b837868 100644 --- a/src/v2/commands/resource/handlers/javascript.ts +++ b/src/v2/commands/resource/handlers/javascript.ts @@ -21,11 +21,7 @@ ${BACKTICKS} `.trim() ); -const transform = pipe, string>([ - mapTransform, - collect, - (arr: string[]) => arr.join('\n'), -]); +const transform = pipe(mapTransform, collect, arr => arr.join('\n')); const resources = [ { diff --git a/src/v2/modules/mod/commands/roles.ts b/src/v2/modules/mod/commands/roles.ts index b52143fe..b1966aeb 100644 --- a/src/v2/modules/mod/commands/roles.ts +++ b/src/v2/modules/mod/commands/roles.ts @@ -15,10 +15,10 @@ const generateButtons = (roles: typeof ROLES | typeof NOTIFY_ROLES) => .setStyle('SECONDARY') .setEmoji(item.emoji) ); -const chunkAndRowify = pipe< - Iterable, - Iterable ->([chunk(5), map(x => new MessageActionRow().addComponents(...x))]); +const chunkAndRowify = pipe( + chunk(5), + map(x => new MessageActionRow().addComponents(...x)) +); export async function setupRoles( interaction: CommandInteraction diff --git a/src/v2/utils/pipe.ts b/src/v2/utils/pipe.ts index 363d1cc1..7f9d8942 100644 --- a/src/v2/utils/pipe.ts +++ b/src/v2/utils/pipe.ts @@ -1,11 +1,26 @@ -type PipeFunctions = [ - (input: Input) => unknown, - ...Function[], - (input: unknown) => Output -]; +type Fn = (input: A) => B; -export function pipe( - fns: PipeFunctions -): (input: Input) => Output { - return (item: Input) => fns.reduce((input, fn) => fn(input), item) as Output; +export function pipe(ab: Fn): Fn; +export function pipe(ab: Fn, bc: Fn): Fn; +export function pipe( + ab: Fn, + bc: Fn, + cd: Fn +): Fn; +export function pipe( + ab: Fn, + bc: Fn, + cd: Fn, + de: Fn +): Fn; +export function pipe( + ab: Fn, + bc: Fn, + cd: Fn, + de: Fn, + ef: Fn +): Fn; + +export function pipe(...fns: Fn[]): Fn { + return (input: unknown) => fns.reduce((acc, fn) => fn(acc), input); }