```ts
const MODULUS = 1000000007;

/** The nth Fibonacci number, modulo 1000000007. */
export function fibMod(n: number): number {
  if (n < 0) {
    throw new Error("Input must be a non-negative integer.");
  }

  let a = 0;
  let b = 1;

  for (let i = 0; i < n; i++) {
    [a, b] = [b, (a + b) % MODULUS];
  }

  return a;
}
```