Yarn Sufficiency and Gauge Conversion from a Kitchen Scale

Skein & Gauge is a two-part yarn calculator. The first part answers "do I have enough to finish?" from the weight of a partial skein against its ball band. The second converts a pattern's stitch counts to a knitter's actual gauge and rounds the result to a stitch repeat. It is a single-file, offline tool; saved yarns persist locally [1].

The problem

Two recurring questions in a project both have exact answers that get guessed at instead. The first is whether the yarn on hand will reach the bind-off — usually estimated by eye from a half-used ball, then discovered wrong at the worst moment. The second is what a pattern's numbers become when your swatch does not match the pattern's gauge — the point at which a garment quietly ends up a size off. A kitchen scale and a ball band answer the first exactly; a proportion answers the second.

How it works

Do I have enough? takes the ball band's weight and length, the weight of the partial skein on a kitchen scale, the number of full skeins, and what the pattern needs. It reports the total length on hand, draws two comparison bars (have vs. need), and gives a verdict. Length can be toggled between yards and metres, and any entered length converts in place. A yarn "stash" of ball-band presets can be saved by name and recalled, persisted under localStorage key skeinmath.v1.

Skein and Gauge sufficiency panel showing have-vs-need bars and an amber close verdict
The sufficiency panel with the have/need bars and verdict. Placeholder pending a real screenshot.

Gauge conversion takes the pattern gauge, your gauge (per 4 in or per 10 cm), a stitch count, and an optional repeat. It reports the adjusted count, the pattern's intended finished dimension, and the "drift" — what the pattern's unmodified count would produce at your gauge if you ignored the mismatch and knit it as written.

The math

Sufficiency

Yardage from weight assumes even winding — length is proportional to mass:

remaining = (partial_grams / ball_grams) × ball_length  +  full_skeins × ball_length

The verdict wants margin, not just coverage, because seams, swatches, and one frogged section all eat yarn:

Gauge

Conversion is a straight proportion of the two gauges:

adjusted_count = pattern_count × (my_gauge / pattern_gauge)

The same ratio converts row counts and shaping intervals. When gauge differs by more than 15% the tool notes that yardage shifts too.

Repeat rounding

A proportional result rarely lands on a legal stitch count for a patterned fabric. Instead of taking the raw number, the tool snaps it to the nearest value of the form "a multiple of N, plus P", checking the three nearest candidate multiples and picking whichever is closest to the unrounded target:

base   = round((target - plus) / mult)
cands  = [base-1, base, base+1] × mult + plus   (positive only)
result = the candidate nearest target

Editing the config

This tool is almost entirely input-driven — there is no facility table to tune. The two constants worth knowing are at the top of the <script> block: YD_PER_M (the yard/metre conversion factor) and LS_KEY (the storage key). The rounding behavior is the roundToRepeat() function; the sufficiency verdict thresholds (the 110% and 100% cutoffs) are inline in calcYarn(). Saved yarns are stored as a stash object keyed by name.

Limitations

Update: even shaping (v1.1.0)

Version 1.1.0 adds a third panel that turns "decrease 7 evenly across 91" or "increase from 48 to 96 over 60 rows" into the literal instruction, in two modes with a decrease/increase toggle.

Across a row

Distributing C changes across N stitches divides the row into C groups of floor(N/C) stitches, with the N mod C leftover stitches absorbed one each into the larger groups. The result is run-length-encoded into pattern language using k2tog (decrease) or kfb (increase):

91 sts, decrease 7  →  [k11, k2tog] 7×          (ends with 84 sts)

Validation blocks impossible requests: decreasing more than floor(N/2) (each k2tog consumes two stitches) or increasing by more than N.

Over rows

Shaping S times across R rows rarely divides evenly, so the panel produces the standard two-interval split — larger interval floor(R/S)+1 for R mod S repetitions, then smaller interval floor(R/S) for the rest:

48 → 96 sts over 60 rows at 2 per shaping row
  = 24 shaping rows  →  inc 2 every 3rd row 12×, then every 2nd row 12×

It validates that the direction toggle matches the start/end counts, that the stitch difference divides evenly by the per-row change, and that the required shaping rows fit inside the row budget — each failure states which constraint broke rather than emitting a wrong instruction.

Even shaping panel showing a run-length-encoded decrease instruction and the resulting stitch count
The v1.1.0 shaping panel: a distribute-across-the-row instruction in pattern language. Placeholder pending a real screenshot.

Configuration

The shaping logic lives in the acrossInstruction() and overRows() functions in the <script> block; the decrease/increase verbs (k2tog/kfb) are set in acrossInstruction(). Mode and direction selections persist with the rest of the tool state under skeinmath.v1.

References

  1. Skein & Gauge Calculator