{
  "schemaVersion": 1,
  "slug": "yarn-calculator",
  "category": "diy-craft",
  "kind": "implementation",
  "independentValidation": false,
  "implementationHash": "cdf6f0e2f32a74dbfed40aad1b6de8ee26d70c28ebede63fa1caf1ccb1f05ff1",
  "provenance": "Generated from the calculation contract used by the published page. Publication is not external validation.",
  "sourceFiles": [
    "data/calculators/yarn-calculator.json",
    "src/engine.js"
  ],
  "runtimeSource": "/sources/engine.txt",
  "runtimeHash": "5c888d8898afbdee36267bb9977829e1e2ac568f6677c8ee87469c139864645c",
  "scope": "The compute function records implemented equations, constants, lookup tables and custom rules. Inputs record defaults and allowed values; outputs record precision and units. Defaults are examples, not recommendations. General background references are not evidence for this specific algorithm.",
  "publishedFormula": {
    "formula": "L_low_adj = L_low×(1+p/100); L_high_adj = L_high×(1+p/100); L_mid = round((L_low_adj+L_high_adj)/2); skeins = ceil(L_high_adj/s); cost = skeins×c",
    "vars": [
      [
        "type",
        "Project type and yarn-weight class lookup"
      ],
      [
        "L_low",
        "Low chart yardage"
      ],
      [
        "L_high",
        "High chart yardage"
      ],
      [
        "p",
        "Waste allowance (%)"
      ],
      [
        "s",
        "Yards per skein"
      ],
      [
        "c",
        "Price per skein"
      ]
    ],
    "note": "Look up the low/high yardage by project and yarn-weight class, then multiply both bounds by (1 + waste%). The displayed yards are the rounded midpoint; meters = midpoint×0.9144; skeins = ceil(adjusted high ÷ yards per skein); cost = skeins×entered price. Ranges are estimates from [Lion Brand’s published chart](https://blog.lionbrand.com/wp-content/uploads/2019/03/HowMuchYarn_021819_H.pdf)."
  },
  "externalEvidence": {
    "reviewedAt": "2026-09-26",
    "sources": [
      {
        "name": "Lion Brand Yarn — How Much Yarn Do You Need?",
        "url": "https://www.lionbrand.com/pages/how-much-yarn-do-i-need"
      }
    ]
  },
  "contract": {
    "compute": "const ranges={hat:[[250,325],[250,325],[200,250],[200,225],[125,200],[125,150],[30,60]],scarf:[[525,825],[450,625],[375,500],[375,500],[250,375],[250,375],[125,200]],socks:[[350,500],[300,450],[275,400],[275,375],[250,350],[200,250],[175,200]],sweater:[[3375,3375],[1750,2625],[1500,2250],[1125,1625],[950,1125],[825,1125],[825,1125]],babyBlanket:[[1500,1625],[1250,1500],[1125,1250],[1000,1125],[875,1000],[750,875],[625,750]],blanket:[[3750,4125],[3500,3750],[3000,3500],[2250,3125],[2000,2250],[1625,2000],[1375,1625]]};const r=(ranges[projectType]||ranges.sweater)[Math.max(0,Math.min(6,Number(yarnWeight)-1))];const low=r[0]*(1+wastePct/100),high=r[1]*(1+wastePct/100),mid=(low+high)/2,skeins=yardsPerSkein>0?Math.ceil(high/yardsPerSkein):null;if(!(yardsPerSkein>0))return {yardsLow:null,yardsHigh:null,yardsNeeded:null,metersNeeded:null,skeinsNeeded:null,totalCost:null,__error:'inputError'};return {yardsLow:Math.round(low),yardsHigh:Math.round(high),yardsNeeded:Math.round(mid),metersNeeded:Math.round(mid*0.9144),skeinsNeeded:skeins,totalCost:skeins*skeinPrice};",
    "inputs": [
      {
        "name": "projectType",
        "type": "select",
        "default": "sweater",
        "options": [
          {
            "value": "sweater"
          },
          {
            "value": "scarf"
          },
          {
            "value": "hat"
          },
          {
            "value": "blanket"
          },
          {
            "value": "socks"
          },
          {
            "value": "babyBlanket"
          }
        ]
      },
      {
        "name": "yarnWeight",
        "type": "select",
        "default": "4",
        "options": [
          {
            "value": "1"
          },
          {
            "value": "2"
          },
          {
            "value": "3"
          },
          {
            "value": "4"
          },
          {
            "value": "5"
          },
          {
            "value": "6"
          },
          {
            "value": "7"
          }
        ]
      },
      {
        "name": "yardsPerSkein",
        "type": "number",
        "default": 200,
        "min": 1,
        "max": 2000,
        "step": 1,
        "slider": true
      },
      {
        "name": "skeinPrice",
        "type": "number",
        "default": 6,
        "min": 0,
        "max": 200,
        "step": 0.01
      },
      {
        "name": "wastePct",
        "type": "number",
        "default": 15,
        "min": 0,
        "max": 100,
        "step": 1,
        "slider": true
      }
    ],
    "outputs": [
      {
        "name": "yardsLow",
        "precision": 0,
        "unit": "yards"
      },
      {
        "name": "yardsHigh",
        "precision": 0,
        "unit": "yards"
      },
      {
        "name": "yardsNeeded",
        "precision": 0,
        "unit": "yards"
      },
      {
        "name": "metersNeeded",
        "precision": 0,
        "unit": "m"
      },
      {
        "name": "skeinsNeeded",
        "precision": 0,
        "unit": ""
      },
      {
        "name": "totalCost",
        "precision": 2,
        "unit": ""
      }
    ],
    "interpret": null
  }
}
