@washy-washy/core 1.6.3 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,25 +1,579 @@
1
- import { A as ironSettingKeys, C as variants, D as MAX_WASHER_TEMPERATURE_LENGTH, E as MAX_WASHER_SPIN_LENGTH, O as formatTemperature, S as mixTags, T as MAX_WASHER_PROGRAM_LENGTH, _ as chartToJson, a as ironGroups, b as colourGroups, c as resolve, d as configFromJson, f as configToJson, g as chartFromJson, h as RowError, i as cardGroups, j as parseMachine, k as ironSetting, l as washGroups, m as COLUMNS, n as blockerLegend, o as loadGroups, p as parseConfig, r as canMix, s as mixBlocker, t as blockerCode, u as CONFIG_SCHEMA_URL, v as instructionsFromRows, w as MAX_WASHER_OPTION_LENGTH, x as durationsOf, y as rowsFromInstructions } from "./mixing-DEthnE5k.mjs";
2
- import { parse } from "csv-parse/sync";
3
- //#region src/csv.ts
1
+ // src/machine.ts
2
+ function fail(what) {
3
+ throw new Error(`machine: ${what}`);
4
+ }
5
+ function stringList(value, field, minimum, maxLength) {
6
+ if (!Array.isArray(value) || value.some((entry) => typeof entry !== "string" || entry === "")) fail(`${field} must be a list of non-empty strings`);
7
+ const list = value;
8
+ if (list.length < minimum) fail(`${field} needs at least ${minimum} entries, found ${list.length}`);
9
+ if (new Set(list).size !== list.length) fail(`${field} repeats a value`);
10
+ const overlong = list.find((entry) => entry.length > maxLength);
11
+ if (overlong !== void 0) fail(`${field} entries must be at most ${maxLength} characters, found "${overlong}"`);
12
+ return list;
13
+ }
14
+ function text(value, field, maxLength, fallback) {
15
+ const resolved = typeof value === "string" && value !== "" ? value : fallback !== void 0 ? fallback : fail(`${field} must be a non-empty string`);
16
+ if (resolved.length > maxLength) fail(`${field} must be at most ${maxLength} characters, found ${resolved.length}`);
17
+ return resolved;
18
+ }
19
+ /** How many dots a thermostat position's dial label draws — never more than a handful. */
20
+ const MAX_DOTS_LENGTH = 5;
21
+ /** Longest a single washer.programs dial caption can be. */
22
+ const MAX_WASHER_PROGRAM_LENGTH = 32;
23
+ /**
24
+ * Longest a single washer.temperatures entry can be — the reference sheet's
25
+ * °C column. Raised from 12 once washy-washy-pdf#61 made room (see #36).
26
+ */
27
+ const MAX_WASHER_TEMPERATURE_LENGTH = 15;
28
+ /** Longest a single washer.spins entry can be. */
29
+ const MAX_WASHER_SPIN_LENGTH = 10;
30
+ /** Longest a single washer.options chip can be. */
31
+ const MAX_WASHER_OPTION_LENGTH = 20;
32
+ function parseIronSetting(value, index) {
33
+ if (typeof value !== "object" || value === null) fail(`iron.settings[${index}] must be an object`);
34
+ const raw = value;
35
+ const key = text(raw.key, `iron.settings[${index}].key`, 30);
36
+ const dots = typeof raw.dots === "string" ? raw.dots : "";
37
+ if (dots.length > MAX_DOTS_LENGTH) fail(`iron.settings[${index}].dots must be at most ${MAX_DOTS_LENGTH} characters`);
38
+ return {
39
+ key,
40
+ dots,
41
+ label: text(raw.label, `iron.settings[${index}].label`, 20),
42
+ detail: text(raw.detail, `iron.settings[${index}].detail`, 60, ""),
43
+ steam: raw.steam === true
44
+ };
45
+ }
46
+ /**
47
+ * Checks a parsed machine file and hands back something the renderer can use.
48
+ * Every failure names the field, because the fix is always an edit to that
49
+ * line of JSON.
50
+ *
51
+ * @example
52
+ * ```ts
53
+ * const machine = parseMachine(JSON.parse(machineFileContents));
54
+ * machine.washer.programs; // ["Off", "Cottons", "Wool", ...]
55
+ * ```
56
+ */
57
+ function parseMachine(value) {
58
+ if (typeof value !== "object" || value === null) fail("the file must contain an object");
59
+ const raw = value;
60
+ if (typeof raw.washer !== "object" || raw.washer === null) fail("washer is missing");
61
+ if (typeof raw.iron !== "object" || raw.iron === null) fail("iron is missing");
62
+ const washerRaw = raw.washer;
63
+ const ironRaw = raw.iron;
64
+ const settings = Array.isArray(ironRaw.settings) ? ironRaw.settings : fail("iron.settings is missing");
65
+ if (settings.length < 2) fail("iron.settings needs at least 2 positions to draw a ring");
66
+ const keys = settings.map((setting, index) => parseIronSetting(setting, index));
67
+ if (new Set(keys.map((setting) => setting.key)).size !== keys.length) fail("iron.settings repeats a key");
68
+ return {
69
+ washer: {
70
+ name: text(washerRaw.name, "washer.name", 60),
71
+ capacity: text(washerRaw.capacity, "washer.capacity", 30, ""),
72
+ programs: stringList(washerRaw.programs, "washer.programs", 2, 32),
73
+ temperatures: stringList(washerRaw.temperatures, "washer.temperatures", 1, 15),
74
+ spins: stringList(washerRaw.spins, "washer.spins", 1, 10),
75
+ options: stringList(washerRaw.options ?? [], "washer.options", 0, 20)
76
+ },
77
+ iron: {
78
+ name: text(ironRaw.name, "iron.name", 60),
79
+ settings: keys
80
+ }
81
+ };
82
+ }
83
+ /**
84
+ * @example
85
+ * ```ts
86
+ * ironSetting(machine, "2")?.label; // "••"
87
+ * ironSetting(machine, "nope"); // undefined
88
+ * ```
89
+ */
90
+ function ironSetting(machine, key) {
91
+ return machine.iron.settings.find((setting) => setting.key === key);
92
+ }
93
+ /**
94
+ * The keys a row may write in `iron_setting`, coolest first.
95
+ *
96
+ * There is no key for "do not iron". That is the `ironing` column's job, and
97
+ * two places to say the same thing is two places to disagree.
98
+ *
99
+ * @example
100
+ * ```ts
101
+ * ironSettingKeys(machine); // ["min", "1", "2", "3"]
102
+ * ```
103
+ */
104
+ function ironSettingKeys(machine) {
105
+ return machine.iron.settings.map((setting) => setting.key);
106
+ }
107
+ /**
108
+ * `40` becomes `40°`; `cold` stays `cold`. The machine file is free to use
109
+ * whatever word its display shows for the cold wash, so the degree sign is
110
+ * decided by whether the value is a number rather than by a list of exceptions.
111
+ *
112
+ * @example
113
+ * ```ts
114
+ * formatTemperature("40"); // "40°"
115
+ * formatTemperature("cold"); // "cold"
116
+ * ```
117
+ */
118
+ function formatTemperature(value) {
119
+ return /^\d+$/.test(value) ? `${value}°` : value;
120
+ }
121
+ // src/types.ts
122
+ /** Which pile a garment belongs to on colour grounds. `any` mixes with all. */
123
+ const colourGroups = [
124
+ "white",
125
+ "colour",
126
+ "dark",
127
+ "sport",
128
+ "any"
129
+ ];
130
+ /**
131
+ * Reasons two piles might not belong together even when the machine settings
132
+ * agree. See `canMix` in `mixing.ts` for how each one is applied.
133
+ */
134
+ const mixTags = [
135
+ "lint-shedder",
136
+ "lint-magnet",
137
+ "dye-bleeder",
138
+ "solo"
139
+ ];
140
+ /**
141
+ * How long a card or a load is going to tie the machine up.
142
+ *
143
+ * Usually one figure. Piles sharing a load agree on every setting, so they
144
+ * ought to agree on this too — but the chart is data somebody types, and
145
+ * printing both is more honest than picking the first one and hoping.
146
+ *
147
+ * @example
148
+ * ```ts
149
+ * durationsOf([pile, pile]); // "~2:00"
150
+ * durationsOf([pile, { ...pile, duration: "~1:10" }]); // "~2:00 / ~1:10"
151
+ * ```
152
+ */
153
+ function durationsOf(group) {
154
+ return [...new Set(group.map((item) => item.duration).filter((value) => value !== ""))].join(" / ");
155
+ }
156
+ /**
157
+ * Which sheet to draw.
158
+ *
159
+ * `full` is the whole chart. The other two are the same chart cut where the
160
+ * work is: washing happens in front of the machine on a Sunday morning, ironing
161
+ * happens at a board on a Wednesday evening, and neither job wants to read past
162
+ * the other's advice to find its own.
163
+ */
164
+ const variants = [
165
+ "full",
166
+ "wash",
167
+ "iron"
168
+ ];
169
+ // src/rows.ts
170
+ const COLUMNS = [
171
+ "clothing_type",
172
+ "detergent",
173
+ "fabric_softener",
174
+ "temperature",
175
+ "spin",
176
+ "duration",
177
+ "program",
178
+ "options",
179
+ "ironing",
180
+ "ironing_notes",
181
+ "iron_setting",
182
+ "drying",
183
+ "colour_group",
184
+ "mix_tags",
185
+ "notes",
186
+ "reference_name",
187
+ "reference_link"
188
+ ];
189
+ var RowError = class extends Error {
190
+ constructor(row, column, message) {
191
+ super(`row ${row}, column "${column}": ${message}`);
192
+ this.name = "RowError";
193
+ }
194
+ };
195
+ /** `a|b|c` -> `["a", "b", "c"]`, tolerating stray whitespace and empties. */
196
+ function splitList(value) {
197
+ return value.split("|").map((part) => part.trim()).filter((part) => part.length > 0);
198
+ }
199
+ function oneOf(row, column, value, allowed) {
200
+ if (!allowed.includes(value)) throw new RowError(row, column, `"${value}" is not one of ${allowed.join(", ")}`);
201
+ return value;
202
+ }
4
203
  /**
5
- * Parses the instruction CSV. See `instructionsFromRows` for the row rules.
204
+ * Caps free-text fields the PDFs render, so a value long enough to visibly
205
+ * crowd a card or reference-sheet row is rejected here rather than in a
206
+ * layout that only degrades quietly. Limits from @washy-washy/pdf's actual
207
+ * fixed-width slots and wrap-safety analysis, not a guess.
208
+ */
209
+ function maxLength(row, column, value, max) {
210
+ if (value.length > max) throw new RowError(row, column, `must be at most ${max} characters, found ${value.length}`);
211
+ return value;
212
+ }
213
+ function boolean(row, column, value) {
214
+ const normalised = value.trim().toLowerCase();
215
+ if ([
216
+ "yes",
217
+ "y",
218
+ "true",
219
+ "1"
220
+ ].includes(normalised)) return true;
221
+ if ([
222
+ "no",
223
+ "n",
224
+ "false",
225
+ "0"
226
+ ].includes(normalised)) return false;
227
+ throw new RowError(row, column, `"${value}" is not a yes/no value`);
228
+ }
229
+ const DURATION_PATTERN = /^~?\d+:[0-5]\d$/;
230
+ /** Empty stays empty — some piles genuinely have no duration on record. */
231
+ function duration(row, column, value) {
232
+ if (value === "") return value;
233
+ if (!DURATION_PATTERN.test(value)) throw new RowError(row, column, `must match H:MM, found "${value}"`);
234
+ return maxLength(row, column, value, 12);
235
+ }
236
+ /**
237
+ * Checks rows shaped like the chart's schema, such as a JSON file
238
+ * round-tripped through `rowsFromInstructions`, against what the appliances in the machine file can actually be set to. A typo in a
239
+ * programme name fails here rather than producing a PDF that tells you to turn
240
+ * the dial to a position that does not exist — and so does a chart written for
241
+ * a different machine than the one you passed.
6
242
  *
7
243
  * @example
8
244
  * ```ts
9
- * const instructions = parseInstructions(csvFileContents, machine);
245
+ * const instructions = instructionsFromRows(JSON.parse(jsonFromStorage), machine);
10
246
  * ```
11
247
  */
12
- function parseInstructions(source, machine) {
13
- const records = parse(source, {
14
- columns: true,
15
- skip_empty_lines: true,
16
- trim: true,
17
- bom: true
248
+ function instructionsFromRows(rows, machine) {
249
+ const { washer } = machine;
250
+ if (rows.length === 0) throw new Error("the chart has no rows");
251
+ const header = Object.keys(rows[0]);
252
+ const missing = COLUMNS.filter((column) => !header.includes(column));
253
+ if (missing.length > 0) throw new Error(`the chart is missing column(s): ${missing.join(", ")}`);
254
+ return rows.map((record, index) => {
255
+ const row = index + 2;
256
+ const clothingType = maxLength(row, "clothing_type", (record.clothing_type ?? "").trim(), 60);
257
+ if (clothingType === "") throw new RowError(row, "clothing_type", "must not be empty");
258
+ const options = splitList(record.options ?? "").map((option) => oneOf(row, "options", option, washer.options));
259
+ const tags = splitList(record.mix_tags ?? "").map((tag) => oneOf(row, "mix_tags", tag, mixTags));
260
+ const ironing = boolean(row, "ironing", record.ironing ?? "");
261
+ const rawSetting = (record.iron_setting ?? "").trim();
262
+ if (!ironing && rawSetting !== "") throw new RowError(row, "iron_setting", `must be empty when ironing is no, found "${rawSetting}"`);
263
+ const ironSetting = ironing ? oneOf(row, "iron_setting", rawSetting, ironSettingKeys(machine)) : "";
264
+ return {
265
+ clothingType,
266
+ detergent: maxLength(row, "detergent", record.detergent ?? "", 200),
267
+ fabricSoftener: boolean(row, "fabric_softener", record.fabric_softener ?? ""),
268
+ temperature: oneOf(row, "temperature", record.temperature ?? "", washer.temperatures),
269
+ spin: oneOf(row, "spin", record.spin ?? "", washer.spins),
270
+ duration: duration(row, "duration", record.duration ?? ""),
271
+ program: oneOf(row, "program", record.program ?? "", washer.programs),
272
+ options,
273
+ ironing,
274
+ ironingNotes: maxLength(row, "ironing_notes", record.ironing_notes ?? "", 400),
275
+ ironSetting,
276
+ drying: maxLength(row, "drying", record.drying ?? "", 230),
277
+ colourGroup: oneOf(row, "colour_group", record.colour_group ?? "", colourGroups),
278
+ mixTags: tags,
279
+ notes: maxLength(row, "notes", record.notes ?? "", 570),
280
+ referenceName: maxLength(row, "reference_name", record.reference_name ?? "", 80),
281
+ referenceLink: maxLength(row, "reference_link", record.reference_link ?? "", 2048)
282
+ };
18
283
  });
19
- if (records.length === 0) throw new Error("the CSV has a header but no rows");
20
- return instructionsFromRows(records, machine);
21
284
  }
22
- //#endregion
23
- export { COLUMNS, CONFIG_SCHEMA_URL, MAX_WASHER_OPTION_LENGTH, MAX_WASHER_PROGRAM_LENGTH, MAX_WASHER_SPIN_LENGTH, MAX_WASHER_TEMPERATURE_LENGTH, RowError, blockerCode, blockerLegend, canMix, cardGroups, chartFromJson, chartToJson, colourGroups, configFromJson, configToJson, durationsOf, formatTemperature, instructionsFromRows, ironGroups, ironSetting, ironSettingKeys, loadGroups, mixBlocker, mixTags, parseConfig, parseInstructions, parseMachine, resolve, rowsFromInstructions, variants, washGroups };
285
+ /**
286
+ * The reverse of `instructionsFromRows` — what a JSON export writes out.
287
+ *
288
+ * @example
289
+ * ```ts
290
+ * const rows = rowsFromInstructions(instructions);
291
+ * ```
292
+ */
293
+ function rowsFromInstructions(instructions) {
294
+ return instructions.map((instruction) => ({
295
+ clothing_type: instruction.clothingType,
296
+ detergent: instruction.detergent,
297
+ fabric_softener: instruction.fabricSoftener ? "yes" : "no",
298
+ temperature: instruction.temperature,
299
+ spin: instruction.spin,
300
+ duration: instruction.duration,
301
+ program: instruction.program,
302
+ options: instruction.options.join("|"),
303
+ ironing: instruction.ironing ? "yes" : "no",
304
+ ironing_notes: instruction.ironingNotes,
305
+ iron_setting: instruction.ironSetting,
306
+ drying: instruction.drying,
307
+ colour_group: instruction.colourGroup,
308
+ mix_tags: instruction.mixTags.join("|"),
309
+ notes: instruction.notes,
310
+ reference_name: instruction.referenceName,
311
+ reference_link: instruction.referenceLink
312
+ }));
313
+ }
314
+ /**
315
+ * The JSON interchange format for a chart — the same row shape
316
+ * a chart's JSON Schema describes, so a file written here validates against
317
+ * it.
318
+ *
319
+ * @example
320
+ * ```ts
321
+ * const json = chartToJson(instructions);
322
+ * ```
323
+ */
324
+ function chartToJson(instructions) {
325
+ return `${JSON.stringify(rowsFromInstructions(instructions), null, 2)}\n`;
326
+ }
327
+ /**
328
+ * The other half of `chartToJson`. Throws the same errors `instructionsFromRows` does.
329
+ *
330
+ * @example
331
+ * ```ts
332
+ * const instructions = chartFromJson(jsonFromStorage, machine);
333
+ * ```
334
+ */
335
+ function chartFromJson(source, machine) {
336
+ let rows;
337
+ try {
338
+ rows = JSON.parse(source);
339
+ } catch (error) {
340
+ throw new Error(`not valid JSON: ${error instanceof Error ? error.message : error}`);
341
+ }
342
+ if (!Array.isArray(rows)) throw new Error("the chart must be a JSON array of rows");
343
+ return instructionsFromRows(rows, machine);
344
+ }
345
+ // src/config.ts
346
+ /**
347
+ * Where `configToJson` points editors at the real JSON Schema (generated
348
+ * from the `Config` type — see `schema/config.schema.json` and `bun run
349
+ * schema`). Unpinned to the package's `latest` npm tag rather than the
350
+ * running version, matching how most `$schema` URLs work: close enough,
351
+ * without needing a build-time read of this package's own `package.json`.
352
+ */
353
+ const CONFIG_SCHEMA_URL = "https://cdn.jsdelivr.net/npm/@washy-washy/core/schema/config.schema.json";
354
+ /**
355
+ * Validates a `{ machine, chart }` object, checking the chart against the
356
+ * machine it's embedded with — never a different one. Every failure names
357
+ * which half is wrong, same as `parseMachine` and `instructionsFromRows` do
358
+ * on their own.
359
+ *
360
+ * @example
361
+ * ```ts
362
+ * const config = parseConfig(JSON.parse(configFileContents));
363
+ * config.machine.washer.name; // "Generic front loader"
364
+ * config.chart[0].clothingType; // "Dark"
365
+ * ```
366
+ */
367
+ function parseConfig(value) {
368
+ if (typeof value !== "object" || value === null) throw new Error("config: the file must contain an object");
369
+ const raw = value;
370
+ if (!("machine" in raw)) throw new Error("config: machine is missing");
371
+ if (!("chart" in raw)) throw new Error("config: chart is missing");
372
+ const machine = parseMachine(raw.machine);
373
+ if (!Array.isArray(raw.chart)) throw new Error("config: chart must be an array of rows");
374
+ return {
375
+ machine,
376
+ chart: instructionsFromRows(raw.chart, machine)
377
+ };
378
+ }
379
+ /**
380
+ * The reverse of `parseConfig` — what a JSON export writes out. Leads with a
381
+ * `$schema` key so an editor that reads it (VS Code among them) validates
382
+ * and autocompletes the file without the person editing it doing anything.
383
+ * `parseConfig` ignores the key on the way back in — it never asks for
384
+ * anything beyond `machine` and `chart`.
385
+ *
386
+ * @example
387
+ * ```ts
388
+ * const json = configToJson(config);
389
+ * ```
390
+ */
391
+ function configToJson(config) {
392
+ const rows = {
393
+ $schema: CONFIG_SCHEMA_URL,
394
+ machine: config.machine,
395
+ chart: rowsFromInstructions(config.chart)
396
+ };
397
+ return `${JSON.stringify(rows, null, 2)}\n`;
398
+ }
399
+ /**
400
+ * The other half of `configToJson`. Throws the same errors `parseConfig` does.
401
+ *
402
+ * @example
403
+ * ```ts
404
+ * const config = configFromJson(configFileContents);
405
+ * ```
406
+ */
407
+ function configFromJson(source) {
408
+ let value;
409
+ try {
410
+ value = JSON.parse(source);
411
+ } catch (error) {
412
+ throw new Error(`config: not valid JSON: ${error instanceof Error ? error.message : error}`);
413
+ }
414
+ return parseConfig(value);
415
+ }
416
+ // src/mixing.ts
417
+ const blockerLegend = {
418
+ solo: "Wash on its own",
419
+ settings: "Different programme, temperature, spin or options",
420
+ colour: "Colours would run into each other",
421
+ lint: "One sheds lint onto the other"
422
+ };
423
+ /** Short codes used in the compatibility matrix, so a cell stays one glyph. */
424
+ const blockerCode = {
425
+ solo: "S",
426
+ settings: "P",
427
+ colour: "C",
428
+ lint: "L"
429
+ };
430
+ function sameSettings(a, b) {
431
+ return a.program === b.program && a.temperature === b.temperature && a.spin === b.spin && a.options.length === b.options.length && a.options.every((option) => b.options.includes(option));
432
+ }
433
+ function compatibleColours(a, b) {
434
+ if (a.colourGroup === "any" || b.colourGroup === "any") return true;
435
+ return a.colourGroup === b.colourGroup;
436
+ }
437
+ /**
438
+ * Decides whether two piles can go in the drum together, and if not, why.
439
+ *
440
+ * The order matters: the reason reported is the one you would want to hear
441
+ * first. "Wash it alone" beats "the spin speed differs", because changing the
442
+ * spin speed would not help.
443
+ *
444
+ * @example
445
+ * ```ts
446
+ * mixBlocker(towels, socks); // "lint" — towels shed onto everything else
447
+ * mixBlocker(socks, socks2); // null — nothing stops them sharing a drum
448
+ * ```
449
+ */
450
+ function mixBlocker(a, b) {
451
+ if (a.mixTags.includes("solo") || b.mixTags.includes("solo")) return "solo";
452
+ if ([a, b].filter((item) => item.mixTags.includes("lint-shedder")).length === 1) return "lint";
453
+ if (!compatibleColours(a, b)) return "colour";
454
+ if (!sameSettings(a, b)) return "settings";
455
+ return null;
456
+ }
457
+ /**
458
+ * @example
459
+ * ```ts
460
+ * canMix(towels, socks); // false
461
+ * ```
462
+ */
463
+ function canMix(a, b) {
464
+ return mixBlocker(a, b) === null;
465
+ }
466
+ /**
467
+ * Annotates each instruction with the other piles it may share a load with.
468
+ *
469
+ * @example
470
+ * ```ts
471
+ * resolve(instructions)[0].mixesWith; // ["Socks", "Jeans"]
472
+ * ```
473
+ */
474
+ function resolve(instructions) {
475
+ return instructions.map((instruction) => ({
476
+ ...instruction,
477
+ mixesWith: instructions.filter((other) => other !== instruction && canMix(instruction, other)).map((other) => other.clothingType)
478
+ }));
479
+ }
480
+ /**
481
+ * Groups piles that can all be washed together — every member compatible with
482
+ * every other, not merely with the first one it met.
483
+ *
484
+ * @example
485
+ * ```ts
486
+ * loadGroups(instructions); // [[towels], [socks, jeans], [wool]]
487
+ * ```
488
+ */
489
+ function loadGroups(instructions) {
490
+ const groups = [];
491
+ for (const instruction of instructions) {
492
+ const home = groups.find((group) => group.every((member) => canMix(member, instruction)));
493
+ if (home) home.push(instruction);
494
+ else groups.push([instruction]);
495
+ }
496
+ return groups;
497
+ }
498
+ function groupBy(items, key) {
499
+ const groups = /* @__PURE__ */ new Map();
500
+ for (const item of items) {
501
+ const existing = groups.get(key(item));
502
+ if (existing) existing.push(item);
503
+ else groups.set(key(item), [item]);
504
+ }
505
+ return [...groups.values()];
506
+ }
507
+ /**
508
+ * Everything you physically set on the washing machine: the programme, what
509
+ * the display reads, which buttons are lit, and whether softener goes in.
510
+ *
511
+ * Deliberately *not* the prose. Two piles can want the same five settings and
512
+ * still want different detergent or a different drying rack, and those the card
513
+ * lists per pile rather than splitting into two near-identical cards.
514
+ */
515
+ function washFingerprint(item) {
516
+ return JSON.stringify([
517
+ item.program,
518
+ item.temperature,
519
+ item.spin,
520
+ [...item.options].sort(),
521
+ item.fabricSoftener
522
+ ]);
523
+ }
524
+ /**
525
+ * Piles you set the machine and the iron up for identically. Every dial
526
+ * drawing on their cards would be the same drawing, so they get one card
527
+ * listing all the names.
528
+ *
529
+ * @example
530
+ * ```ts
531
+ * cardGroups(instructions).map((group) => group.map((item) => item.clothingType));
532
+ * // [["Socks", "Jeans"], ["Towels"]]
533
+ * ```
534
+ */
535
+ function cardGroups(instructions) {
536
+ return groupBy(instructions, (item) => JSON.stringify([
537
+ washFingerprint(item),
538
+ item.ironing,
539
+ item.ironSetting
540
+ ]));
541
+ }
542
+ /**
543
+ * The same, for a sheet with no iron on it. Dark, Black Socks and Denim each
544
+ * need their own card on the full chart only because they want three different
545
+ * thermostat positions; standing at the machine they are one wash.
546
+ *
547
+ * @example
548
+ * ```ts
549
+ * washGroups(instructions); // merges piles cardGroups would have split on iron settings alone
550
+ * ```
551
+ */
552
+ function washGroups(instructions) {
553
+ return groupBy(instructions, washFingerprint);
554
+ }
555
+ /**
556
+ * Piles by where the iron's thermostat points, coolest first.
557
+ *
558
+ * An ironing sheet is read the other way round from a washing one. You do not
559
+ * fetch a pile and look up its setting — you set the iron once and work through
560
+ * everything that goes at that heat, so the thermostat position is the heading
561
+ * and the piles are the list under it. `order` is `ironSettingKeys`; a pile you
562
+ * never iron has no position in it and sorts last, which is right — it is the
563
+ * pile you never pick up.
564
+ *
565
+ * @example
566
+ * ```ts
567
+ * ironGroups(instructions, ironSettingKeys(machine));
568
+ * ```
569
+ */
570
+ function ironGroups(instructions, order) {
571
+ const rank = (setting) => {
572
+ const at = order.indexOf(setting);
573
+ return at < 0 ? order.length : at;
574
+ };
575
+ return groupBy(instructions, (item) => item.ironSetting).sort((a, b) => rank(a[0].ironSetting) - rank(b[0].ironSetting));
576
+ }
577
+ export { COLUMNS, CONFIG_SCHEMA_URL, MAX_WASHER_OPTION_LENGTH, MAX_WASHER_PROGRAM_LENGTH, MAX_WASHER_SPIN_LENGTH, MAX_WASHER_TEMPERATURE_LENGTH, RowError, blockerCode, blockerLegend, canMix, cardGroups, chartFromJson, chartToJson, colourGroups, configFromJson, configToJson, durationsOf, formatTemperature, instructionsFromRows, ironGroups, ironSetting, ironSettingKeys, loadGroups, mixBlocker, mixTags, parseConfig, parseMachine, resolve, rowsFromInstructions, variants, washGroups };
24
578
 
25
579
  //# sourceMappingURL=index.mjs.map