pacocoursey / cmdk

Fast, unstyled command menu React component.
https://cmdk.paco.me
MIT License
9.98k stars 287 forks source link

Export of commandScore? #295

Open goatyeahh opened 3 months ago

goatyeahh commented 3 months ago

Would you consider exporting commandScore? I like the default commandScore, but it would be great to reuse it.

CleanShot 2024-08-05 at 13 06 14@2x

Why?

My first use case is that I have added some unique value to my command items to avoid name clash issues that interfere with the search like suggested here https://github.com/pacocoursey/cmdk/issues/174

<Command.Item value="apple __a__">Apple</Command.Item>
<Command.Item value="apple __b__">Apple</Command.Item>

so something like this would do the trick

  filter={(value: string, search: string, keywords?: string[]) => {
    // value: `<name> __${unique}__)`
    const valueWithoutUnique = value.replace(/\s+__\s+__/, "");
    return commandScore(valueWithoutUnique, search, keywords);
  }}

or another use case would be to change filter only for some specific keyword and for others leave the default.

EdoAPP commented 1 month ago

It seems that the change it's already in the main branch https://github.com/pacocoursey/cmdk/blob/main/cmdk/src/index.tsx#L937 but the current release doesn't contain the changes. Perhaps @pacocoursey can comment on when there's an incoming release.