(entry: string)
| 88 | * Returns the updated history array |
| 89 | */ |
| 90 | export async function addToHistory(entry: string): Promise<string[]> { |
| 91 | const trimmed = entry.trim() |
| 92 | |
| 93 | // Don't add empty entries |
| 94 | if (!trimmed) { |
| 95 | return await loadHistory() |
| 96 | } |
| 97 | |
| 98 | const history = await loadHistory() |
| 99 | |
| 100 | // Don't add consecutive duplicates |
| 101 | if (history.length > 0 && history[history.length - 1] === trimmed) { |
| 102 | return history |
| 103 | } |
| 104 | |
| 105 | const updated = [...history, trimmed] |
| 106 | await saveHistory(updated) |
| 107 | |
| 108 | return updated.slice(-MAX_HISTORY_ENTRIES) |
| 109 | } |
no test coverage detected