Skip to content

Support prefix-only matching against haystack terms? #81

@jacobcarpenter

Description

@jacobcarpenter

Somewhat related to the discussion in #80 (and #58), I'm finding myself wanting haystack string prefix-only matching (with typo tolerance).

It seems like it might not be crazy to introduce a new interLft = 3 option above the current strict level for {whole string}-anchored matching.

That is, given a list like

const specialties = [
  // ...
  'Close Quarters Combat',
  // ...
  'Quartermaster',
];

I want quart to only match "Quartermaster".

I'm currently achieving this with something like:

const filterResult = uf.filter(haystack, needle);
if (!filterResult?.length) {
	return [];
}

// require matches to anchor to the beginning of the haystack term
// "quart" -> ❌ "Close Quarters Combat" ✅ "Quartermaster"
const info = uf.info(filterResult, haystack, needle);
return info.idx.filter((_, index) => info.start[index] === 0);

... but it sounds like info is doing a bit more than needed to just ensure the match is anchored to the haystack string start.

Interested in whether that seems like a reasonable request?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions