```ts
export function clipText(text: string, from: number, to: number): string {
  if (from < 0 || to > text.length) {
    throw new Error('Both from and to must be within the bounds of the text');
  }

  if (from > to) {
    const temp = from;
    from = to;
    to = temp;
  }

  return text.substring(from, to);
}
```