(input: {
keep?: string
max: number
used: Map<string, number>
view: string[]
tabs: string[]
})
| 16 | } |
| 17 | |
| 18 | export function pruneSessionKeys(input: { |
| 19 | keep?: string |
| 20 | max: number |
| 21 | used: Map<string, number> |
| 22 | view: string[] |
| 23 | tabs: string[] |
| 24 | }) { |
| 25 | if (!input.keep) return [] |
| 26 | |
| 27 | const keys = new Set<string>([...input.view, ...input.tabs]) |
| 28 | if (keys.size <= input.max) return [] |
| 29 | |
| 30 | const score = (key: string) => { |
| 31 | if (key === input.keep) return Number.MAX_SAFE_INTEGER |
| 32 | return input.used.get(key) ?? 0 |
| 33 | } |
| 34 | |
| 35 | return Array.from(keys) |
| 36 | .sort((a, b) => score(b) - score(a)) |
| 37 | .slice(input.max) |
| 38 | } |
no test coverage detected