===== ISTEM =====
Solve the following programming task.

TASK: Text Editor with Undo and Redo

Write a class 'Editor' that holds a text document (initially an empty string) and a cursor position (initially 0), with these methods:
- type(text): inserts text at the cursor and moves the cursor to the end of the inserted text.
- moveTo(pos): moves the cursor to pos, clamped to the range 0 to the current text length.
- backspace(n): deletes up to n characters immediately before the cursor (fewer if the cursor is closer than n to the start) and moves the cursor back by the number of characters deleted.
- undo(): reverts the most recent undo step. Does nothing if there is none.
- redo(): re-applies the most recently undone step. Does nothing if there is none.
- getText(): returns the current text.
- getCursor(): returns the current cursor position.

Undo steps:
- Every call to type, and every call to backspace that deletes at least one character, is an edit. An edit normally creates a new undo step.
- Exception: a type call is added to the previous undo step, instead of creating a new one, if the method called immediately before it (not counting getText and getCursor) was also type.
- A backspace that deletes nothing (cursor already at 0) changes nothing and creates no undo step.
- Undoing a step restores the text and the cursor to exactly what they were before the step. Redoing a step restores them to exactly what they were at the end of the step.
- Every edit clears the redo history. moveTo, undo and redo never clear it.

STARTER CODE (javascript):
class Editor {
  // Write your code here
}

module.exports = { Editor };


RULES:
- Keep the function name and signature EXACTLY as given.
- Return working code only. No explanations.
- Put the code in a single ``` block.
- Try to solve it first. If you genuinely cannot, write only this single
  line instead of producing faulty code: CANNOT_SOLVE

===== HAM YANIT =====
```javascript
class Editor {
  constructor() {
    this.text = '';
    this.cursor = 0;
    this.history = [];
    this.redoHistory = [];
  }

  type(text) {
    const start = this.text.slice(0, this.cursor);
    const end = this.text.slice(this.cursor);
    this.text = start + text + end;
    this.cursor += text.length;
    this.redoHistory = [];
    if (this.history.length > 0 && this.history[this.history.length - 1].action === 'type') {
      this.history[this.history.length - 1].text += text;
    } else {
      this.history.push({ action: 'type', text, cursor: this.cursor });
    }
  }

  moveTo(pos) {
    this.cursor = Math.min(Math.max(pos, 0), this.text.length);
    this.redoHistory = [];
  }

  backspace(n) {
    if (this.cursor === 0) return;
    const deleteCount = Math.min(n, this.cursor);
    const start = this.text.slice(0, this.cursor - deleteCount);
    const end = this.text.slice(this.cursor);
    this.text = start + end;
    this.cursor -= deleteCount;
    this.redoHistory = [];
    this.history.push({ action: 'backspace', deleteCount, cursor: this.cursor });
  }

  undo() {
    if (this.history.length === 0) return;
    const step = this.history.pop();
    if (step.action === 'type') {
      const start = this.text.slice(0, step.cursor - step.text.length);
      const end = this.text.slice(step.cursor);
      this.text = start + end;
      this.cursor = step.cursor;
    } else if (step.action === 'backspace') {
      const start = this.text.slice(0, step.cursor + step.deleteCount);
      const end = this.text.slice(step.cursor);
      this.text = start + end;
      this.cursor = step.cursor + step.deleteCount;
    }
    this.redoHistory.push(step);
  }

  redo() {
    if (this.redoHistory.length === 0) return;
    const step = this.redoHistory.pop();
    if (step.action === 'type') {
      const start = this.text.slice(0, step.cursor);
      const end = this.text.slice(step.cursor);
      this.text = start + step.text + end;
      this.cursor = step.cursor + step.text.length;
    } else if (step.action === 'backspace') {
      const start = this.text.slice(0, step.cursor);
      const end = this.text.slice(step.cursor + step.deleteCount);
      this.text = start + end;
      this.cursor = step.cursor;
    }
    this.history.push(step);
  }

  getText() {
    return this.text;
  }

  getCursor() {
    return this.cursor;
  }
}

module.exports = { Editor };
```