MCPcopy Create free account
hub / github.com/campsite/campsite / commandScoreSort

Function commandScoreSort

apps/web/utils/commandScoreSort.ts:3–18  ·  view source on GitHub ↗
(items: T[], query: string, search: (item: T) => string)

Source from the content-addressed store, hash-verified

1import { commandScore } from '@campsite/ui'
2
3export function commandScoreSort<T>(items: T[], query: string, search: (item: T) => string) {
4 return items
5 .map((item) => {
6 const score = commandScore(search(item), query)
7
8 return { score, item }
9 })
10 .filter(({ score }) => score > 0)
11 .sort((a, b) => {
12 if (a.score === b.score) {
13 return search(a.item).localeCompare(search(b.item))
14 }
15 return b.score - a.score
16 })
17 .map(({ item }) => item)
18}

Callers 3

useFilteredProjectsFunction · 0.90
useSyncedMembersFunction · 0.90

Calls 2

commandScoreFunction · 0.90
mapMethod · 0.80

Tested by

no test coverage detected