UNPKG

liberty-prettydiff

Version:

Language aware code comparison tool for several web based languages. It also beautifies, minifies, and a few other things.

23 lines (19 loc) 520 B
enum ActionType { Append, Erase } interface AppendAction { type: ActionType.Append; text: string; } interface EraseAction { type: ActionType.Erase; numChars: number; } function updateText(currentText: string, action: AppendAction | EraseAction) { if (action.type === ActionType.Append) { // 'action' has type 'AppendAction' return currentText + action.text; } else { // 'action' has type 'EraseAction' return currentText.slice(0, -action.numChars); } }