@washy-washy/core 1.6.4 → 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.
@@ -1,373 +0,0 @@
1
- /**
2
- * The appliances a chart is drawn for, as data rather than code.
3
- *
4
- * Everything the PDFs render — dial angles, which chips exist, what a valid CSV
5
- * value is — comes from a machine file, so pointing this at a different washing
6
- * machine is editing JSON rather than editing TypeScript. The labels in that
7
- * file are copied off the fascia in whatever language it is printed in, and
8
- * nothing here ever translates them: a chart that says "Cottons" when the dial
9
- * says "Katoen" is worse than no chart, because you have to translate it back
10
- * while standing in front of the machine.
11
- */
12
- interface Washer {
13
- /** @maxLength 60 */
14
- name: string;
15
- /** @maxLength 30 */
16
- capacity: string;
17
- /** Dial labels in physical order from twelve o'clock, clockwise. Index is the angle. */
18
- programs: string[];
19
- temperatures: string[];
20
- spins: string[];
21
- options: string[];
22
- }
23
- interface IronSetting {
24
- /** @maxLength 30 */
25
- key: string;
26
- /** @maxLength 5 */
27
- dots: string;
28
- /** @maxLength 20 */
29
- label: string;
30
- /** @maxLength 60 */
31
- detail: string;
32
- steam: boolean;
33
- }
34
- interface Iron {
35
- /** @maxLength 60 */
36
- name: string;
37
- /** Thermostat positions in order, coolest first. */
38
- settings: IronSetting[];
39
- }
40
- interface Machine {
41
- washer: Washer;
42
- iron: Iron;
43
- }
44
- /** Longest a single washer.programs dial caption can be. */
45
- declare const MAX_WASHER_PROGRAM_LENGTH = 32;
46
- /**
47
- * Longest a single washer.temperatures entry can be — the reference sheet's
48
- * °C column. Raised from 12 once washy-washy-pdf#61 made room (see #36).
49
- */
50
- declare const MAX_WASHER_TEMPERATURE_LENGTH = 15;
51
- /** Longest a single washer.spins entry can be. */
52
- declare const MAX_WASHER_SPIN_LENGTH = 10;
53
- /** Longest a single washer.options chip can be. */
54
- declare const MAX_WASHER_OPTION_LENGTH = 20;
55
- /**
56
- * Checks a parsed machine file and hands back something the renderer can use.
57
- * Every failure names the field, because the fix is always an edit to that
58
- * line of JSON.
59
- *
60
- * @example
61
- * ```ts
62
- * const machine = parseMachine(JSON.parse(machineFileContents));
63
- * machine.washer.programs; // ["Off", "Cottons", "Wool", ...]
64
- * ```
65
- */
66
- declare function parseMachine(value: unknown): Machine;
67
- /**
68
- * @example
69
- * ```ts
70
- * ironSetting(machine, "2")?.label; // "••"
71
- * ironSetting(machine, "nope"); // undefined
72
- * ```
73
- */
74
- declare function ironSetting(machine: Machine, key: string): IronSetting | undefined;
75
- /**
76
- * The keys a row may write in `iron_setting`, coolest first.
77
- *
78
- * There is no key for "do not iron". That is the `ironing` column's job, and
79
- * two places to say the same thing is two places to disagree.
80
- *
81
- * @example
82
- * ```ts
83
- * ironSettingKeys(machine); // ["min", "1", "2", "3"]
84
- * ```
85
- */
86
- declare function ironSettingKeys(machine: Machine): string[];
87
- /**
88
- * `40` becomes `40°`; `cold` stays `cold`. The machine file is free to use
89
- * whatever word its display shows for the cold wash, so the degree sign is
90
- * decided by whether the value is a number rather than by a list of exceptions.
91
- *
92
- * @example
93
- * ```ts
94
- * formatTemperature("40"); // "40°"
95
- * formatTemperature("cold"); // "cold"
96
- * ```
97
- */
98
- declare function formatTemperature(value: string): string;
99
- /** Which pile a garment belongs to on colour grounds. `any` mixes with all. */
100
- declare const colourGroups: readonly ["white", "colour", "dark", "sport", "any"];
101
- type ColourGroup = (typeof colourGroups)[number];
102
- /**
103
- * Reasons two piles might not belong together even when the machine settings
104
- * agree. See `canMix` in `mixing.ts` for how each one is applied.
105
- */
106
- declare const mixTags: readonly ["lint-shedder", "lint-magnet", "dye-bleeder", "solo"];
107
- type MixTag = (typeof mixTags)[number];
108
- /**
109
- * One CSV row: everything needed to wash, iron and dry one pile of laundry.
110
- *
111
- * The machine-facing fields are plain strings rather than unions, because what
112
- * counts as valid depends on the machine file you point this at. `csv.ts`
113
- * checks each of them against that machine as it parses, so nothing downstream
114
- * has to wonder whether a programme name exists.
115
- */
116
- interface Instruction {
117
- /** @maxLength 60 */
118
- clothingType: string;
119
- /** @maxLength 200 */
120
- detergent: string;
121
- fabricSoftener: boolean;
122
- temperature: string;
123
- spin: string;
124
- /** @maxLength 12 */
125
- duration: string;
126
- program: string;
127
- options: string[];
128
- /** Whether this pile gets ironed at all. */
129
- ironing: boolean;
130
- /**
131
- * How to iron it, or why you don't. Free prose and often empty, because most
132
- * of what there is to say about a pile nobody irons is already said by
133
- * `ironing` being false.
134
- * @maxLength 400
135
- */
136
- ironingNotes: string;
137
- /** Thermostat position. Empty when `ironing` is false. */
138
- ironSetting: string;
139
- /** @maxLength 230 */
140
- drying: string;
141
- colourGroup: ColourGroup;
142
- mixTags: MixTag[];
143
- /** @maxLength 570 */
144
- notes: string;
145
- /**
146
- * Who to credit for a care instruction that isn't obvious from the garment
147
- * itself — "the label says 40°" doesn't need one, "the manufacturer says
148
- * wash these alone" might. Empty when there's nothing to cite.
149
- * @maxLength 80
150
- */
151
- referenceName: string;
152
- /**
153
- * A link backing up `referenceName`. Empty when there's nothing to cite.
154
- * @maxLength 2048
155
- */
156
- referenceLink: string;
157
- }
158
- /** An instruction plus the other piles it may share a drum with. */
159
- interface ResolvedInstruction extends Instruction {
160
- mixesWith: string[];
161
- }
162
- /**
163
- * How long a card or a load is going to tie the machine up.
164
- *
165
- * Usually one figure. Piles sharing a load agree on every setting, so they
166
- * ought to agree on this too — but the chart is data somebody types, and
167
- * printing both is more honest than picking the first one and hoping.
168
- *
169
- * @example
170
- * ```ts
171
- * durationsOf([pile, pile]); // "~2:00"
172
- * durationsOf([pile, { ...pile, duration: "~1:10" }]); // "~2:00 / ~1:10"
173
- * ```
174
- */
175
- declare function durationsOf(group: Instruction[]): string;
176
- /**
177
- * Which sheet to draw.
178
- *
179
- * `full` is the whole chart. The other two are the same chart cut where the
180
- * work is: washing happens in front of the machine on a Sunday morning, ironing
181
- * happens at a board on a Wednesday evening, and neither job wants to read past
182
- * the other's advice to find its own.
183
- */
184
- declare const variants: readonly ["full", "wash", "iron"];
185
- type Variant = (typeof variants)[number];
186
- /**
187
- * Where `configToJson` points editors at the real JSON Schema (generated
188
- * from the `Config` type — see `schema/config.schema.json` and `bun run
189
- * schema`). Unpinned to the package's `latest` npm tag rather than the
190
- * running version, matching how most `$schema` URLs work: close enough,
191
- * without needing a build-time read of this package's own `package.json`.
192
- */
193
- declare const CONFIG_SCHEMA_URL = "https://cdn.jsdelivr.net/npm/@washy-washy/core/schema/config.schema.json";
194
- /**
195
- * The washing machine and the chart that describes it, in one place. Both
196
- * halves are exactly what `parseMachine`/`instructionsFromRows` already
197
- * produce — this is a wrapper around the pair, not a third shape.
198
- */
199
- interface Config {
200
- machine: Machine;
201
- chart: Instruction[];
202
- }
203
- /**
204
- * Validates a `{ machine, chart }` object, checking the chart against the
205
- * machine it's embedded with — never a different one. Every failure names
206
- * which half is wrong, same as `parseMachine` and `instructionsFromRows` do
207
- * on their own.
208
- *
209
- * @example
210
- * ```ts
211
- * const config = parseConfig(JSON.parse(configFileContents));
212
- * config.machine.washer.name; // "Generic front loader"
213
- * config.chart[0].clothingType; // "Dark"
214
- * ```
215
- */
216
- declare function parseConfig(value: unknown): Config;
217
- /**
218
- * The reverse of `parseConfig` — what a JSON export writes out. Leads with a
219
- * `$schema` key so an editor that reads it (VS Code among them) validates
220
- * and autocompletes the file without the person editing it doing anything.
221
- * `parseConfig` ignores the key on the way back in — it never asks for
222
- * anything beyond `machine` and `chart`.
223
- *
224
- * @example
225
- * ```ts
226
- * const json = configToJson(config);
227
- * ```
228
- */
229
- declare function configToJson(config: Config): string;
230
- /**
231
- * The other half of `configToJson`. Throws the same errors `parseConfig` does.
232
- *
233
- * @example
234
- * ```ts
235
- * const config = configFromJson(configFileContents);
236
- * ```
237
- */
238
- declare function configFromJson(source: string): Config;
239
- /** Why two piles cannot share a drum. `null` means they can. */
240
- type Blocker = "solo" | "settings" | "colour" | "lint";
241
- declare const blockerLegend: Record<Blocker, string>;
242
- /** Short codes used in the compatibility matrix, so a cell stays one glyph. */
243
- declare const blockerCode: Record<Blocker, string>;
244
- /**
245
- * Decides whether two piles can go in the drum together, and if not, why.
246
- *
247
- * The order matters: the reason reported is the one you would want to hear
248
- * first. "Wash it alone" beats "the spin speed differs", because changing the
249
- * spin speed would not help.
250
- *
251
- * @example
252
- * ```ts
253
- * mixBlocker(towels, socks); // "lint" — towels shed onto everything else
254
- * mixBlocker(socks, socks2); // null — nothing stops them sharing a drum
255
- * ```
256
- */
257
- declare function mixBlocker(a: Instruction, b: Instruction): Blocker | null;
258
- /**
259
- * @example
260
- * ```ts
261
- * canMix(towels, socks); // false
262
- * ```
263
- */
264
- declare function canMix(a: Instruction, b: Instruction): boolean;
265
- /**
266
- * Annotates each instruction with the other piles it may share a load with.
267
- *
268
- * @example
269
- * ```ts
270
- * resolve(instructions)[0].mixesWith; // ["Socks", "Jeans"]
271
- * ```
272
- */
273
- declare function resolve(instructions: Instruction[]): ResolvedInstruction[];
274
- /**
275
- * Groups piles that can all be washed together — every member compatible with
276
- * every other, not merely with the first one it met.
277
- *
278
- * @example
279
- * ```ts
280
- * loadGroups(instructions); // [[towels], [socks, jeans], [wool]]
281
- * ```
282
- */
283
- declare function loadGroups<T extends Instruction>(instructions: T[]): T[][];
284
- /**
285
- * Piles you set the machine and the iron up for identically. Every dial
286
- * drawing on their cards would be the same drawing, so they get one card
287
- * listing all the names.
288
- *
289
- * @example
290
- * ```ts
291
- * cardGroups(instructions).map((group) => group.map((item) => item.clothingType));
292
- * // [["Socks", "Jeans"], ["Towels"]]
293
- * ```
294
- */
295
- declare function cardGroups<T extends Instruction>(instructions: T[]): T[][];
296
- /**
297
- * The same, for a sheet with no iron on it. Dark, Black Socks and Denim each
298
- * need their own card on the full chart only because they want three different
299
- * thermostat positions; standing at the machine they are one wash.
300
- *
301
- * @example
302
- * ```ts
303
- * washGroups(instructions); // merges piles cardGroups would have split on iron settings alone
304
- * ```
305
- */
306
- declare function washGroups<T extends Instruction>(instructions: T[]): T[][];
307
- /**
308
- * Piles by where the iron's thermostat points, coolest first.
309
- *
310
- * An ironing sheet is read the other way round from a washing one. You do not
311
- * fetch a pile and look up its setting — you set the iron once and work through
312
- * everything that goes at that heat, so the thermostat position is the heading
313
- * and the piles are the list under it. `order` is `ironSettingKeys`; a pile you
314
- * never iron has no position in it and sorts last, which is right — it is the
315
- * pile you never pick up.
316
- *
317
- * @example
318
- * ```ts
319
- * ironGroups(instructions, ironSettingKeys(machine));
320
- * ```
321
- */
322
- declare function ironGroups<T extends Instruction>(instructions: T[], order: readonly string[]): T[][];
323
- declare const COLUMNS: readonly ["clothing_type", "detergent", "fabric_softener", "temperature", "spin", "duration", "program", "options", "ironing", "ironing_notes", "iron_setting", "drying", "colour_group", "mix_tags", "notes", "reference_name", "reference_link"];
324
- /** One row, keyed the same way as a CSV column and the chart's JSON Schema. */
325
- type Row = Record<(typeof COLUMNS)[number], string>;
326
- declare class RowError extends Error {
327
- constructor(row: number, column: string, message: string);
328
- }
329
- /**
330
- * Checks rows shaped like the chart's schema — the same shape a CSV parses
331
- * into, or a JSON file round-tripped through `rowsFromInstructions` — against
332
- * what the appliances in the machine file can actually be set to. A typo in a
333
- * programme name fails here rather than producing a PDF that tells you to turn
334
- * the dial to a position that does not exist — and so does a chart written for
335
- * a different machine than the one you passed.
336
- *
337
- * @example
338
- * ```ts
339
- * const instructions = instructionsFromRows(JSON.parse(jsonFromStorage), machine);
340
- * ```
341
- */
342
- declare function instructionsFromRows(rows: Record<string, string>[], machine: Machine): Instruction[];
343
- /**
344
- * The reverse of `instructionsFromRows` — what a JSON export writes out.
345
- *
346
- * @example
347
- * ```ts
348
- * const rows = rowsFromInstructions(instructions);
349
- * ```
350
- */
351
- declare function rowsFromInstructions(instructions: Instruction[]): Row[];
352
- /**
353
- * The JSON interchange format for a chart — the same row shape
354
- * a chart's JSON Schema describes, so a file written here validates against
355
- * it exactly as a CSV does.
356
- *
357
- * @example
358
- * ```ts
359
- * const json = chartToJson(instructions);
360
- * ```
361
- */
362
- declare function chartToJson(instructions: Instruction[]): string;
363
- /**
364
- * The other half of `chartToJson`. Throws the same errors `parseInstructions` does.
365
- *
366
- * @example
367
- * ```ts
368
- * const instructions = chartFromJson(jsonFromStorage, machine);
369
- * ```
370
- */
371
- declare function chartFromJson(source: string, machine: Machine): Instruction[];
372
- export { mixTags as A, formatTemperature as B, ColourGroup as C, Variant as D, ResolvedInstruction as E, MAX_WASHER_PROGRAM_LENGTH as F, ironSettingKeys as H, MAX_WASHER_SPIN_LENGTH as I, MAX_WASHER_TEMPERATURE_LENGTH as L, Iron as M, IronSetting as N, colourGroups as O, MAX_WASHER_OPTION_LENGTH as P, Machine as R, parseConfig as S, MixTag as T, parseMachine as U, ironSetting as V, washGroups as _, chartToJson as a, configFromJson as b, Blocker as c, canMix as d, cardGroups as f, resolve as g, mixBlocker as h, chartFromJson as i, variants as j, durationsOf as k, blockerCode as l, loadGroups as m, Row as n, instructionsFromRows as o, ironGroups as p, RowError as r, rowsFromInstructions as s, COLUMNS as t, blockerLegend as u, CONFIG_SCHEMA_URL as v, Instruction as w, configToJson as x, Config as y, Washer as z };
373
- //# sourceMappingURL=rows-BrgThiZI.d.mts.map