MCPcopy Create free account
hub / github.com/ZingerLittleBee/ServerBee / orderCommandsForMenu

Function orderCommandsForMenu

scripts/make-menu.ts:484–508  ·  view source on GitHub ↗
(
  commands: CommandDefinition[],
  recentCommands: Record<string, number>
)

Source from the content-addressed store, hash-verified

482})
483
484export const orderCommandsForMenu = (
485 commands: CommandDefinition[],
486 recentCommands: Record<string, number>
487): CommandDefinition[] =>
488 [...commands].sort((leftCommand, rightCommand) => {
489 const leftTimestamp = recentCommands[leftCommand.key] ?? 0
490 const rightTimestamp = recentCommands[rightCommand.key] ?? 0
491
492 if (leftTimestamp !== rightTimestamp) {
493 return rightTimestamp - leftTimestamp
494 }
495
496 const leftDefaultOrder = DEFAULT_ORDER_BY_KEY.get(leftCommand.key)
497 const rightDefaultOrder = DEFAULT_ORDER_BY_KEY.get(rightCommand.key)
498
499 if (leftDefaultOrder !== undefined && rightDefaultOrder !== undefined) {
500 return leftDefaultOrder - rightDefaultOrder
501 }
502
503 if (leftCommand.category !== rightCommand.category) {
504 return leftCommand.category.localeCompare(rightCommand.category)
505 }
506
507 return leftCommand.name.localeCompare(rightCommand.name)
508 })
509
510export const readRecentCommands = async (historyPath = HISTORY_PATH): Promise<Record<string, number>> => {
511 try {

Callers 2

make-menu.test.tsFile · 0.90
openMenuFunction · 0.85

Calls 1

getMethod · 0.45

Tested by

no test coverage detected