diff --git a/README.md b/README.md index 48fc754..9d955a7 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,6 @@ As environment variables: - Search cards by title - Create a card - Delete a card -- Make all tests _self-contained_ (e.g. create a board, _then_ add widgets and cards, etc) ## Usage diff --git a/src/lib/utility.ts b/src/lib/utility.ts index be7a810..1b23744 100644 --- a/src/lib/utility.ts +++ b/src/lib/utility.ts @@ -1,3 +1,4 @@ +import { ArrayMatchFunction } from '$/types/Utility.js'; import { assertBravoClaim } from './errors.js'; export function stringsMatchIgnoringCase(string1: string, string2: string) { @@ -9,6 +10,35 @@ export function stringsMatchIgnoringCase(string1: string, string2: string) { ); } +export function stringsMatch( + string1: string, + string2: string, + options?: { ignoreCase?: boolean }, +) { + if (options?.ignoreCase) { + return stringsMatchIgnoringCase(string1, string2); + } + return string1 === string2; +} + +/** + * Async find function, allowing + * for async match functions. (Synchronous funcs + * will also work fine.) + */ +export async function find( + items: Item[], + matchFunction: ArrayMatchFunction, +) { + let idx = 0; + for await (const item of items) { + if (await matchFunction(item, idx, items)) { + return item; + } + idx++; + } +} + export function findByField< Item extends Record, Field extends keyof Item,