Dev.to WebDev 🛠 Dev 👁 1 📖 2 min read

Building an IRC Table R602.7 Door & Window Rough Opening (R.O.) and Header Framing Solver in TypeScript

Framing mistakes around doors and windows almost always come from confusing nominal callout dimensions (like a 36" x 80" pre-hung door) with the framed Rough Opening (R.O.) and total header cut length including jack-stud

Framing mistakes around doors and windows almost always come from confusing nominal callout dimensions (like a 36" x 80" pre-hung door) with the framed Rough Opening (R.O.) and total header cut length including jack-stud bearings. A deterministic TypeScript solver turns every opening category into an exact lumber cut list.

1. Typed Opening Allowances Across 7 US Framing Categories

Different US millwork units require completely different rough-opening clearances (especially pocket doors, which frame to 2 * W + 1" width):

export type OpeningType =
  | 'prehung_interior'
  | 'prehung_exterior'
  | 'double_french'
  | 'pocket_door'
  | 'bifold_bypass'
  | 'garage_door'
  | 'window';

export type WallRole = 'non_bearing' | 'load_bearing_1story' | 'load_bearing_2story';

export interface RoughOpeningResult {
  roWidthIn: number;
  roHeightIn: number;
  jackStudsTotal: number;
  kingStudsTotal: number;
  headerSpec: string;
  headerCutLengthIn: number;
  upperCripples: number;
}

export function computeRoughOpening(
  type: OpeningType,
  nominalWidthIn: number,
  nominalHeightIn: number
): { roWidthIn: number; roHeightIn: number } {
  switch (type) {
    case 'prehung_interior':
    case 'prehung_exterior':
      return { roWidthIn: nominalWidthIn + 2, roHeightIn: nominalHeightIn + 2.5 };
    case 'double_french':
      return { roWidthIn: nominalWidthIn + 2.5, roHeightIn: nominalHeightIn + 2.5 };
    case 'pocket_door':
      return { roWidthIn: nominalWidthIn * 2 + 1, roHeightIn: nominalHeightIn + 4.5 };
    case 'bifold_bypass':
      return { roWidthIn: nominalWidthIn + 1.5, roHeightIn: nominalHeightIn + 2 };
    case 'garage_door':
      return { roWidthIn: nominalWidthIn, roHeightIn: nominalHeightIn };
    case 'window':
      return { roWidthIn: nominalWidthIn + 0.5, roHeightIn: nominalHeightIn + 0.5 };
  }
}

2. Preliminary IRC Table R602.7 Header & Stud Schedule

Once roWidthIn is solved, compute total jack studs (1.5" bearing per stud), total header cut length (roWidthIn + jackStudsTotal * 1.5), SPF #2 header depth for 30 psf ground snow / 28-ft building width preliminary sizing, and 16-inch OC upper cripples:

export function solveOpeningFraming(
  type: OpeningType,
  nominalWidthIn: number,
  nominalHeightIn: number,
  role: WallRole
): RoughOpeningResult {
  const { roWidthIn, roHeightIn } = computeRoughOpening(type, nominalWidthIn, nominalHeightIn);
  const jacksPerSide = role === 'non_bearing' ? 1 : roWidthIn <= 48 ? 1 : roWidthIn <= 72 ? 2 : 3;
  const jackStudsTotal = jacksPerSide * 2;
  const kingStudsTotal = 2;
  const headerCutLengthIn = roWidthIn + jackStudsTotal * 1.5;
  const upperCripples = Math.max(0, Math.ceil(roWidthIn / 16) - 1);

  let headerSpec = 'Single 2x4 Flat (Non-Bearing)';
  if (role === 'load_bearing_1story') {
    headerSpec =
      roWidthIn <= 38 ? '2-Ply 2x6 SPF #2' :
      roWidthIn <= 54 ? '2-Ply 2x8 SPF #2' :
      roWidthIn <= 74 ? '2-Ply 2x10 SPF #2' :
      roWidthIn <= 90 ? '2-Ply 2x12 SPF #2' : 'Engineered LVL Required';
  } else if (role === 'load_bearing_2story') {
    headerSpec =
      roWidthIn <= 36 ? '2-Ply 2x8 SPF #2' :
      roWidthIn <= 50 ? '2-Ply 2x10 SPF #2' :
      roWidthIn <= 66 ? '2-Ply 2x12 SPF #2' : 'Engineered LVL Required';
  }

  return {
    roWidthIn,
    roHeightIn,
    jackStudsTotal,
    kingStudsTotal,
    headerSpec,
    headerCutLengthIn,
    upperCripples
  };
}

3. Verifying Two Common Framing Traps

  • A 36" x 80" pre-hung front entry door in a 1-story load-bearing exterior wall resolves to 38" x 82.5" R.O., 2 jack studs (1 per side), 2 king studs, 2-Ply 2x6 SPF #2, and a 41" exact header cut length.
  • A 32" x 80" pocket door resolves to 65" x 84.5" R.O. (not 34"!), triggering 2 jacks per side (4 total) and a 71" header cut length if framed in a bearing partition.

Interactive Tool & Copyable Workbook

Disclaimer: Preliminary framing and space-planning software math only. Always verify rough openings against the manufacturer spec sheet and confirm structural headers with a licensed engineer and local AHJ.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.