(historyPath = HISTORY_PATH)
| 508 | } |
| 509 | |
| 510 | if (leftCommand.category !== rightCommand.category) { |
| 511 | return leftCommand.category.localeCompare(rightCommand.category) |
| 512 | } |
| 513 | |
| 514 | return leftCommand.name.localeCompare(rightCommand.name) |
| 515 | }) |
| 516 | |
| 517 | export const readRecentCommands = async (historyPath = HISTORY_PATH): Promise<Record<string, number>> => { |
| 518 | try { |
| 519 | const historyContent = await readFile(historyPath, 'utf8') |
| 520 | |
| 521 | return historyContent |
| 522 | .split('\n') |
| 523 | .filter(Boolean) |
| 524 | .reduce<Record<string, number>>((recentCommands, line) => { |
| 525 | const [key, timestampValue] = line.split('\t') |
| 526 | const timestamp = Number(timestampValue) |
| 527 | |
| 528 | if (key && Number.isFinite(timestamp)) { |
| 529 | recentCommands[key] = timestamp |
| 530 | } |
| 531 | |
| 532 | return recentCommands |
| 533 | }, {}) |
| 534 | } catch (error) { |
| 535 | if (error instanceof Error && 'code' in error && error.code === 'ENOENT') { |
| 536 | return {} |
| 537 | } |
no outgoing calls
no test coverage detected