import { toSearchQuery } from "./toSearchQuery.js";
/**
 * @remarks \@since 6.0.0
 * @internal
 */ export const defaultExtractor = (name)=>(item)=>{
        if (typeof item === "string") {
            return item;
        }
        throw new Error(`A \`TextExtractor\` must be provided to \`${name}\` for lists that do not contain strings`);
    };
/**
 * @internal
 * @remarks \@since 6.0.0
 */ export function search(options) {
    const { list, type, query, filter, extractor, whitespace = "keep" } = options;
    const fallback = type === "search" ? undefined : list;
    if (!list.length) {
        return fallback;
    }
    const q = toSearchQuery(query, whitespace);
    if (!q) {
        return fallback;
    }
    const fn = type === "search" ? "find" : "filter";
    return list[fn]((item)=>filter(q, toSearchQuery(extractor(item), whitespace)));
}

//# sourceMappingURL=utils.js.map