```ts
const MODULUS = 1000000007;

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

  let a = 0, b = 1;
  for (let i = 2; i <= n; i++) {
    const nextMod = (a + b) % MODULUS;
    a = b;
    b = nextMod;
  }
  return b;
}
```