From a5e8743afd66871b8cb2df1919fcd97bb65f8f71 Mon Sep 17 00:00:00 2001 From: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Date: Wed, 3 May 2023 13:00:11 -0500 Subject: [PATCH] chore: remove utils folder in favor of single file --- .../{utilities/treeSearch.ts => functions.ts} | 22 ++++++++++++++- src/core/utilities/functions.ts | 28 ------------------- 2 files changed, 21 insertions(+), 29 deletions(-) rename src/core/{utilities/treeSearch.ts => functions.ts} (76%) delete mode 100644 src/core/utilities/functions.ts diff --git a/src/core/utilities/treeSearch.ts b/src/core/functions.ts similarity index 76% rename from src/core/utilities/treeSearch.ts rename to src/core/functions.ts index 16b7176..8ab6745 100644 --- a/src/core/utilities/treeSearch.ts +++ b/src/core/functions.ts @@ -1,12 +1,32 @@ +import { Err, Ok } from 'ts-results-es'; import { ApplicationCommandOptionType, AutocompleteInteraction } from 'discord.js'; import type { SernAutocompleteData, SernOptionsData } from '../../types/module'; + +//function wrappers for empty ok / err +export const ok = () => Ok.EMPTY; +export const err = () => Err.EMPTY; + +export function partition(arr: (T & V)[], condition: (e: T & V) => boolean): [T[], V[]] { + const t: T[] = []; + const v: V[] = []; + for (const el of arr) { + if (condition(el)) { + t.push(el as T); + } else { + v.push(el as V); + } + } + return [t, v]; +} + + /** * Uses an iterative DFS to check if an autocomplete node exists * @param iAutocomplete * @param options */ -export default function treeSearch( +export function treeSearch( iAutocomplete: AutocompleteInteraction, options: SernOptionsData[] | undefined, ): SernAutocompleteData | undefined { diff --git a/src/core/utilities/functions.ts b/src/core/utilities/functions.ts deleted file mode 100644 index 18df085..0000000 --- a/src/core/utilities/functions.ts +++ /dev/null @@ -1,28 +0,0 @@ -import * as Files from '../module-loading/readFile'; -import { basename } from 'path'; -import { Err, Ok } from 'ts-results-es'; -/** - * - * @param modName - * @param absPath - */ -export function nameOrFilename(modName: string | undefined, absPath: string) { - return modName ?? Files.fmtFileName(basename(absPath)); -} - -//function wrappers for empty ok / err -export const ok = () => Ok.EMPTY; -export const err = () => Err.EMPTY; - -export function partition(arr: (T & V)[], condition: (e: T & V) => boolean): [T[], V[]] { - const t: T[] = []; - const v: V[] = []; - for (const el of arr) { - if (condition(el)) { - t.push(el as T); - } else { - v.push(el as V); - } - } - return [t, v]; -}