@mark1russell7/stack-needs 0.6.0 → 0.8.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/README.md CHANGED
@@ -15,7 +15,7 @@ Each function is a plain function with no clock, no network and no file.
15
15
  | `CalorieRow` | A sex, a range of ages in months, and the need of each activity level, or one need for all levels. |
16
16
  | `CalorieChange` | A stage (for example `pregnancy-2`), a sex, and the change of the daily need at that stage, with the condition of the source. |
17
17
  | `Person` | A group of persons: a sex, an age in whole months, a count and, as options, an activity level and a stage. |
18
- | `HouseholdFragment` | A fragment of an endurance layer: the resources, the stores, one draw and one direct use. It has the form of `EnduranceLayer`. |
18
+ | `HouseholdFragment` | A fragment of an endurance layer: the resources, the stores, the draws and their direct uses. It has the form of `EnduranceLayer`. |
19
19
 
20
20
  ## The rules of the data
21
21
 
@@ -64,12 +64,14 @@ console.log(enduranceOf(food.layer, cut, { at: "2026-11-22" }).needs["food.energ
64
64
 
65
65
  `householdFragment` turns the persons and a buy list into a fragment of an endurance layer. The buy list is the count of units of each product of the catalog of supplies of `@mark1russell7/market`.
66
66
 
67
- - The fragment has one draw `food.energy`. Its rate is the need of the persons for one day, in `kcal`. Its users are the persons.
67
+ - The draw `food.energy` has the need of the persons for one day, in `kcal`. Its users are the persons.
68
+ - The draw `food.infant-formula` has the infants on formula below 6 months (`FORMULA_DRAW_MONTHS`), with the whole need of their rows.
69
+ - The fragment has each draw with one or more users. The draw `food.energy` is first.
68
70
  - Each gift of the buy list (`giftsOf`) is one store. Examples are `food.no-cook` in `kcal`, the dry foods in `kg` and `water.stored` in `L`.
69
71
  - A gift with no read has no store. It is in `noReads`, and `storesRead` is false. The draw does not change.
70
- - The direct uses are the food uses of `uses`: each use for the need `food.energy`. The default `DIRECT_USES` gives `food.no-cook`, 1 kcal for each kcal.
71
- - The resources are the resources of the stores and of the food uses. The resource of each food use is in `kcal` in the catalog, or the function throws a `RangeError`.
72
- - The supply part of the draw is `supply`. Its default is the part of `NEED_SUPPLIES` for `food.energy`: `food.retail`.
72
+ - The direct uses are each use of `uses` for the need of a draw. The default `DIRECT_USES` gives `food.no-cook` to the food draw and `food.infant-formula-ready` to the formula draw, 1 kcal for each kcal.
73
+ - The resources are the resources of the stores and of the direct uses. The resource of each direct use is in `kcal` in the catalog, or the function throws a `RangeError`.
74
+ - The supply part of each draw is `supply`. Its default is the part of `NEED_SUPPLIES` for the need of the draw: `food.retail`.
73
75
  - The result also has the food energy of each product (`buyListEnergy`). A caller gets the energy of the dry food for its converters from it.
74
76
 
75
77
  The result has two reads. `needRead` tells if the draw has a read, and `storesRead` tells if each gift of the buy list has a read.
@@ -84,11 +86,34 @@ The days are then an upper limit for the whole household.
84
86
 
85
87
  ### An infant
86
88
 
87
- The infant table gives the need of an infant below 12 months. The fragment adds that need to the one draw of food energy.
89
+ The infant table gives the need of an infant below 12 months (`INFANT_MONTHS`). Each person record below 12 months must have the field `feeding`. It has no default, because each way gives a different draw.
88
90
 
89
- This has a limit. The fragment cannot tell formula from other food. Thus, when the buy list does not hold the formula of those days, the days are too high for the infant. The field `table` of each line lets a planner find the lines of the infant table.
91
+ | `feeding` | The draw of food energy |
92
+ | --- | --- |
93
+ | `food` | The draw holds the need of the infant, from the infant table. |
94
+ | `breast-milk` | Only below 6 months (`BREAST_MILK_MONTHS`). The draw does not hold the need of the infant. The milk comes from the food of the mother, so the stage of lactation of the mother holds that energy. The result lists the infant in `breastMilk`. |
95
+ | `formula` | Only below 12 months. Below 6 months (`FORMULA_DRAW_MONTHS`), the draw `food.infant-formula` holds the whole need of the infant, because the infant has milk only. Only the formula of the buy list feeds it, so a list with no formula gives 0 days. From 6 months, no cited source gives the part of formula. Thus the infant gives no layer, as a person with no row. With `noRow: "leave-out"`, no draw has the need of the infant, and `leftOut` lists the infant. The result lists each infant on formula in `formula`. |
96
+
97
+ With the default tables, the line of each infant in `need` has a read, so `need` gives the energy of the whole household.
98
+
99
+ The rules of breast milk:
100
+
101
+ - A person of the household must have a stage of lactation, or the function gives a `RangeError`.
102
+ - The change of a stage is the milk of one infant. Thus each infant on breast milk needs one person of the draw with a stage of lactation. When the infants are more, the function gives no layer, also with `leave-out`. A person that the draw leaves out does not count.
103
+ - From 6 months, the infant table gives 604 to 745 kcal/d, and the change of the stage is 400 kcal/d. Thus a part of the need is in no draw, and the function gives a `RangeError`. Give `food` from 6 months.
104
+
105
+ The notes b and c of Table A2-3 of the guidelines (page 141) give the two changes of lactation:
106
+
107
+ | Stage | The note of the source | The change |
108
+ | --- | --- | --- |
109
+ | `lactation-1` | 500 calories/day for the milk production, minus 170 calories/day for the weight loss after the birth. | 330 kcal/d |
110
+ | `lactation-2` | 400 calories/day for the milk production. The source assumes a stable weight after 6 months. | 400 kcal/d |
111
+
112
+ Thus below 6 months, a part of the milk comes from the stores of the mother. The draw holds only the part from food.
113
+ The source gives the energy of the milk production, not the energy that the infant gets. It gives no change for two or more infants.
114
+ Thus the package does not give the milk part of an infant from 6 months, and it does not give a change for twins. Each is a no read until a source gives it.
90
115
 
91
- The milk of a mother comes from the food of the mother. Thus, for an infant that drinks only that milk, give the mother the stage `lactation-1`. Then leave the infant out of the persons. If the persons hold the infant too, the draw counts that energy two times. The result is then more food than the household needs, which is on the safe side. After 6 months, an infant eats food and drinks milk. The stage `lactation-2` of the mother and the need of the infant then count a part of the energy two times.
116
+ A stage of lactation is a change with `milk: true`: `lactation-1` and `lactation-2` of the guidelines. From 6 months, an infant eats food and drinks milk. With `feeding: "food"` and the stage `lactation-2` of the mother, the draw counts a part of that energy two times. The result is then more food than the household needs, which is on the safe side.
92
117
 
93
118
  ### The resources of the buy list and the join
94
119
 
@@ -104,8 +129,8 @@ The package holds one record of each use and of each default supply part. `house
104
129
 
105
130
  | Name | What it has |
106
131
  | --- | --- |
107
- | `NEED_SUPPLIES` | The default reference part of each need: `hydration.drink` to `water.main`, and `food.energy` to `food.retail`. A household with a well gives a different part. |
108
- | `DIRECT_USES` | `water.stored` gives `hydration.drink`, 1 L for each L. This is a definition, not a read. `food.no-cook` gives `food.energy`, 1 kcal for each kcal. |
132
+ | `NEED_SUPPLIES` | The default reference part of each need: `hydration.drink` to `water.main`, and `food.energy` and `food.infant-formula` to `food.retail`. A household with a well gives a different part. |
133
+ | `DIRECT_USES` | `water.stored` gives `hydration.drink`, 1 L for each L. This is a definition, not a read. `food.no-cook` gives `food.energy`, and `food.infant-formula-ready` gives `food.infant-formula`, 1 kcal for each kcal. |
109
134
  | `checkJoins` | The join gate of a catalog, the direct uses and the supply parts with the reference lists. |
110
135
 
111
136
  `checkJoins(catalog, uses, supplies, { needs, parts })` gives one finding for each break. An empty list is a pass. Each finding is an error.
package/build/index.d.ts CHANGED
@@ -46,6 +46,8 @@ export interface CalorieChange {
46
46
  readonly change: Quantity;
47
47
  /** The condition of the source for the change, for example a healthy weight before the pregnancy. */
48
48
  readonly condition?: string | undefined;
49
+ /** True when the persons of the stage make the milk of an infant: a stage of lactation. */
50
+ readonly milk?: true | undefined;
49
51
  }
50
52
  /** A table of estimated calorie needs from one source. */
51
53
  export interface CalorieTable {
@@ -65,6 +67,16 @@ export interface CalorieTable {
65
67
  * An example is `CALORIE_CHAIN`: the guidelines from 12 months, and the infant table below 12 months.
66
68
  */
67
69
  export type CalorieTables = CalorieTable | readonly CalorieTable[];
70
+ /**
71
+ * The ways to feed an infant.
72
+ *
73
+ * - `breast-milk`: only the milk of a person of the household.
74
+ * - `formula`: infant formula.
75
+ * - `food`: the food of the household, also with milk.
76
+ */
77
+ export declare const INFANT_FEEDINGS: readonly ["breast-milk", "formula", "food"];
78
+ /** A way to feed an infant. */
79
+ export type InfantFeeding = (typeof INFANT_FEEDINGS)[number];
68
80
  /** A group of persons of the same sex and age, and their count. */
69
81
  export interface Person {
70
82
  readonly sex: CalorieSex;
@@ -75,6 +87,11 @@ export interface Person {
75
87
  readonly level?: ActivityLevel | undefined;
76
88
  /** The stage of the persons, for example `pregnancy-2`: the stage of a change of the table. Without it, no change applies. */
77
89
  readonly stage?: string | undefined;
90
+ /**
91
+ * The way to feed the persons. The household fragment must have it for each record below `INFANT_MONTHS`.
92
+ * `calorieNeed` does not read it, because the energy need is the same.
93
+ */
94
+ readonly feeding?: InfantFeeding | undefined;
78
95
  }
79
96
  /** The need of one person record for the days, or no read when the table has no row for the age. */
80
97
  export type CalorieNeedLine = {
@@ -226,10 +243,17 @@ export declare function checkCalorieChain(tables: CalorieTables, options?: GateO
226
243
  export declare function hasNeedsError(findings: readonly NeedsFinding[]): boolean;
227
244
  /** The code of the need of the food draw: food energy, in `kcal` for each day. */
228
245
  export declare const FOOD_NEED = "food.energy";
246
+ /**
247
+ * The code of the need of the infants on formula below `FORMULA_DRAW_MONTHS`, in `kcal` for each day.
248
+ * It is a need of its own. Thus the food of the adults does not feed the infants, and the formula does not feed the adults.
249
+ */
250
+ export declare const FORMULA_NEED = "food.infant-formula";
229
251
  /** The code of the need of drinking water, in `L` for each day. */
230
252
  export declare const WATER_NEED = "hydration.drink";
231
253
  /** The resource of the food to eat with no water and no fuel, in `kcal`. It has a direct use for the food draw. */
232
254
  export declare const NO_COOK = "food.no-cook";
255
+ /** The resource of the ready-to-feed infant formula, in `kcal`. It has a direct use for the formula need. It needs no water and no fuel. */
256
+ export declare const FORMULA_READY = "food.infant-formula-ready";
233
257
  /** The resource of the stored drinking water, in `L`. It has a direct use for the water need. */
234
258
  export declare const STORED_WATER = "water.stored";
235
259
  /** The direct use of a resource for a need: 1 unit of the resource gives `amount` of the need. */
@@ -246,12 +270,14 @@ export interface FragmentDirectUse {
246
270
  export declare const NEED_SUPPLIES: {
247
271
  readonly "hydration.drink": "water.main";
248
272
  readonly "food.energy": "food.retail";
273
+ readonly "food.infant-formula": "food.retail";
249
274
  };
250
275
  /**
251
276
  * The direct uses of the resources of the buy list. Each use gives 1 unit of its need for each unit of its resource.
252
277
  *
253
278
  * - 1 L of stored drinking water gives 1 L of drink. This is a definition, not a read.
254
279
  * - 1 kcal of food to eat with no water and no fuel gives 1 kcal of food energy.
280
+ * - 1 kcal of ready-to-feed infant formula gives 1 kcal of the formula need.
255
281
  *
256
282
  * These records have the form of `DirectUse` of `@mark1russell7/stack-endurance`.
257
283
  */
@@ -318,11 +344,11 @@ export interface FragmentStore {
318
344
  readonly resource: string;
319
345
  readonly amount: number;
320
346
  }
321
- /** The food draw: the food energy of the persons of the draw for each day. */
347
+ /** A draw: the food energy or the formula of the persons of the draw for each day. */
322
348
  export interface FragmentDraw {
323
349
  readonly need: string;
324
350
  readonly level: string;
325
- /** The food energy of the persons of the draw for each day, in `kcal`. It is above 0. */
351
+ /** The energy of the persons of the draw for each day, in `kcal`. It is above 0. */
326
352
  readonly perDay: number;
327
353
  /** The count of the persons of the draw. */
328
354
  readonly users: number;
@@ -338,7 +364,19 @@ export interface HouseholdFragment {
338
364
  readonly draws: readonly FragmentDraw[];
339
365
  readonly direct: readonly FragmentDirectUse[];
340
366
  }
341
- /** The action for the persons with no row in the table. The only action is `leave-out`. */
367
+ /** The age in months below which a person record must have a `feeding`: 12, the first month of the guidelines. */
368
+ export declare const INFANT_MONTHS = 12;
369
+ /**
370
+ * The age in months from which an infant cannot have `feeding: "breast-milk"`: 6.
371
+ * From 6 months, the infant table gives more than the change of a stage of lactation, so a part of the need is in no draw. Give `food` from this age.
372
+ */
373
+ export declare const BREAST_MILK_MONTHS = 6;
374
+ /**
375
+ * The age in months below which an infant on formula is in the formula draw with the whole need of its row: 6.
376
+ * Below this age, an infant has milk only, as for `BREAST_MILK_MONTHS`. From this age, no cited source gives the part of formula.
377
+ */
378
+ export declare const FORMULA_DRAW_MONTHS = 6;
379
+ /** The action for the persons that no draw can serve: no row in the table, or an infant on formula from `FORMULA_DRAW_MONTHS`. The only action is `leave-out`. */
342
380
  export type NoRowAction = "leave-out";
343
381
  /** The inputs of the household fragment. */
344
382
  export interface HouseholdFragmentInput {
@@ -350,11 +388,11 @@ export interface HouseholdFragmentInput {
350
388
  readonly catalog: SupplyCatalog;
351
389
  /** The count of units of each product of the buy list, by the `id` of the product. */
352
390
  readonly units: Readonly<Record<string, number>>;
353
- /** The `id` of the part of the stack that supplies the food when no case stops it. The default is `NEED_SUPPLIES["food.energy"]`, `food.retail`. */
391
+ /** The `id` of the part of the stack that supplies the food and the formula when no case stops it. The default is `food.retail`, from `NEED_SUPPLIES`. */
354
392
  readonly supply?: string | undefined;
355
- /** The direct uses. The fragment takes each use for the need `food.energy`. The default is `DIRECT_USES`. */
393
+ /** The direct uses. The fragment takes each use for the need of one of its draws. The default is `DIRECT_USES`. */
356
394
  readonly uses?: readonly FragmentDirectUse[] | undefined;
357
- /** The level of the food draw. It is one of the levels of the joined layer. */
395
+ /** The level of the draws. It is one of the levels of the joined layer. */
358
396
  readonly level: string;
359
397
  /** The levels of the fragment. The default is no levels: a different fragment of the stack gives them. */
360
398
  readonly levels?: readonly string[] | undefined;
@@ -363,7 +401,7 @@ export interface HouseholdFragmentInput {
363
401
  /** The start of the `id` of each store. The default is `buy`. */
364
402
  readonly prefix?: string | undefined;
365
403
  /**
366
- * The action for the persons with no row in the table. Without it, a person with no row gives no layer.
404
+ * The action for the persons with no row in the table, and for the infants on formula from `FORMULA_DRAW_MONTHS`. Without it, such a person gives no layer.
367
405
  * With `leave-out`, the draw has no need of those persons, and the result lists them.
368
406
  */
369
407
  readonly noRow?: NoRowAction | undefined;
@@ -394,8 +432,21 @@ export interface HouseholdFragmentRead extends HouseholdStoresResult {
394
432
  readonly need: CalorieNeedTotal;
395
433
  /** This field is true: the draw has a read for each of its users. */
396
434
  readonly needRead: true;
397
- /** The persons with no row that the option `leave-out` left out of the draw. With no option, the list is empty. */
435
+ /**
436
+ * The persons with no row, and the infants on formula from `FORMULA_DRAW_MONTHS`, that the option `leave-out` left out of the draws.
437
+ * With no option, the list is empty.
438
+ */
398
439
  readonly leftOut: readonly Person[];
440
+ /**
441
+ * The infants on formula. Each infant below `FORMULA_DRAW_MONTHS` is in the formula draw. The option `leave-out` left the other
442
+ * infants out, so `leftOut` also lists them.
443
+ */
444
+ readonly formula: readonly Person[];
445
+ /**
446
+ * The infants on breast milk only. Each has a line with a read in `need`, and no part of the draw.
447
+ * The stage of lactation of a person of the draw holds that energy.
448
+ */
449
+ readonly breastMilk: readonly Person[];
399
450
  }
400
451
  /** No household fragment: the draw has no read. A low rate gives too many days, so the function gives no layer. */
401
452
  export interface HouseholdFragmentNoRead extends HouseholdStoresResult {
@@ -405,6 +456,10 @@ export interface HouseholdFragmentNoRead extends HouseholdStoresResult {
405
456
  readonly needRead: false;
406
457
  /** The persons with no row in the table. */
407
458
  readonly noRow: readonly Person[];
459
+ /** The infants on formula. */
460
+ readonly formula: readonly Person[];
461
+ /** The infants on breast milk only. */
462
+ readonly breastMilk: readonly Person[];
408
463
  /** The reason for no layer. */
409
464
  readonly why: string;
410
465
  }
@@ -413,21 +468,38 @@ export type HouseholdFragmentResult = HouseholdFragmentRead | HouseholdFragmentN
413
468
  /**
414
469
  * This function joins a household and a buy list into a fragment of an endurance layer.
415
470
  *
416
- * - The fragment has one draw of food energy. Its rate is the need of the persons for one day, and its users are the persons.
471
+ * - The draw of food energy has the rate of the need of its persons for one day, and its users are the persons.
472
+ * - The draw of formula has the infants on formula below `FORMULA_DRAW_MONTHS`, with the whole need of their rows.
473
+ * - The fragment has each draw with one or more users. The draw of food energy is first.
417
474
  * - Each gift of the buy list with a read is one store, with the `id` `<prefix>:<product>:<resource>`. A gift with no read has no store.
418
- * - The direct uses are the food uses: each use of `uses` for the need `food.energy`. The default `DIRECT_USES` gives `food.no-cook`, 1 kcal for each kcal.
419
- * - The resources are the resources of the stores and of the food uses, with the units of the catalog.
420
- * - The supply part of the draw is `supply`. Its default is the part of `NEED_SUPPLIES` for `food.energy`.
475
+ * - The direct uses are each use of `uses` for the need of a draw. The default `DIRECT_USES` gives 1 kcal for each kcal.
476
+ * `food.no-cook` feeds the food draw, and `food.infant-formula-ready` feeds the formula draw.
477
+ * - The resources are the resources of the stores and of the direct uses, with the units of the catalog.
478
+ * - The supply part of each draw is `supply`. Its default is the part of `NEED_SUPPLIES` for the need of the draw.
421
479
  * - The fragment has no converter. A caller adds converters for the dry food, with the water and the fuel of each run.
422
480
  *
423
481
  * A person with no row in the tables gives no layer, because a low rate gives too many days. The default tables give a row for each age.
424
482
  * The option `noRow: "leave-out"` leaves those persons out of the draw. A draw of 0 kcal gives no layer.
483
+ *
484
+ * Each person record below `INFANT_MONTHS` must have a `feeding`. It has no default.
485
+ *
486
+ * - `food`: the need of the infant is in the draw of food energy.
487
+ * - `breast-milk`: the infant has a line, and no part of the draw. It is only for an infant below `BREAST_MILK_MONTHS`.
488
+ * A person of the household must have a stage of lactation. Each infant on breast milk needs one person of the draw with a stage of lactation.
489
+ * When the infants are more, the function gives no layer: the change of a stage is the milk of one infant.
490
+ * - `formula`: below `FORMULA_DRAW_MONTHS`, the whole need of the infant is in the draw of formula, because the infant has milk only.
491
+ * From `FORMULA_DRAW_MONTHS`, no cited source gives the part of formula, so the infant gives no layer, as a person with no row.
492
+ * The option `leave-out` also applies. The feeding is only for an infant below `INFANT_MONTHS`.
493
+ *
425
494
  * The function is pure.
426
495
  *
427
496
  * @param input - The persons, the activity level, the catalog and the buy list, the supply part and the level of the draw
428
497
  * @returns The fragment or a no read of the draw, with the energy of the list and the gifts with no read
429
498
  * @throws RangeError for the errors of `calorieNeed`, `giftsOf` and `buyListEnergy`, except a household with no person
430
- * @throws RangeError when the catalog has no resource in `kcal` for a food use
499
+ * @throws RangeError when the catalog has no resource in `kcal` for the direct use of a draw
500
+ * @throws RangeError when a record below `INFANT_MONTHS` has no `feeding`, or when a `feeding` is not a way of `INFANT_FEEDINGS`
501
+ * @throws RangeError for `breast-milk` from `BREAST_MILK_MONTHS`, and for `formula` from `INFANT_MONTHS`
502
+ * @throws RangeError when an infant drinks only breast milk and no person of the household has a stage of lactation
431
503
  */
432
504
  export declare function householdFragment(input: HouseholdFragmentInput): HouseholdFragmentResult;
433
505
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"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;wBA8BjE,cAAc,mBAAmB;;qBCzJpC;;qBAGA;;qBAGA;;qBAGA;;iBAGI;WACN;WACA;WACA;;;;;;;qBAQE;WAA0B;WAA0C;;;;;;;;;;qBAapE,sBAAsB;;;;;;;;;;;qBAetB;;YAUD,mBAAmB;;;;;YAMnB,cAAc,QAAQ;;iBAajB;WACN;WACA;;;iBAIM;WACN;;;iBAIM;;WAEN,gBAAgB;;WAEhB,gBAAgB;;;;;;;;;;;;;;;;;;wBAmBX,WACd,SAAS,eACT,eAAe,qBACf,UAAU,SAAS,yBACnB,YAAY,iBACX;;iBCpHc;WACN;WACA;;;iBAIM;WACN;WACA;WACA;;;iBAIM;WACN;WACA;;WAEA;;WAEA;WACA;;;iBAIM;;WAEN;WACA;WACA,oBAAoB;WACpB,iBAAiB;WACjB,gBAAgB;WAChB,iBAAiB;;;YAIhB;;iBAGK;;WAEN,kBAAkB;;WAElB,UAAU;;WAEV,SAAS;;WAET,OAAO,SAAS;;WAEhB;;WAEA,gBAAgB;;WAEhB;;WAEA;;WAEA,QAAQ;;WAER;;;;;WAKA,QAAQ;;;iBAIF;WACN;WACA;WACA;;;iBAIM;;WAEN,QAAQ;;WAER,kBAAkB;;WAElB;;;iBAIM,8BAA8B;WACpC,OAAO;;;;;;WAMP,MAAM;;WAEN;;WAEA,kBAAkB;;;iBAIZ,gCAAgC;WACtC;;WAEA,MAAM;WACN;;WAEA,gBAAgB;;WAEhB;;;YAIC,0BAA0B,wBAAwB;;;;;;;;;;;;;;;;;;;;wBA8C9C,kBAAkB,OAAO,yBAAyB"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/calorie.ts","../src/data.ts","../src/check.ts","../src/uses.ts","../src/household.ts"],"mappings":";;;;qBAQa;;YAGD,wBAAwB;;qBAGvB;;YAGD,qBAAqB;;;;;YAMrB;WAAyB,QAAQ,SAAS,OAAO,eAAe;WAAqB;;WAA4B,MAAM;WAAmB;;;iBAGrI;WACN,KAAK;;WAEL;;WAEA;;WAE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;;;;;qBAgBtB;;YAUD,mBAAmB;;;;;YAMnB,cAAc,QAAQ;;iBAajB;WACN;WACA;;;iBAIM;WACN;;;iBAIM;;WAEN,gBAAgB;;WAEhB,gBAAgB;;;;;;;;;;;;;;;;;;wBAmBX,WACd,SAAS,eACT,eAAe,qBACf,UAAU,SAAS,yBACnB,YAAY,iBACX;;iBC9Hc;WACN;WACA;;;iBAIM;WACN;WACA;WACA;;;iBAIM;WACN;WACA;;WAEA;;WAEA;WACA;;;iBAIM;;WAEN;WACA;WACA,oBAAoB;WACpB,iBAAiB;WACjB,gBAAgB;WAChB,iBAAiB;;;qBAIf;;;;;qBAMA;;;;;qBAMA;;YAGD;;iBAGK;;WAEN,kBAAkB;;WAElB,UAAU;;WAEV,SAAS;;WAET,OAAO,SAAS;;WAEhB;;WAEA,gBAAgB;;WAEhB;;WAEA;;WAEA,QAAQ;;WAER;;;;;WAKA,QAAQ;;;iBAIF;WACN;WACA;WACA;;;iBAIM;;WAEN,QAAQ;;WAER,kBAAkB;;WAElB;;;iBAIM,8BAA8B;WACpC,OAAO;;;;;;WAMP,MAAM;;WAEN;;;;;WAKA,kBAAkB;;;;;WAKlB,kBAAkB;;;;;WAKlB,qBAAqB;;;iBAIf,gCAAgC;WACtC;;WAEA,MAAM;WACN;;WAEA,gBAAgB;;WAEhB,kBAAkB;;WAElB,qBAAqB;;WAErB;;;YAIC,0BAA0B,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAoE9C,kBAAkB,OAAO,yBAAyB"}
package/build/index.js CHANGED
@@ -10,6 +10,18 @@ const ACTIVITY_LEVELS = [
10
10
  ];
11
11
  /** The sexes of the table. */
12
12
  const CALORIE_SEXES = ["female", "male"];
13
+ /**
14
+ * The ways to feed an infant.
15
+ *
16
+ * - `breast-milk`: only the milk of a person of the household.
17
+ * - `formula`: infant formula.
18
+ * - `food`: the food of the household, also with milk.
19
+ */
20
+ const INFANT_FEEDINGS = [
21
+ "breast-milk",
22
+ "formula",
23
+ "food"
24
+ ];
13
25
  /** The unit of each food energy. */
14
26
  const ENERGY_UNIT = "kcal";
15
27
  /** The unit of each daily need. */
@@ -163,6 +175,10 @@ const change = (stage, title, value) => ({
163
175
  change: day(value),
164
176
  condition: HEALTHY
165
177
  });
178
+ const milk = (stage, title, value) => ({
179
+ ...change(stage, title, value),
180
+ milk: true
181
+ });
166
182
  /** The table of estimated calorie needs of the Dietary Guidelines for Americans, 2020-2025: 68 rows, 34 for each sex, and 5 changes of pregnancy and lactation. */
167
183
  const DGA_CALORIES = {
168
184
  id: "dga.2020-2025:calorie-needs",
@@ -173,8 +189,8 @@ const DGA_CALORIES = {
173
189
  change("pregnancy-1", "Pregnancy: 1st trimester", 0),
174
190
  change("pregnancy-2", "Pregnancy: 2nd trimester", 340),
175
191
  change("pregnancy-3", "Pregnancy: 3rd trimester", 452),
176
- change("lactation-1", "Lactation: 1st 6 months", 330),
177
- change("lactation-2", "Lactation: 2nd 6 months", 400)
192
+ milk("lactation-1", "Lactation: 1st 6 months", 330),
193
+ milk("lactation-2", "Lactation: 2nd 6 months", 400)
178
194
  ],
179
195
  rows: [
180
196
  {
@@ -1011,10 +1027,17 @@ function hasNeedsError(findings) {
1011
1027
  // src/uses.ts
1012
1028
  /** The code of the need of the food draw: food energy, in `kcal` for each day. */
1013
1029
  const FOOD_NEED = "food.energy";
1030
+ /**
1031
+ * The code of the need of the infants on formula below `FORMULA_DRAW_MONTHS`, in `kcal` for each day.
1032
+ * It is a need of its own. Thus the food of the adults does not feed the infants, and the formula does not feed the adults.
1033
+ */
1034
+ const FORMULA_NEED = "food.infant-formula";
1014
1035
  /** The code of the need of drinking water, in `L` for each day. */
1015
1036
  const WATER_NEED = "hydration.drink";
1016
1037
  /** The resource of the food to eat with no water and no fuel, in `kcal`. It has a direct use for the food draw. */
1017
1038
  const NO_COOK = "food.no-cook";
1039
+ /** The resource of the ready-to-feed infant formula, in `kcal`. It has a direct use for the formula need. It needs no water and no fuel. */
1040
+ const FORMULA_READY = "food.infant-formula-ready";
1018
1041
  /** The resource of the stored drinking water, in `L`. It has a direct use for the water need. */
1019
1042
  const STORED_WATER = "water.stored";
1020
1043
  /**
@@ -1024,25 +1047,35 @@ const STORED_WATER = "water.stored";
1024
1047
  */
1025
1048
  const NEED_SUPPLIES = {
1026
1049
  "hydration.drink": "water.main",
1027
- "food.energy": "food.retail"
1050
+ "food.energy": "food.retail",
1051
+ "food.infant-formula": "food.retail"
1028
1052
  };
1029
1053
  /**
1030
1054
  * The direct uses of the resources of the buy list. Each use gives 1 unit of its need for each unit of its resource.
1031
1055
  *
1032
1056
  * - 1 L of stored drinking water gives 1 L of drink. This is a definition, not a read.
1033
1057
  * - 1 kcal of food to eat with no water and no fuel gives 1 kcal of food energy.
1058
+ * - 1 kcal of ready-to-feed infant formula gives 1 kcal of the formula need.
1034
1059
  *
1035
1060
  * These records have the form of `DirectUse` of `@mark1russell7/stack-endurance`.
1036
1061
  */
1037
- const DIRECT_USES = [{
1038
- resource: STORED_WATER,
1039
- need: WATER_NEED,
1040
- amount: 1
1041
- }, {
1042
- resource: NO_COOK,
1043
- need: FOOD_NEED,
1044
- amount: 1
1045
- }];
1062
+ const DIRECT_USES = [
1063
+ {
1064
+ resource: STORED_WATER,
1065
+ need: WATER_NEED,
1066
+ amount: 1
1067
+ },
1068
+ {
1069
+ resource: NO_COOK,
1070
+ need: FOOD_NEED,
1071
+ amount: 1
1072
+ },
1073
+ {
1074
+ resource: FORMULA_READY,
1075
+ need: FORMULA_NEED,
1076
+ amount: 1
1077
+ }
1078
+ ];
1046
1079
  /**
1047
1080
  * These are the codes of the join gate. Each code is an error.
1048
1081
  *
@@ -1120,12 +1153,22 @@ function checkJoins(catalog, uses, supplies, references) {
1120
1153
  return findings;
1121
1154
  }
1122
1155
  // src/household.ts
1156
+ /** The age in months below which a person record must have a `feeding`: 12, the first month of the guidelines. */
1157
+ const INFANT_MONTHS = 12;
1158
+ /**
1159
+ * The age in months from which an infant cannot have `feeding: "breast-milk"`: 6.
1160
+ * From 6 months, the infant table gives more than the change of a stage of lactation, so a part of the need is in no draw. Give `food` from this age.
1161
+ */
1162
+ const BREAST_MILK_MONTHS = 6;
1163
+ /**
1164
+ * The age in months below which an infant on formula is in the formula draw with the whole need of its row: 6.
1165
+ * Below this age, an infant has milk only, as for `BREAST_MILK_MONTHS`. From this age, no cited source gives the part of formula.
1166
+ */
1167
+ const FORMULA_DRAW_MONTHS = 6;
1123
1168
  /** This function gives the stores of the buy list, its resources and its gifts with no read. */
1124
- function buyListStores(input, foodUses) {
1169
+ function buyListStores(input) {
1125
1170
  const { catalog, units } = input;
1126
1171
  const energy = buyListEnergy(catalog, units);
1127
- const unitOf = new Map(catalog.resources.map((resource) => [resource.code, resource.unit]));
1128
- for (const use of foodUses) if (unitOf.get(use.resource) !== "kcal") throw new RangeError(`The catalog has no resource "${use.resource}" in kcal for the food use.`);
1129
1172
  const prefix = input.prefix ?? "buy";
1130
1173
  const stores = [];
1131
1174
  const noReads = [];
@@ -1141,10 +1184,6 @@ function buyListStores(input, foodUses) {
1141
1184
  });
1142
1185
  return {
1143
1186
  stores,
1144
- resources: [.../* @__PURE__ */ new Set([...stores.map((store) => store.resource), ...foodUses.map((use) => use.resource)])].map((code) => ({
1145
- code,
1146
- unit: unitOf.get(code) ?? ""
1147
- })),
1148
1187
  parts: {
1149
1188
  energy,
1150
1189
  noReads,
@@ -1153,78 +1192,192 @@ function buyListStores(input, foodUses) {
1153
1192
  };
1154
1193
  }
1155
1194
  /**
1195
+ * This function gives the resources of the stores and of the uses, with the units of the catalog.
1196
+ *
1197
+ * @throws RangeError when the resource of a use is not in the catalog in kcal
1198
+ */
1199
+ function layerResources(catalog, stores, uses) {
1200
+ const unitOf = new Map(catalog.resources.map((resource) => [resource.code, resource.unit]));
1201
+ for (const use of uses) if (unitOf.get(use.resource) !== "kcal") throw new RangeError(`The catalog has no resource "${use.resource}" in kcal for the use of ${use.need}.`);
1202
+ return [.../* @__PURE__ */ new Set([...stores.map((store) => store.resource), ...uses.map((use) => use.resource)])].map((code) => ({
1203
+ code,
1204
+ unit: unitOf.get(code) ?? ""
1205
+ }));
1206
+ }
1207
+ /**
1156
1208
  * This function joins a household and a buy list into a fragment of an endurance layer.
1157
1209
  *
1158
- * - The fragment has one draw of food energy. Its rate is the need of the persons for one day, and its users are the persons.
1210
+ * - The draw of food energy has the rate of the need of its persons for one day, and its users are the persons.
1211
+ * - The draw of formula has the infants on formula below `FORMULA_DRAW_MONTHS`, with the whole need of their rows.
1212
+ * - The fragment has each draw with one or more users. The draw of food energy is first.
1159
1213
  * - Each gift of the buy list with a read is one store, with the `id` `<prefix>:<product>:<resource>`. A gift with no read has no store.
1160
- * - The direct uses are the food uses: each use of `uses` for the need `food.energy`. The default `DIRECT_USES` gives `food.no-cook`, 1 kcal for each kcal.
1161
- * - The resources are the resources of the stores and of the food uses, with the units of the catalog.
1162
- * - The supply part of the draw is `supply`. Its default is the part of `NEED_SUPPLIES` for `food.energy`.
1214
+ * - The direct uses are each use of `uses` for the need of a draw. The default `DIRECT_USES` gives 1 kcal for each kcal.
1215
+ * `food.no-cook` feeds the food draw, and `food.infant-formula-ready` feeds the formula draw.
1216
+ * - The resources are the resources of the stores and of the direct uses, with the units of the catalog.
1217
+ * - The supply part of each draw is `supply`. Its default is the part of `NEED_SUPPLIES` for the need of the draw.
1163
1218
  * - The fragment has no converter. A caller adds converters for the dry food, with the water and the fuel of each run.
1164
1219
  *
1165
1220
  * A person with no row in the tables gives no layer, because a low rate gives too many days. The default tables give a row for each age.
1166
1221
  * The option `noRow: "leave-out"` leaves those persons out of the draw. A draw of 0 kcal gives no layer.
1222
+ *
1223
+ * Each person record below `INFANT_MONTHS` must have a `feeding`. It has no default.
1224
+ *
1225
+ * - `food`: the need of the infant is in the draw of food energy.
1226
+ * - `breast-milk`: the infant has a line, and no part of the draw. It is only for an infant below `BREAST_MILK_MONTHS`.
1227
+ * A person of the household must have a stage of lactation. Each infant on breast milk needs one person of the draw with a stage of lactation.
1228
+ * When the infants are more, the function gives no layer: the change of a stage is the milk of one infant.
1229
+ * - `formula`: below `FORMULA_DRAW_MONTHS`, the whole need of the infant is in the draw of formula, because the infant has milk only.
1230
+ * From `FORMULA_DRAW_MONTHS`, no cited source gives the part of formula, so the infant gives no layer, as a person with no row.
1231
+ * The option `leave-out` also applies. The feeding is only for an infant below `INFANT_MONTHS`.
1232
+ *
1167
1233
  * The function is pure.
1168
1234
  *
1169
1235
  * @param input - The persons, the activity level, the catalog and the buy list, the supply part and the level of the draw
1170
1236
  * @returns The fragment or a no read of the draw, with the energy of the list and the gifts with no read
1171
1237
  * @throws RangeError for the errors of `calorieNeed`, `giftsOf` and `buyListEnergy`, except a household with no person
1172
- * @throws RangeError when the catalog has no resource in `kcal` for a food use
1238
+ * @throws RangeError when the catalog has no resource in `kcal` for the direct use of a draw
1239
+ * @throws RangeError when a record below `INFANT_MONTHS` has no `feeding`, or when a `feeding` is not a way of `INFANT_FEEDINGS`
1240
+ * @throws RangeError for `breast-milk` from `BREAST_MILK_MONTHS`, and for `formula` from `INFANT_MONTHS`
1241
+ * @throws RangeError when an infant drinks only breast milk and no person of the household has a stage of lactation
1173
1242
  */
1174
1243
  function householdFragment(input) {
1175
- const foodUses = (input.uses ?? DIRECT_USES).filter((use) => use.need === FOOD_NEED);
1176
- const { stores, resources, parts } = buyListStores(input, foodUses);
1244
+ const { stores, parts } = buyListStores(input);
1245
+ checkFeedings(input.persons);
1177
1246
  if (input.persons.every((person) => person.count === 0)) return {
1178
1247
  ...parts,
1179
1248
  layer: void 0,
1180
1249
  need: void 0,
1181
1250
  needRead: false,
1182
1251
  noRow: [],
1252
+ formula: [],
1253
+ breastMilk: [],
1183
1254
  why: "The household has no person, so the draw is 0 kcal."
1184
1255
  };
1185
- const need = calorieNeed(input.table ?? CALORIE_CHAIN, input.persons, input.activity, 1);
1256
+ const tables = input.table ?? CALORIE_CHAIN;
1257
+ const need = calorieNeed(tables, input.persons, input.activity, 1);
1186
1258
  const noRow = [];
1259
+ const formula = [];
1260
+ const formulaLater = [];
1261
+ const breastMilk = [];
1187
1262
  let users = 0;
1188
- for (const line of need.lines) if (line.read) users += line.person.count;
1189
- else if (line.person.count > 0) noRow.push(line.person);
1190
- if (noRow.length > 0 && input.noRow !== "leave-out") return {
1263
+ let perDay = 0;
1264
+ let formulaUsers = 0;
1265
+ let formulaPerDay = 0;
1266
+ let mothers = 0;
1267
+ let nursed = 0;
1268
+ for (const line of need.lines) {
1269
+ const { person } = line;
1270
+ if (person.count === 0) continue;
1271
+ if (person.feeding === "breast-milk") {
1272
+ breastMilk.push(person);
1273
+ nursed += person.count;
1274
+ } else if (person.feeding === "formula") {
1275
+ formula.push(person);
1276
+ if (line.read && person.ageMonths < 6) {
1277
+ formulaUsers += person.count;
1278
+ formulaPerDay += line.need.value;
1279
+ } else formulaLater.push(person);
1280
+ } else if (!line.read) noRow.push(person);
1281
+ else {
1282
+ users += person.count;
1283
+ perDay += line.need.value;
1284
+ if (makesMilk(tables, person)) mothers += person.count;
1285
+ }
1286
+ }
1287
+ if (breastMilk.length > 0 && !input.persons.some((person) => person.count > 0 && makesMilk(tables, person))) throw new RangeError(`The infants ${breastMilk.map(nameOf).join(", ")} drink only breast milk, but no person of the household has a stage of lactation. The milk comes from the food of the mother, so give the mother a stage of lactation, for example lactation-1.`);
1288
+ const reasons = [
1289
+ ...nursed > mothers ? [`${String(nursed)} infants drink only breast milk, but the draw has ${String(mothers)} persons with a stage of lactation. The change of a stage is the milk of one infant. Give feeding: food to the other infants.`] : [],
1290
+ ...noRow.length > 0 ? [`The table has no row for ${String(noRow.length)} person records.`] : [],
1291
+ ...formulaLater.length > 0 ? [`${String(formulaLater.length)} infant records of ${String(6)} months or more are on formula. No cited source gives the part of their need that formula gives.`] : []
1292
+ ];
1293
+ if (nursed > mothers) return {
1191
1294
  ...parts,
1192
1295
  layer: void 0,
1193
1296
  need,
1194
1297
  needRead: false,
1195
1298
  noRow,
1196
- why: `The table has no row for ${String(noRow.length)} person records. The option noRow: "leave-out" leaves them out of the draw.`
1299
+ formula,
1300
+ breastMilk,
1301
+ why: reasons.join(" ")
1197
1302
  };
1198
- if (users === 0 || need.need.value <= 0) return {
1303
+ if (reasons.length > 0 && input.noRow !== "leave-out") return {
1199
1304
  ...parts,
1200
1305
  layer: void 0,
1201
1306
  need,
1202
1307
  needRead: false,
1203
1308
  noRow,
1204
- why: "No person of the draw has a row in the table, so the draw is 0 kcal."
1309
+ formula,
1310
+ breastMilk,
1311
+ why: `${reasons.join(" ")} The option noRow: "leave-out" leaves them out of the draw.`
1205
1312
  };
1206
- const draw = {
1313
+ const draws = [];
1314
+ if (users > 0 && perDay > 0) draws.push({
1207
1315
  need: FOOD_NEED,
1208
1316
  level: input.level,
1209
- perDay: need.need.value,
1317
+ perDay,
1210
1318
  users,
1211
1319
  supply: input.supply ?? NEED_SUPPLIES["food.energy"]
1320
+ });
1321
+ if (formulaUsers > 0 && formulaPerDay > 0) draws.push({
1322
+ need: FORMULA_NEED,
1323
+ level: input.level,
1324
+ perDay: formulaPerDay,
1325
+ users: formulaUsers,
1326
+ supply: input.supply ?? NEED_SUPPLIES["food.infant-formula"]
1327
+ });
1328
+ if (draws.length === 0) return {
1329
+ ...parts,
1330
+ layer: void 0,
1331
+ need,
1332
+ needRead: false,
1333
+ noRow,
1334
+ formula,
1335
+ breastMilk,
1336
+ why: "No person of the draws has a need of food in the draws, so the draws are 0 kcal."
1212
1337
  };
1338
+ const needs = new Set(draws.map((draw) => draw.need));
1339
+ const uses = (input.uses ?? DIRECT_USES).filter((use) => needs.has(use.need));
1213
1340
  return {
1214
1341
  ...parts,
1215
1342
  layer: {
1216
1343
  schema: "endurance/1",
1217
1344
  levels: [...input.levels ?? []],
1218
- resources,
1345
+ resources: layerResources(input.catalog, stores, uses),
1219
1346
  stores,
1220
- draws: [draw],
1221
- direct: foodUses.map((use) => ({ ...use }))
1347
+ draws,
1348
+ direct: uses.map((use) => ({ ...use }))
1222
1349
  },
1223
1350
  need,
1224
1351
  needRead: true,
1225
- leftOut: noRow
1352
+ leftOut: [...noRow, ...formulaLater],
1353
+ formula,
1354
+ breastMilk
1226
1355
  };
1227
1356
  }
1228
- export { ACTIVITY_LEVELS, CALORIE_CHAIN, CALORIE_SEXES, CALORIE_TABLES, DGA_CALORIES, DGA_SOURCE, DIRECT_USES, FOOD_NEED, JOIN_CODES, NASEM_ENERGY_SOURCE, NASEM_INFANT_CALORIES, NEEDS_CODES, NEED_SUPPLIES, NO_COOK, STORED_WATER, WATER_NEED, calorieChange, calorieNeed, calorieRow, calorieRowOf, checkCalorieChain, checkCalorieTable, checkJoins, hasNeedsError, householdFragment, isActivityLevel };
1357
+ /** This function gives the name of a person record in a message. */
1358
+ function nameOf(person) {
1359
+ return `${String(person.sex)} of ${String(person.ageMonths)} months`;
1360
+ }
1361
+ /**
1362
+ * This function examines the feeding of each record. A record below `INFANT_MONTHS` must have one.
1363
+ * Each feeding is a way of `INFANT_FEEDINGS`, and each way holds at the age of the record.
1364
+ */
1365
+ function checkFeedings(persons) {
1366
+ for (const person of persons) {
1367
+ const { feeding } = person;
1368
+ if (feeding === void 0) {
1369
+ if (person.count > 0 && person.ageMonths < 12) throw new RangeError(`The persons ${nameOf(person)} are below ${String(12)} months and have no feeding. Give feeding: ${INFANT_FEEDINGS.join(", ")}.`);
1370
+ } else if (!INFANT_FEEDINGS.includes(feeding)) throw new RangeError(`The feeding ${String(feeding)} of the persons ${nameOf(person)} is not a way of ${INFANT_FEEDINGS.join(", ")}.`);
1371
+ else if (feeding === "breast-milk" && !(person.ageMonths < 6)) throw new RangeError(`The persons ${nameOf(person)} have feeding: breast-milk, which is only for an infant below ${String(6)} months. From that age, the need is more than the change of a stage of lactation. Give feeding: food.`);
1372
+ else if (feeding === "formula" && !(person.ageMonths < 12)) throw new RangeError(`The persons ${nameOf(person)} have feeding: formula, which is only for an infant below ${String(12)} months. Give feeding: food.`);
1373
+ }
1374
+ }
1375
+ /** This function tells if the stage of a person record is a stage that makes milk, in one of the tables. */
1376
+ function makesMilk(tables, person) {
1377
+ const { stage } = person;
1378
+ if (stage === void 0) return false;
1379
+ return ("rows" in tables ? [tables] : tables).some((table) => calorieChange(table, person.sex, stage)?.milk === true);
1380
+ }
1381
+ export { ACTIVITY_LEVELS, BREAST_MILK_MONTHS, CALORIE_CHAIN, CALORIE_SEXES, CALORIE_TABLES, DGA_CALORIES, DGA_SOURCE, DIRECT_USES, FOOD_NEED, FORMULA_DRAW_MONTHS, FORMULA_NEED, FORMULA_READY, INFANT_FEEDINGS, INFANT_MONTHS, JOIN_CODES, NASEM_ENERGY_SOURCE, NASEM_INFANT_CALORIES, NEEDS_CODES, NEED_SUPPLIES, NO_COOK, STORED_WATER, WATER_NEED, calorieChange, calorieNeed, calorieRow, calorieRowOf, checkCalorieChain, checkCalorieTable, checkJoins, hasNeedsError, householdFragment, isActivityLevel };
1229
1382
 
1230
1383
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/calorie.ts","../src/data.ts","../src/check.ts","../src/uses.ts","../src/household.ts"],"sourcesContent":["import { quantity, valueIn, type Quantity } from \"@mark1russell7/quantity\";\nimport type { Source } from \"@mark1russell7/guidebook\";\n\n// The energy need of the persons of a household, from a cited table of estimated calorie needs.\n// The package names no person. The persons and their activity level are input data.\n// A person record has a sex, an age in months and a count. Each table finds its own row from its own age ranges.\n\n/** The activity levels of the table, as the source names them: sedentary, moderately active and active. */\nexport const ACTIVITY_LEVELS: readonly [\"sedentary\", \"moderately-active\", \"active\"] = [\"sedentary\", \"moderately-active\", \"active\"];\n\n/** An activity level of the table. */\nexport type ActivityLevel = (typeof ACTIVITY_LEVELS)[number];\n\n/** The sexes of the table. */\nexport const CALORIE_SEXES: readonly [\"female\", \"male\"] = [\"female\", \"male\"];\n\n/** A sex of the table. */\nexport type CalorieSex = (typeof CALORIE_SEXES)[number];\n\n/**\n * The estimated calorie need of one person of a row for each day. A row gives a need for each activity level, or one need for all levels.\n * The table of the toddlers gives one need for each age and sex only. Each need has a unit of energy for each day, for example `{ \"value\": 2000, \"unit\": \"kcal/d\" }`.\n */\nexport type CalorieNeed = { readonly levels: Readonly<Record<ActivityLevel, Quantity>>; readonly each?: never } | { readonly each: Quantity; readonly levels?: never };\n\n/** A row of a table of calorie needs: a sex, a range of ages in months, and the need. */\nexport interface CalorieRow {\n readonly sex: CalorieSex;\n /** The age as the source names it, for example `19-20` (years) or `21 through 23 months`. */\n readonly age: string;\n /** The first age of the row, in whole months. */\n readonly from: number;\n /** The last age of the row, in whole months. Without it, the row applies to each larger age. */\n readonly to?: number | undefined;\n readonly need: CalorieNeed;\n}\n\n/**\n * A change of the daily need of a person at a stage, for example the second trimester of a pregnancy. The change adds\n * to the need of the row of the person. It can be 0.\n */\nexport interface CalorieChange {\n /** The id of the stage, for example `pregnancy-2`. */\n readonly stage: string;\n /** The stage as the source names it, for example `Pregnancy: 2nd trimester`. */\n readonly title: string;\n /** The sex of the persons of the stage. */\n readonly sex: CalorieSex;\n /** The change of the need for each day, in a unit of energy for each day, for example `{ \"value\": 340, \"unit\": \"kcal/d\" }`. */\n readonly change: Quantity;\n /** The condition of the source for the change, for example a healthy weight before the pregnancy. */\n readonly condition?: string | undefined;\n}\n\n/** A table of estimated calorie needs from one source. */\nexport interface CalorieTable {\n /** The id, for example `dga.2020-2025:calorie-needs`. */\n readonly id: string;\n readonly title: string;\n readonly source: Source;\n /** The place of the tables in the source: the tables and their pages. */\n readonly locator: string;\n /** The rows of the table. The age ranges of the rows of one sex do not overlap. */\n readonly rows: readonly CalorieRow[];\n /** The changes of the need at each stage. The stage and the sex of each change are unique. */\n readonly changes?: readonly CalorieChange[] | undefined;\n}\n\n/**\n * One table, or tables in order. For each person, the first table with a row for the age gives the need.\n * An example is `CALORIE_CHAIN`: the guidelines from 12 months, and the infant table below 12 months.\n */\nexport type CalorieTables = CalorieTable | readonly CalorieTable[];\n\n/** A group of persons of the same sex and age, and their count. */\nexport interface Person {\n readonly sex: CalorieSex;\n /** The age, in whole months, for example 420 for 35 years. */\n readonly ageMonths: number;\n readonly count: number;\n /** The activity level of the persons. Without it, the level of the call applies. */\n readonly level?: ActivityLevel | undefined;\n /** The stage of the persons, for example `pregnancy-2`: the stage of a change of the table. Without it, no change applies. */\n readonly stage?: string | undefined;\n}\n\n/** The need of one person record for the days, or no read when the table has no row for the age. */\nexport type CalorieNeedLine =\n | { readonly person: Person; readonly read: true; readonly level: ActivityLevel; readonly table: string; readonly row: string; readonly stage?: string | undefined; readonly need: Quantity }\n | { readonly person: Person; readonly read: false; readonly why: string };\n\n/** The energy need of the persons of a household for a count of days. */\nexport interface CalorieNeedTotal {\n /** The need of each person record, in the order of the input. */\n readonly lines: readonly CalorieNeedLine[];\n /** True when each line has a read. When it is false, `need` is a lower limit. */\n readonly read: boolean;\n /** The sum of the needs of the lines with a read, in `kcal`. */\n readonly need: Quantity;\n /** The count of the persons of all the records, also of the records with no read. */\n readonly persons: number;\n}\n\n/** The unit of each food energy. */\nconst ENERGY_UNIT = \"kcal\";\n/** The unit of each daily need. */\nconst DAILY_UNIT = \"kcal/d\";\n\n/** This function tells if a value is an activity level of the table. */\nexport function isActivityLevel(level: unknown): level is ActivityLevel {\n return (ACTIVITY_LEVELS as readonly unknown[]).includes(level);\n}\n\n/**\n * This function gives the row of a table for a sex and an age in months, or `undefined` when the table has no row.\n *\n * @param table - The table of calorie needs\n * @param sex - The sex\n * @param ageMonths - The age, in whole months\n */\nexport function calorieRow(table: CalorieTable, sex: CalorieSex, ageMonths: number): CalorieRow | undefined {\n return table.rows.find((row) => row.sex === sex && ageMonths >= row.from && (row.to === undefined || ageMonths <= row.to));\n}\n\n/**\n * This function gives the first table with a row for a sex and an age in months, and its row.\n * It gives `undefined` when no table has a row.\n *\n * @param tables - One table, or tables in order\n * @param sex - The sex\n * @param ageMonths - The age, in whole months\n */\nexport function calorieRowOf(tables: CalorieTables, sex: CalorieSex, ageMonths: number): { readonly table: CalorieTable; readonly row: CalorieRow } | undefined {\n for (const table of tableList(tables)) {\n const row = calorieRow(table, sex, ageMonths);\n if (row !== undefined) return { table, row };\n }\n return undefined;\n}\n\n/** This function gives the tables of the input as a list. */\nfunction tableList(tables: CalorieTables): readonly CalorieTable[] {\n return \"rows\" in tables ? [tables] : tables;\n}\n\n/**\n * This function gives the change of a table for a sex and a stage, or `undefined` when the table has no such change.\n *\n * @param table - The table of calorie needs\n * @param sex - The sex\n * @param stage - The id of the stage, for example `pregnancy-2`\n */\nexport function calorieChange(table: CalorieTable, sex: CalorieSex, stage: string): CalorieChange | undefined {\n return table.changes?.find((change) => change.sex === sex && change.stage === stage);\n}\n\n/**\n * This function gives the energy need of the persons of a household for a count of days, in `kcal`.\n * It adds the need of each person at the activity level of that person. The first table with a row for the age of a person gives the row.\n *\n * - An age with no row in the tables gives a line with no read, for example 6 months in `DGA_CALORIES` alone. Then the total is a lower limit.\n * - Each line with a read has the `id` of the table of its row.\n * - The table of the toddlers gives one need for each age and sex. Thus the level does not change the need of a toddler.\n * - A record with a stage adds the change of the stage to the need of its row, for example 340 kcal/d in the second trimester. The change comes from the table of the row.\n * - One stage holds for each day of the call. For a period that crosses stages, the planner selects the stage, for example the stage with the largest change.\n *\n * The activity level is an explicit input. This package has no default level. The planner selects it, also for the worst case of a long power cut.\n * In that case, work can make the level higher, for example the carry of water. The function is pure.\n *\n * @param tables - The table of calorie needs, or tables in order\n * @param persons - The person records of the household: a sex, an age in months, a count and, as an option, a level\n * @param level - The activity level of each record with no level of its own\n * @param days - The count of days, a finite number of 0 or more\n * @throws RangeError when a count of persons or an age is not a whole number of 0 or more, or when the household has no person\n * @throws RangeError when a level is not a level of the table, or when a sex is not a sex of the table\n * @throws RangeError when the count of days is not a finite number of 0 or more, or when the list of tables is empty\n * @throws RangeError when no table has the change for the stage and the sex of a record\n * @throws RangeError when the table of the row of a record has no change for the stage and the sex of the record\n * @throws RangeError when the daily need of a record, with the change of its stage, is not above 0\n */\nexport function calorieNeed(tables: CalorieTables, persons: readonly Person[], level: ActivityLevel, days: number): CalorieNeedTotal {\n if (!(Number.isFinite(days) && days >= 0)) throw new RangeError(`The count of days is ${String(days)}. It must be a finite number of 0 or more.`);\n if (!isActivityLevel(level)) throw new RangeError(`The activity level ${String(level)} is not a level of the table.`);\n const list = tableList(tables);\n if (list.length === 0) throw new RangeError(\"The list of tables is empty.\");\n const ids = list.map((table) => table.id).join(\", \");\n let count = 0;\n const lines = persons.map((person): CalorieNeedLine => {\n const name = `${String(person.sex)} of ${String(person.ageMonths)} months`;\n if (!(Number.isSafeInteger(person.count) && person.count >= 0)) throw new RangeError(`The count of the persons ${name} is ${String(person.count)}. It must be a whole number of 0 or more.`);\n if (!(Number.isSafeInteger(person.ageMonths) && person.ageMonths >= 0)) throw new RangeError(`The age of the persons ${name} is not a whole number of months of 0 or more.`);\n if (!(CALORIE_SEXES as readonly unknown[]).includes(person.sex)) throw new RangeError(`The sex ${String(person.sex)} is not a sex of the table.`);\n const own = person.level ?? level;\n if (!isActivityLevel(own)) throw new RangeError(`The activity level ${String(own)} of the persons ${name} is not a level of the table.`);\n // A stage that the table does not have is an error, not a no read: the option leave-out would remove the persons from a draw.\n const { stage } = person;\n if (stage !== undefined && list.every((table) => calorieChange(table, person.sex, stage) === undefined)) throw new RangeError(`The tables ${ids} have no change for the stage ${String(stage)} of the persons ${name}.`);\n count += person.count;\n const found = calorieRowOf(list, person.sex, person.ageMonths);\n if (found === undefined) return { person, read: false, why: `The tables ${ids} have no row for a ${name}.` };\n const { table, row } = found;\n const change = stage === undefined ? undefined : calorieChange(table, person.sex, stage);\n if (stage !== undefined && change === undefined) throw new RangeError(`The table ${table.id} of the row of the persons ${name} has no change for the stage ${String(stage)}.`);\n const daily = valueIn(row.need.levels === undefined ? row.need.each : row.need.levels[own], DAILY_UNIT) + (change === undefined ? 0 : valueIn(change.change, DAILY_UNIT));\n if (!(daily > 0)) throw new RangeError(`The daily need of the persons ${name} at the stage ${String(person.stage)} is ${String(daily)} kcal/d. It must be above 0.`);\n const line = { person, read: true as const, level: own, table: table.id, row: row.age, need: quantity(person.count * daily * days, ENERGY_UNIT) };\n return change === undefined ? line : { ...line, stage: change.stage };\n });\n if (count === 0) throw new RangeError(\"The household has no person.\");\n const total = lines.reduce((sum, line) => sum + (line.read ? line.need.value : 0), 0);\n return { lines, read: lines.every((line) => line.read), need: quantity(total, ENERGY_UNIT), persons: count };\n}\n","import type { CalorieChange, CalorieNeed, CalorieTable } from \"./calorie.ts\";\nimport type { Source } from \"@mark1russell7/guidebook\";\n\n// The estimated calorie needs of the Dietary Guidelines for Americans, 2020-2025. Each value is from the tables of\n// Appendix 2 of the PDF, read on 2026-11-22. A calorie of the source is a food calorie, thus 1 kcal. The source gives\n// each need for a reference height and weight, to keep the weight of a person. A person can need more or less.\n// The rows of the toddlers are at 12, 15, 18 and 21 through 23 months. Each row here covers the months up to the next row.\n// The changes of pregnancy and lactation are from Table A2-3. The source gives them for women with a healthy weight before\n// the pregnancy.\n// The 2025-2030 edition of the guidelines (read on 2026-11-24) has no table of calorie needs. It sends the reader to the\n// DRI calculator of the USDA. Its daily servings by calorie level start at a calorie level and do not give a need. So\n// this table stays the table of the 2020-2025 edition.\n\n/** The source of the calorie table: the PDF of the Dietary Guidelines for Americans, 2020-2025, 9th Edition. It is a work of the United States federal government. */\nexport const DGA_SOURCE: Source = {\n id: \"dga-2020-2025\",\n title: \"Dietary Guidelines for Americans, 2020-2025, 9th Edition\",\n url: \"https://www.dietaryguidelines.gov/sites/default/files/2020-12/Dietary_Guidelines_for_Americans_2020-2025.pdf\",\n license: \"us-public-domain\",\n checked: \"2026-11-22\",\n by: \"U.S. Department of Agriculture and U.S. Department of Health and Human Services\",\n terms: \"https://www.dietaryguidelines.gov/policy-and-links\",\n sha256: \"ceea04ce1a7c13a95a170f3548ed3926ad6dd49599bd730fb58bc9c02711d16e\",\n};\n\nconst day = (value: number): { readonly value: number; readonly unit: string } => ({ value, unit: \"kcal/d\" });\nconst levels = (sedentary: number, moderate: number, active: number): CalorieNeed => ({ levels: { sedentary: day(sedentary), \"moderately-active\": day(moderate), active: day(active) } });\nconst each = (value: number): CalorieNeed => ({ each: day(value) });\nconst HEALTHY = \"For women with a healthy weight before the pregnancy. Other women ask their health care provider.\";\nconst change = (stage: string, title: string, value: number): CalorieChange => ({ stage, title, sex: \"female\", change: day(value), condition: HEALTHY });\n\n/** The table of estimated calorie needs of the Dietary Guidelines for Americans, 2020-2025: 68 rows, 34 for each sex, and 5 changes of pregnancy and lactation. */\nexport const DGA_CALORIES: CalorieTable = {\n id: \"dga.2020-2025:calorie-needs\",\n title: \"Dietary Guidelines for Americans, 2020-2025: Estimated Calorie Needs\",\n source: DGA_SOURCE,\n locator: \"Appendix 2: Table A2-1 (ages 12 through 23 months, page 139), Table A2-2 (ages 2 and older, pages 140 and 141) and Table A2-3 (pregnancy and lactation, page 141)\",\n changes: [\n change(\"pregnancy-1\", \"Pregnancy: 1st trimester\", 0),\n change(\"pregnancy-2\", \"Pregnancy: 2nd trimester\", 340),\n change(\"pregnancy-3\", \"Pregnancy: 3rd trimester\", 452),\n change(\"lactation-1\", \"Lactation: 1st 6 months\", 330),\n change(\"lactation-2\", \"Lactation: 2nd 6 months\", 400),\n ],\n rows: [\n { sex: \"female\", age: \"12 months\", from: 12, to: 14, need: each(800) },\n { sex: \"female\", age: \"15 months\", from: 15, to: 17, need: each(800) },\n { sex: \"female\", age: \"18 months\", from: 18, to: 20, need: each(900) },\n { sex: \"female\", age: \"21 through 23 months\", from: 21, to: 23, need: each(1000) },\n { sex: \"female\", age: \"2\", from: 24, to: 35, need: levels(1000, 1000, 1000) },\n { sex: \"female\", age: \"3\", from: 36, to: 47, need: levels(1000, 1200, 1400) },\n { sex: \"female\", age: \"4\", from: 48, to: 59, need: levels(1200, 1400, 1400) },\n { sex: \"female\", age: \"5\", from: 60, to: 71, need: levels(1200, 1400, 1600) },\n { sex: \"female\", age: \"6\", from: 72, to: 83, need: levels(1200, 1400, 1600) },\n { sex: \"female\", age: \"7\", from: 84, to: 95, need: levels(1200, 1600, 1800) },\n { sex: \"female\", age: \"8\", from: 96, to: 107, need: levels(1400, 1600, 1800) },\n { sex: \"female\", age: \"9\", from: 108, to: 119, need: levels(1400, 1600, 1800) },\n { sex: \"female\", age: \"10\", from: 120, to: 131, need: levels(1400, 1800, 2000) },\n { sex: \"female\", age: \"11\", from: 132, to: 143, need: levels(1600, 1800, 2000) },\n { sex: \"female\", age: \"12\", from: 144, to: 155, need: levels(1600, 2000, 2200) },\n { sex: \"female\", age: \"13\", from: 156, to: 167, need: levels(1600, 2000, 2200) },\n { sex: \"female\", age: \"14\", from: 168, to: 179, need: levels(1800, 2000, 2400) },\n { sex: \"female\", age: \"15\", from: 180, to: 191, need: levels(1800, 2000, 2400) },\n { sex: \"female\", age: \"16\", from: 192, to: 203, need: levels(1800, 2000, 2400) },\n { sex: \"female\", age: \"17\", from: 204, to: 215, need: levels(1800, 2000, 2400) },\n { sex: \"female\", age: \"18\", from: 216, to: 227, need: levels(1800, 2000, 2400) },\n { sex: \"female\", age: \"19-20\", from: 228, to: 251, need: levels(2000, 2200, 2400) },\n { sex: \"female\", age: \"21-25\", from: 252, to: 311, need: levels(2000, 2200, 2400) },\n { sex: \"female\", age: \"26-30\", from: 312, to: 371, need: levels(1800, 2000, 2400) },\n { sex: \"female\", age: \"31-35\", from: 372, to: 431, need: levels(1800, 2000, 2200) },\n { sex: \"female\", age: \"36-40\", from: 432, to: 491, need: levels(1800, 2000, 2200) },\n { sex: \"female\", age: \"41-45\", from: 492, to: 551, need: levels(1800, 2000, 2200) },\n { sex: \"female\", age: \"46-50\", from: 552, to: 611, need: levels(1800, 2000, 2200) },\n { sex: \"female\", age: \"51-55\", from: 612, to: 671, need: levels(1600, 1800, 2200) },\n { sex: \"female\", age: \"56-60\", from: 672, to: 731, need: levels(1600, 1800, 2200) },\n { sex: \"female\", age: \"61-65\", from: 732, to: 791, need: levels(1600, 1800, 2000) },\n { sex: \"female\", age: \"66-70\", from: 792, to: 851, need: levels(1600, 1800, 2000) },\n { sex: \"female\", age: \"71-75\", from: 852, to: 911, need: levels(1600, 1800, 2000) },\n { sex: \"female\", age: \"76 and up\", from: 912, need: levels(1600, 1800, 2000) },\n { sex: \"male\", age: \"12 months\", from: 12, to: 14, need: each(800) },\n { sex: \"male\", age: \"15 months\", from: 15, to: 17, need: each(900) },\n { sex: \"male\", age: \"18 months\", from: 18, to: 20, need: each(1000) },\n { sex: \"male\", age: \"21 through 23 months\", from: 21, to: 23, need: each(1000) },\n { sex: \"male\", age: \"2\", from: 24, to: 35, need: levels(1000, 1000, 1000) },\n { sex: \"male\", age: \"3\", from: 36, to: 47, need: levels(1000, 1400, 1400) },\n { sex: \"male\", age: \"4\", from: 48, to: 59, need: levels(1200, 1400, 1600) },\n { sex: \"male\", age: \"5\", from: 60, to: 71, need: levels(1200, 1400, 1600) },\n { sex: \"male\", age: \"6\", from: 72, to: 83, need: levels(1400, 1600, 1800) },\n { sex: \"male\", age: \"7\", from: 84, to: 95, need: levels(1400, 1600, 1800) },\n { sex: \"male\", age: \"8\", from: 96, to: 107, need: levels(1400, 1600, 2000) },\n { sex: \"male\", age: \"9\", from: 108, to: 119, need: levels(1600, 1800, 2000) },\n { sex: \"male\", age: \"10\", from: 120, to: 131, need: levels(1600, 1800, 2200) },\n { sex: \"male\", age: \"11\", from: 132, to: 143, need: levels(1800, 2000, 2200) },\n { sex: \"male\", age: \"12\", from: 144, to: 155, need: levels(1800, 2200, 2400) },\n { sex: \"male\", age: \"13\", from: 156, to: 167, need: levels(2000, 2200, 2600) },\n { sex: \"male\", age: \"14\", from: 168, to: 179, need: levels(2000, 2400, 2800) },\n { sex: \"male\", age: \"15\", from: 180, to: 191, need: levels(2200, 2600, 3000) },\n { sex: \"male\", age: \"16\", from: 192, to: 203, need: levels(2400, 2800, 3200) },\n { sex: \"male\", age: \"17\", from: 204, to: 215, need: levels(2400, 2800, 3200) },\n { sex: \"male\", age: \"18\", from: 216, to: 227, need: levels(2400, 2800, 3200) },\n { sex: \"male\", age: \"19-20\", from: 228, to: 251, need: levels(2600, 2800, 3000) },\n { sex: \"male\", age: \"21-25\", from: 252, to: 311, need: levels(2400, 2800, 3000) },\n { sex: \"male\", age: \"26-30\", from: 312, to: 371, need: levels(2400, 2600, 3000) },\n { sex: \"male\", age: \"31-35\", from: 372, to: 431, need: levels(2400, 2600, 3000) },\n { sex: \"male\", age: \"36-40\", from: 432, to: 491, need: levels(2400, 2600, 2800) },\n { sex: \"male\", age: \"41-45\", from: 492, to: 551, need: levels(2200, 2600, 2800) },\n { sex: \"male\", age: \"46-50\", from: 552, to: 611, need: levels(2200, 2400, 2800) },\n { sex: \"male\", age: \"51-55\", from: 612, to: 671, need: levels(2200, 2400, 2800) },\n { sex: \"male\", age: \"56-60\", from: 672, to: 731, need: levels(2200, 2400, 2600) },\n { sex: \"male\", age: \"61-65\", from: 732, to: 791, need: levels(2000, 2400, 2600) },\n { sex: \"male\", age: \"66-70\", from: 792, to: 851, need: levels(2000, 2200, 2600) },\n { sex: \"male\", age: \"71-75\", from: 852, to: 911, need: levels(2000, 2200, 2600) },\n { sex: \"male\", age: \"76 and up\", from: 912, need: levels(2000, 2200, 2400) },\n ],\n};\n\n// The Estimated Energy Requirements of the report Dietary Reference Intakes for Energy (2023) of the National Academies,\n// for the ages of 0 to 35 months. Each value is from Table 7-5 (boys, page 160) and Table 7-6 (girls, page 161) of the\n// PDF, read on 2026-11-24. The report gives each need for the median length and weight of the age group in the United\n// States (NHANES 2015-2018). The age groups are 3 months wide. The report predicts each group at one age, for example\n// 1 month for the group Birth-2.\n// The report is all rights reserved. The values are facts with a citation, and the gate of the sources permits them.\n// The Infant Nutrition and Feeding guide of the WIC program of the USDA (read on 2026-11-24) gives no table of daily needs.\n\n/** The source of the infant table: the PDF of the report Dietary Reference Intakes for Energy (2023) of the National Academies. */\nexport const NASEM_ENERGY_SOURCE: Source = {\n id: \"nasem-dri-energy-2023\",\n title: \"Dietary Reference Intakes for Energy (2023)\",\n url: \"https://nap.nationalacademies.org/26818\",\n license: \"all-rights-reserved\",\n checked: \"2026-11-24\",\n by: \"National Academies of Sciences, Engineering, and Medicine\",\n terms: \"https://nap.nationalacademies.org/26818\",\n note: \"DOI 10.17226/26818. The terms are on the first page of the PDF. The table cites its values as facts and copies no text.\",\n sha256: \"e6a7d9c9104053d4925c621b659b06de4c8dd6c64ed4534e6f5bc5cf0dd41b27\",\n};\n\n/**\n * The table of the Estimated Energy Requirements of the ages of 0 to 35 months, from the report Dietary Reference Intakes\n * for Energy (2023): 24 rows, 12 for each sex. Each row gives one need for each age group and sex. The last row ends at\n * 35 months, so the table is for a chain of tables, for example `CALORIE_CHAIN`.\n */\nexport const NASEM_INFANT_CALORIES: CalorieTable = {\n id: \"nasem.2023:eer-0-35-months\",\n title: \"Dietary Reference Intakes for Energy (2023): Estimated Energy Requirements of the ages of 0 to 35 months\",\n source: NASEM_ENERGY_SOURCE,\n locator: \"Chapter 7: Table 7-5 (boys of 0 to 35 months, page 160) and Table 7-6 (girls of 0 to 35 months, page 161)\",\n rows: [\n { sex: \"female\", age: \"Birth-2\", from: 0, to: 2, need: each(531) },\n { sex: \"female\", age: \"3-5\", from: 3, to: 5, need: each(546) },\n { sex: \"female\", age: \"6-8\", from: 6, to: 8, need: each(604) },\n { sex: \"female\", age: \"9-11\", from: 9, to: 11, need: each(689) },\n { sex: \"female\", age: \"12-14\", from: 12, to: 14, need: each(780) },\n { sex: \"female\", age: \"15-17\", from: 15, to: 17, need: each(817) },\n { sex: \"female\", age: \"18-20\", from: 18, to: 20, need: each(881) },\n { sex: \"female\", age: \"21-23\", from: 21, to: 23, need: each(956) },\n { sex: \"female\", age: \"24-26\", from: 24, to: 26, need: each(1011) },\n { sex: \"female\", age: \"27-29\", from: 27, to: 29, need: each(1051) },\n { sex: \"female\", age: \"30-32\", from: 30, to: 32, need: each(1122) },\n { sex: \"female\", age: \"33-35\", from: 33, to: 35, need: each(1192) },\n { sex: \"male\", age: \"Birth-2\", from: 0, to: 2, need: each(566) },\n { sex: \"male\", age: \"3-5\", from: 3, to: 5, need: each(589) },\n { sex: \"male\", age: \"6-8\", from: 6, to: 8, need: each(675) },\n { sex: \"male\", age: \"9-11\", from: 9, to: 11, need: each(745) },\n { sex: \"male\", age: \"12-14\", from: 12, to: 14, need: each(821) },\n { sex: \"male\", age: \"15-17\", from: 15, to: 17, need: each(881) },\n { sex: \"male\", age: \"18-20\", from: 18, to: 20, need: each(952) },\n { sex: \"male\", age: \"21-23\", from: 21, to: 23, need: each(1027) },\n { sex: \"male\", age: \"24-26\", from: 24, to: 26, need: each(1058) },\n { sex: \"male\", age: \"27-29\", from: 27, to: 29, need: each(1136) },\n { sex: \"male\", age: \"30-32\", from: 30, to: 32, need: each(1183) },\n { sex: \"male\", age: \"33-35\", from: 33, to: 35, need: each(1213) },\n ],\n};\n\n/** The tables of estimated calorie needs, one record for each source. */\nexport const CALORIE_TABLES: readonly CalorieTable[] = [DGA_CALORIES, NASEM_INFANT_CALORIES];\n\n/**\n * The default tables of `householdFragment`, in order: the guidelines first, then the infant table. The guidelines give\n * each age from 12 months. The infant table gives the ages below 12 months. Together they give a row for each age.\n */\nexport const CALORIE_CHAIN: readonly CalorieTable[] = [DGA_CALORIES, NASEM_INFANT_CALORIES];\n","import { checkSources, type Finding, type FindingCode, type GateOptions, type SourceField } from \"@mark1russell7/guidebook\";\nimport { valueIn, type Quantity } from \"@mark1russell7/quantity\";\nimport { ACTIVITY_LEVELS, CALORIE_SEXES, type CalorieRow, type CalorieTable, type CalorieTables } from \"./calorie.ts\";\n\n// The gate of a table of calorie needs: the gate of the sources of guidebook, and the rows.\n\n/**\n * These are the codes of the gate of the rows. Each code is an error. The gate of the sources of `@mark1russell7/guidebook` gives its own codes.\n *\n * - `needs-row`: a row has no age or a wrong sex. Or its range of months is not a range of whole numbers of 0 or more.\n * - `needs-overlap`: two rows of one sex have ages in common.\n * - `needs-gap`: the rows of one sex in a table have a gap between two rows. Or the rows of one sex in a chain of tables\n * do not cover each month from 0 to an open last row.\n * - `needs-value`: a need is not a finite number above 0 in a unit of energy for each day.\n * - `needs-change`: a change has no stage, no title or a wrong sex, or a stage with a space at an end. Or a different\n * change has its stage and sex. Or its value is not a finite number in a unit of energy for each day. Or its sum with\n * the smallest need of its sex is not above 0.\n * - `needs-id`: two tables of a chain have the same `id`. Each line of a need names its table by the `id`.\n */\nexport const NEEDS_CODES: readonly [\"needs-row\", \"needs-overlap\", \"needs-gap\", \"needs-value\", \"needs-change\", \"needs-id\"] = [\n \"needs-row\",\n \"needs-overlap\",\n \"needs-gap\",\n \"needs-value\",\n \"needs-change\",\n \"needs-id\",\n];\n\n/** A code of the gate of a table of calorie needs. */\nexport type NeedsCode = (typeof NEEDS_CODES)[number];\n\n/** A finding of the gate of a table of calorie needs: a finding of the gate of the sources, or a finding of a row. */\nexport type NeedsFinding = Finding<NeedsCode | FindingCode, \"source\" | \"unit\" | \"row\" | \"change\" | \"chain\">;\n\n/** This function tells if a need is a finite number in a unit of energy for each day, and above 0 when `positive` is true. */\nfunction goodNeed(need: Quantity, positive = true): boolean {\n try {\n const value = valueIn(need, \"kcal/d\");\n return Number.isFinite(value) && (!positive || value > 0);\n } catch {\n return false;\n }\n}\n\n/** The fields that the source of each table must have: the credit, the evidence of the license and the hash of the file. */\nconst TABLE_FIELDS: readonly SourceField[] = [\"by\", \"terms\", \"sha256\"];\n\n/**\n * This function gives each finding of a table of calorie needs. A list with no error tells that the gate passes.\n *\n * - The findings of the source come from `checkSources` of `@mark1russell7/guidebook`, with the options of the call and the rules of a table.\n * - The rules of a table: the source has a publisher (`by`), a page of its terms and a hash, and its addresses start with `https:`.\n * - The hash of the source is part of the gate of the sources (`bad-sha256`).\n * - The rows have the codes of `NEEDS_CODES`.\n *\n * The findings are in the order of the table. The function is pure.\n *\n * @param table - The table of calorie needs\n * @param options - The options of the gate of the sources, for example the date of the gate\n */\nexport function checkCalorieTable(table: CalorieTable, options?: GateOptions): NeedsFinding[] {\n const require = [...new Set([...(options?.require ?? []), ...TABLE_FIELDS])];\n const findings: NeedsFinding[] = [...checkSources([table.source], { ...options, require, https: true })];\n const add = (code: NeedsCode, record: \"source\" | \"row\" | \"change\", id: string, message: string): void => {\n findings.push({ level: \"error\", code, record, id, message });\n };\n\n const whole = (value: number | undefined): boolean => value === undefined || (Number.isSafeInteger(value) && value >= 0);\n const range = (row: CalorieRow): boolean => whole(row.from) && whole(row.to) && (row.to === undefined || row.to >= row.from);\n const idOf = (index: number): string => `${table.id}.rows[${String(index)}]`;\n table.rows.forEach((row, index) => {\n const id = idOf(index);\n if (row.age.trim() === \"\" || !(CALORIE_SEXES as readonly unknown[]).includes(row.sex)) add(\"needs-row\", \"row\", id, `The row \"${id}\" has no age or a sex that is not a sex of the table.`);\n if (!range(row)) add(\"needs-row\", \"row\", id, `The row \"${id}\" has a range of months that is not a range of whole numbers of 0 or more.`);\n const needs = row.need.levels === undefined ? [row.need.each] : ACTIVITY_LEVELS.map((level) => row.need.levels?.[level]);\n if (!needs.every((need) => need !== undefined && goodNeed(need))) add(\"needs-value\", \"row\", id, `The row \"${id}\" has a need that is not a number above 0 in kcal/d.`);\n for (const other of table.rows.slice(0, index)) {\n if (other.sex !== row.sex) continue;\n if (row.from <= (other.to ?? Infinity) && other.from <= (row.to ?? Infinity)) add(\"needs-overlap\", \"row\", id, `The row \"${id}\" (${row.sex}, ${row.age}) has ages in common with the row ${other.age}.`);\n }\n });\n\n // The rows of each sex, in the order of their first month, have no gap. A row with a bad range has its own finding.\n // A table can start after month 0 and end at a closed row: the gate of a chain checks the cover of all months.\n for (const sex of CALORIE_SEXES) {\n const rows = table.rows.map((row, index) => ({ row, index })).filter(({ row }) => row.sex === sex && range(row));\n rows.sort((a, b) => a.row.from - b.row.from);\n rows.slice(1).forEach(({ row, index }, at) => {\n const before = rows[at]?.row.to;\n if (before !== undefined && row.from > before + 1) add(\"needs-gap\", \"row\", idOf(index), `The table has no row of a ${sex} for the months ${String(before + 1)} to ${String(row.from - 1)}.`);\n });\n }\n\n // The changes: a stage, a title and a sex of the table, one change for each stage and sex, and a finite value.\n // A change with the smallest need of its sex stays above 0. A row with a bad need has its own finding.\n const smallest = (sex: string): number =>\n Math.min(\n ...table.rows\n .filter((row) => row.sex === sex)\n .flatMap((row) => (row.need.levels === undefined ? [row.need.each] : ACTIVITY_LEVELS.map((level) => row.need.levels?.[level])))\n .filter((need): need is Quantity => need !== undefined && goodNeed(need))\n .map((need) => valueIn(need, \"kcal/d\")),\n );\n const seen = new Set<string>();\n (table.changes ?? []).forEach((change, index) => {\n const id = `${table.id}.changes[${String(index)}]`;\n const stage = typeof change.stage === \"string\" ? change.stage.trim() : \"\";\n const title = typeof change.title === \"string\" ? change.title.trim() : \"\";\n if (stage === \"\" || stage !== change.stage || title === \"\" || !(CALORIE_SEXES as readonly unknown[]).includes(change.sex)) add(\"needs-change\", \"change\", id, `The change \"${id}\" has no stage, no title, a stage with a space at an end or a sex that is not a sex of the table.`);\n else if (seen.has(`${change.sex} ${stage}`)) add(\"needs-change\", \"change\", id, `The change \"${id}\" has the stage ${stage} of a ${change.sex}, and a different change has it too.`);\n seen.add(`${String(change.sex)} ${stage}`);\n if (!goodNeed(change.change, false)) add(\"needs-change\", \"change\", id, `The change \"${id}\" has a value that is not a finite number in kcal/d.`);\n else if (smallest(change.sex) + valueIn(change.change, \"kcal/d\") <= 0) add(\"needs-change\", \"change\", id, `The change \"${id}\" makes the smallest need of a ${change.sex} 0 or less.`);\n });\n return findings;\n}\n\n/**\n * This function gives each finding of a chain of tables. First come the findings of `checkCalorieTable` for each table,\n * in the order of the chain. Then come the findings of the cover. For each sex, the rows of all the tables cover each month from 0 to an\n * open last row (`needs-gap`, record `chain`). A row of a later table can overlap a row of an earlier table: the earlier\n * table gives the need. Two tables of the chain with the same `id` give `needs-id`.\n *\n * The limit of the first match: when an earlier table loses a row at its start, a later table can give those months.\n * Then the gate gives no finding. A caller that needs each month from one table tests the `id` of the table of each month.\n *\n * A list with no error tells that the gate passes. The function is pure.\n *\n * @param tables - One table, or tables in order\n * @param options - The options of the gate of the sources, for example the date of the gate\n */\nexport function checkCalorieChain(tables: CalorieTables, options?: GateOptions): NeedsFinding[] {\n const list = \"rows\" in tables ? [tables] : tables;\n const findings = list.flatMap((table) => checkCalorieTable(table, options));\n const id = list.map((table) => table.id).join(\" + \");\n const add = (message: string, code: NeedsCode = \"needs-gap\"): void => {\n findings.push({ level: \"error\", code, record: \"chain\", id, message });\n };\n if (list.length === 0) add(\"The chain has no table.\");\n list.forEach((table, index) => {\n if (list.findIndex((other) => other.id === table.id) < index) add(`The chain has the table ${table.id} two times or more.`, \"needs-id\");\n });\n for (const sex of CALORIE_SEXES) {\n const rows = list.flatMap((table) => table.rows).filter((row) => row.sex === sex && Number.isSafeInteger(row.from) && row.from >= 0);\n if (rows.length === 0) {\n add(`The tables have no row of a ${sex}.`);\n continue;\n }\n rows.sort((a, b) => a.from - b.from);\n // The first month with no row so far. It is Infinity after an open row.\n let next = 0;\n for (const row of rows) {\n if (row.from > next) add(`The tables have no row of a ${sex} for the months ${String(next)} to ${String(row.from - 1)}.`);\n next = Math.max(next, row.to === undefined ? Infinity : row.to + 1);\n }\n if (next !== Infinity) add(`The rows of a ${sex} end at ${String(next - 1)} months. The chain has no open last row.`);\n }\n return findings;\n}\n\n/** This function tells if a list of findings has an error. */\nexport function hasNeedsError(findings: readonly NeedsFinding[]): boolean {\n return findings.some((finding) => finding.level === \"error\");\n}\n","import type { Finding } from \"@mark1russell7/guidebook\";\nimport type { SupplyCatalog } from \"@mark1russell7/market/supplies\";\nimport { valueIn } from \"@mark1russell7/quantity\";\n\n// The uses and the supply parts of the needs, and the gate of their joins with the reference lists.\n// An add-on does not import a different add-on. Thus the reference lists are parameters, and a test joins the real lists.\n\n/** The code of the need of the food draw: food energy, in `kcal` for each day. */\nexport const FOOD_NEED = \"food.energy\";\n\n/** The code of the need of drinking water, in `L` for each day. */\nexport const WATER_NEED = \"hydration.drink\";\n\n/** The resource of the food to eat with no water and no fuel, in `kcal`. It has a direct use for the food draw. */\nexport const NO_COOK = \"food.no-cook\";\n\n/** The resource of the stored drinking water, in `L`. It has a direct use for the water need. */\nexport const STORED_WATER = \"water.stored\";\n\n/** The direct use of a resource for a need: 1 unit of the resource gives `amount` of the need. */\nexport interface FragmentDirectUse {\n readonly resource: string;\n readonly need: string;\n readonly amount: number;\n}\n\n/**\n * The default reference part that supplies each need when no case stops it, by the code of the need.\n * The parts are `id` values of `SUPPLY_PARTS` of `@mark1russell7/stack-hazards`. A household with a well gives a different part.\n * The type has the exact keys. The annotation replaces `as const`, because the package has isolated declarations.\n */\nexport const NEED_SUPPLIES: { readonly \"hydration.drink\": \"water.main\"; readonly \"food.energy\": \"food.retail\" } = {\n \"hydration.drink\": \"water.main\",\n \"food.energy\": \"food.retail\",\n};\n\n/**\n * The direct uses of the resources of the buy list. Each use gives 1 unit of its need for each unit of its resource.\n *\n * - 1 L of stored drinking water gives 1 L of drink. This is a definition, not a read.\n * - 1 kcal of food to eat with no water and no fuel gives 1 kcal of food energy.\n *\n * These records have the form of `DirectUse` of `@mark1russell7/stack-endurance`.\n */\nexport const DIRECT_USES: readonly FragmentDirectUse[] = [\n { resource: STORED_WATER, need: WATER_NEED, amount: 1 },\n { resource: NO_COOK, need: FOOD_NEED, amount: 1 },\n];\n\n/**\n * These are the codes of the join gate. Each code is an error.\n *\n * - `join-use-resource`: a direct use names a resource that is not in the catalog.\n * - `join-use-need`: a direct use names a need that is not in the reference needs.\n * - `join-use-unit`: the unit of the resource of a direct use does not convert to the unit of its need.\n * - `join-use-amount`: the amount of a direct use is not the factor from the unit of its resource to the unit of its need.\n * - `join-supply-need`: a supply names a need that is not in the reference needs.\n * - `join-supply-part`: a supply names a part that is not in the reference parts.\n */\nexport const JOIN_CODES: readonly [\"join-use-resource\", \"join-use-need\", \"join-use-unit\", \"join-use-amount\", \"join-supply-need\", \"join-supply-part\"] = [\n \"join-use-resource\",\n \"join-use-need\",\n \"join-use-unit\",\n \"join-use-amount\",\n \"join-supply-need\",\n \"join-supply-part\",\n];\n\n/** A code of the join gate. */\nexport type JoinCode = (typeof JOIN_CODES)[number];\n\n/**\n * A finding of the join gate, in the form of a finding of `@mark1russell7/guidebook`. Each finding of the gate is an error.\n * The record is `use` for a direct use, with the resource of the use as its `id`. It is `supply` for a supply, with the need as its `id`.\n */\nexport type JoinFinding = Finding<JoinCode, \"use\" | \"supply\">;\n\n/** This function gives the factor from a unit to a different unit, or `undefined` when the units do not convert. */\nfunction factorOf(from: string, to: string): number | undefined {\n try {\n const factor = valueIn({ value: 1, unit: from }, to);\n return Number.isFinite(factor) ? factor : undefined;\n } catch {\n return undefined;\n }\n}\n\n/** A reference need: its code and its unit. Each record of `NEEDS` of `@mark1russell7/alerts` has this form. */\nexport interface ReferenceNeed {\n readonly code: string;\n readonly unit: string;\n}\n\n/** A reference part: its `id`. Each record of `SUPPLY_PARTS` of `@mark1russell7/stack-hazards` has this form. */\nexport interface ReferencePart {\n readonly id: string;\n}\n\n/** The reference lists of the join gate. */\nexport interface JoinReferences {\n /** The reference needs, for example `NEEDS` of `@mark1russell7/alerts`. */\n readonly needs: readonly ReferenceNeed[];\n /** The reference parts, for example `SUPPLY_PARTS` of `@mark1russell7/stack-hazards`. */\n readonly parts: readonly ReferencePart[];\n}\n\n/**\n * This function examines the joins of a catalog, the direct uses and the supply parts with the reference lists.\n *\n * - The resource of each direct use is a resource of the catalog, and its need is a reference need.\n * - The unit of the resource of each direct use converts to the unit of its need.\n * - The amount of each direct use is the factor of that conversion. A direct use is a definition, so a different rate is a converter with a cited source.\n * - Each supply names a reference need and a reference part.\n *\n * The findings are in the order of the uses, then in the order of the supplies. The function is pure.\n *\n * @param catalog - The catalog of supplies of `@mark1russell7/market`\n * @param uses - The direct uses, for example `DIRECT_USES`\n * @param supplies - The part that supplies each need, by the code of the need, for example `NEED_SUPPLIES`\n * @param references - The reference needs and the reference parts\n * @returns The findings of the joins. An empty list is a pass.\n */\nexport function checkJoins(\n catalog: SupplyCatalog,\n uses: readonly FragmentDirectUse[],\n supplies: Readonly<Record<string, string>>,\n references: JoinReferences,\n): JoinFinding[] {\n const findings: JoinFinding[] = [];\n const add = (code: JoinCode, record: \"use\" | \"supply\", id: string, message: string): void => {\n findings.push({ level: \"error\", code, record, id, message });\n };\n const units = new Map(catalog.resources.map((resource) => [resource.code, resource.unit] as const));\n const needs = new Map(references.needs.map((need) => [need.code, need.unit] as const));\n for (const use of uses) {\n const unit = units.get(use.resource);\n const needUnit = needs.get(use.need);\n if (unit === undefined) add(\"join-use-resource\", \"use\", use.resource, `The direct use of ${use.resource} names no resource of the catalog.`);\n if (needUnit === undefined) add(\"join-use-need\", \"use\", use.resource, `The direct use of ${use.resource} names the need ${use.need}, which is not a reference need.`);\n if (unit === undefined || needUnit === undefined) continue;\n const factor = factorOf(unit, needUnit);\n if (factor === undefined) {\n add(\"join-use-unit\", \"use\", use.resource, `The direct use of ${use.resource} for ${use.need} takes ${unit}, which does not convert to ${needUnit}.`);\n } else if (use.amount !== factor) {\n add(\n \"join-use-amount\",\n \"use\",\n use.resource,\n `The direct use of ${use.resource} for ${use.need} gives ${String(use.amount)} ${needUnit} for each ${unit}, not ${String(factor)}. A direct use is a definition: a different rate is a converter with a cited source.`,\n );\n }\n }\n const parts = new Set(references.parts.map((part) => part.id));\n for (const [need, part] of Object.entries(supplies)) {\n if (!needs.has(need)) add(\"join-supply-need\", \"supply\", need, `The supply of ${need} names no reference need.`);\n if (!parts.has(part)) add(\"join-supply-part\", \"supply\", need, `The supply of ${need} names the part ${part}, which is not a reference part.`);\n }\n return findings;\n}\n","import { buyListEnergy, giftsOf, type BuyListEnergy, type SupplyCatalog } from \"@mark1russell7/market/supplies\";\nimport { calorieNeed, type ActivityLevel, type CalorieNeedTotal, type CalorieTables, type Person } from \"./calorie.ts\";\nimport { CALORIE_CHAIN } from \"./data.ts\";\nimport { DIRECT_USES, FOOD_NEED, NEED_SUPPLIES, type FragmentDirectUse } from \"./uses.ts\";\n\n// The join of a household and a buy list into a fragment of an endurance layer: one draw of food energy and the stores of the list.\n// The records have the form of the records of `@mark1russell7/stack-endurance`. An add-on does not import a different add-on, so the form is a copy.\n// A test assigns the layer to `EnduranceLayer` of stack-endurance. That test is the type gate of the copy.\n// The fragment has no converter. No cited source gives the water and the fuel to cook 1 kg of dry food, and a number with no source is not data.\n\n/** A resource of a store, with its unit. */\nexport interface FragmentResource {\n readonly code: string;\n readonly unit: string;\n}\n\n/** A store of the buy list: an amount of one resource, in its unit. */\nexport interface FragmentStore {\n readonly id: string;\n readonly resource: string;\n readonly amount: number;\n}\n\n/** The food draw: the food energy of the persons of the draw for each day. */\nexport interface FragmentDraw {\n readonly need: string;\n readonly level: string;\n /** The food energy of the persons of the draw for each day, in `kcal`. It is above 0. */\n readonly perDay: number;\n /** The count of the persons of the draw. */\n readonly users: number;\n readonly supply: string;\n}\n\n/** A fragment of an endurance layer, with the form of `EnduranceLayer` of `@mark1russell7/stack-endurance`. It has no converter. */\nexport interface HouseholdFragment {\n /** The format of an endurance layer, `endurance/1`. */\n readonly schema: \"endurance/1\";\n readonly levels: readonly string[];\n readonly resources: readonly FragmentResource[];\n readonly stores: readonly FragmentStore[];\n readonly draws: readonly FragmentDraw[];\n readonly direct: readonly FragmentDirectUse[];\n}\n\n/** The action for the persons with no row in the table. The only action is `leave-out`. */\nexport type NoRowAction = \"leave-out\";\n\n/** The inputs of the household fragment. */\nexport interface HouseholdFragmentInput {\n /** The person records of the household. */\n readonly persons: readonly Person[];\n /** The activity level of each person record with no level of its own. It has no default. */\n readonly activity: ActivityLevel;\n /** The catalog of supplies of `@mark1russell7/market`. */\n readonly catalog: SupplyCatalog;\n /** The count of units of each product of the buy list, by the `id` of the product. */\n readonly units: Readonly<Record<string, number>>;\n /** The `id` of the part of the stack that supplies the food when no case stops it. The default is `NEED_SUPPLIES[\"food.energy\"]`, `food.retail`. */\n readonly supply?: string | undefined;\n /** The direct uses. The fragment takes each use for the need `food.energy`. The default is `DIRECT_USES`. */\n readonly uses?: readonly FragmentDirectUse[] | undefined;\n /** The level of the food draw. It is one of the levels of the joined layer. */\n readonly level: string;\n /** The levels of the fragment. The default is no levels: a different fragment of the stack gives them. */\n readonly levels?: readonly string[] | undefined;\n /** The table of calorie needs, or tables in order. The default is `CALORIE_CHAIN`, which gives a row for each age. */\n readonly table?: CalorieTables | undefined;\n /** The start of the `id` of each store. The default is `buy`. */\n readonly prefix?: string | undefined;\n /**\n * The action for the persons with no row in the table. Without it, a person with no row gives no layer.\n * With `leave-out`, the draw has no need of those persons, and the result lists them.\n */\n readonly noRow?: NoRowAction | undefined;\n}\n\n/** A gift of the buy list with no read. The fragment has no store for it. A no read is not 0. */\nexport interface GiftNoRead {\n readonly product: string;\n readonly resource: string;\n readonly why: string;\n}\n\n/** The parts of the result that do not change with the draw. */\nexport interface HouseholdStoresResult {\n /** The food energy of each product of the buy list. A caller gets the energy of the dry food for its converters from it. */\n readonly energy: BuyListEnergy;\n /** The gifts of the buy list with no read. */\n readonly noReads: readonly GiftNoRead[];\n /** True when each gift of the buy list has a read. When it is false, the stores are a lower limit. */\n readonly storesRead: boolean;\n}\n\n/** The household fragment with its draw. The draw is exact for its users. */\nexport interface HouseholdFragmentRead extends HouseholdStoresResult {\n readonly layer: HouseholdFragment;\n /**\n * The food energy of the household for one day, with a line for each person record. Its `read` covers the whole\n * household. It is false when a person is left out, or when a record with count 0 has no row. The flag of the draw\n * is `needRead`.\n */\n readonly need: CalorieNeedTotal;\n /** This field is true: the draw has a read for each of its users. */\n readonly needRead: true;\n /** The persons with no row that the option `leave-out` left out of the draw. With no option, the list is empty. */\n readonly leftOut: readonly Person[];\n}\n\n/** No household fragment: the draw has no read. A low rate gives too many days, so the function gives no layer. */\nexport interface HouseholdFragmentNoRead extends HouseholdStoresResult {\n readonly layer: undefined;\n /** The food energy of the household for one day. It is `undefined` when the household has no person. */\n readonly need: CalorieNeedTotal | undefined;\n readonly needRead: false;\n /** The persons with no row in the table. */\n readonly noRow: readonly Person[];\n /** The reason for no layer. */\n readonly why: string;\n}\n\n/** The household fragment, or a no read of the draw. Both have the reads of the buy list. */\nexport type HouseholdFragmentResult = HouseholdFragmentRead | HouseholdFragmentNoRead;\n\n/** This function gives the stores of the buy list, its resources and its gifts with no read. */\nfunction buyListStores(\n input: HouseholdFragmentInput,\n foodUses: readonly FragmentDirectUse[],\n): { stores: FragmentStore[]; resources: FragmentResource[]; parts: HouseholdStoresResult } {\n const { catalog, units } = input;\n const energy = buyListEnergy(catalog, units);\n const unitOf = new Map(catalog.resources.map((resource) => [resource.code, resource.unit]));\n for (const use of foodUses) {\n if (unitOf.get(use.resource) !== \"kcal\") throw new RangeError(`The catalog has no resource \"${use.resource}\" in kcal for the food use.`);\n }\n const prefix = input.prefix ?? \"buy\";\n const stores: FragmentStore[] = [];\n const noReads: GiftNoRead[] = [];\n for (const [product, count] of Object.entries(units)) {\n for (const gift of giftsOf(catalog, product, count)) {\n if (!gift.read) noReads.push({ product, resource: gift.resource, why: gift.why });\n else if (gift.amount > 0) stores.push({ id: `${prefix}:${product}:${gift.resource}`, resource: gift.resource, amount: gift.amount });\n }\n }\n const codes = [...new Set([...stores.map((store) => store.resource), ...foodUses.map((use) => use.resource)])];\n const resources = codes.map((code) => ({ code, unit: unitOf.get(code) ?? \"\" }));\n return { stores, resources, parts: { energy, noReads, storesRead: noReads.length === 0 } };\n}\n\n/**\n * This function joins a household and a buy list into a fragment of an endurance layer.\n *\n * - The fragment has one draw of food energy. Its rate is the need of the persons for one day, and its users are the persons.\n * - Each gift of the buy list with a read is one store, with the `id` `<prefix>:<product>:<resource>`. A gift with no read has no store.\n * - The direct uses are the food uses: each use of `uses` for the need `food.energy`. The default `DIRECT_USES` gives `food.no-cook`, 1 kcal for each kcal.\n * - The resources are the resources of the stores and of the food uses, with the units of the catalog.\n * - The supply part of the draw is `supply`. Its default is the part of `NEED_SUPPLIES` for `food.energy`.\n * - The fragment has no converter. A caller adds converters for the dry food, with the water and the fuel of each run.\n *\n * A person with no row in the tables gives no layer, because a low rate gives too many days. The default tables give a row for each age.\n * The option `noRow: \"leave-out\"` leaves those persons out of the draw. A draw of 0 kcal gives no layer.\n * The function is pure.\n *\n * @param input - The persons, the activity level, the catalog and the buy list, the supply part and the level of the draw\n * @returns The fragment or a no read of the draw, with the energy of the list and the gifts with no read\n * @throws RangeError for the errors of `calorieNeed`, `giftsOf` and `buyListEnergy`, except a household with no person\n * @throws RangeError when the catalog has no resource in `kcal` for a food use\n */\nexport function householdFragment(input: HouseholdFragmentInput): HouseholdFragmentResult {\n const foodUses = (input.uses ?? DIRECT_USES).filter((use) => use.need === FOOD_NEED);\n const { stores, resources, parts } = buyListStores(input, foodUses);\n if (input.persons.every((person) => person.count === 0)) {\n return { ...parts, layer: undefined, need: undefined, needRead: false, noRow: [], why: \"The household has no person, so the draw is 0 kcal.\" };\n }\n const need = calorieNeed(input.table ?? CALORIE_CHAIN, input.persons, input.activity, 1);\n const noRow: Person[] = [];\n let users = 0;\n for (const line of need.lines) {\n if (line.read) users += line.person.count;\n else if (line.person.count > 0) noRow.push(line.person);\n }\n if (noRow.length > 0 && input.noRow !== \"leave-out\") {\n return { ...parts, layer: undefined, need, needRead: false, noRow, why: `The table has no row for ${String(noRow.length)} person records. The option noRow: \"leave-out\" leaves them out of the draw.` };\n }\n if (users === 0 || need.need.value <= 0) {\n return { ...parts, layer: undefined, need, needRead: false, noRow, why: \"No person of the draw has a row in the table, so the draw is 0 kcal.\" };\n }\n const draw: FragmentDraw = { need: FOOD_NEED, level: input.level, perDay: need.need.value, users, supply: input.supply ?? NEED_SUPPLIES[FOOD_NEED] };\n return {\n ...parts,\n layer: {\n schema: \"endurance/1\",\n levels: [...(input.levels ?? [])],\n resources,\n stores,\n draws: [draw],\n direct: foodUses.map((use) => ({ ...use })),\n },\n need,\n needRead: true,\n leftOut: noRow,\n };\n}\n"],"mappings":";;;;;AAQA,MAAa,kBAAyE;CAAC;CAAa;CAAqB;AAAQ;;AAMjI,MAAa,gBAA6C,CAAC,UAAU,MAAM;;AA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OAAO;EAAE,GAAG;EAAO,OAAO,KAAA;EAAW,MAAM,KAAA;EAAW,UAAU;EAAO,OAAO,CAAC;EAAG,KAAK;CAAsD;CAE/I,MAAM,OAAO,YAAY,MAAM,SAAS,eAAe,MAAM,SAAS,MAAM,UAAU,CAAC;CACvF,MAAM,QAAkB,CAAC;CACzB,IAAI,QAAQ;CACZ,KAAK,MAAM,QAAQ,KAAK,OACtB,IAAI,KAAK,MAAM,SAAS,KAAK,OAAO;MAC/B,IAAI,KAAK,OAAO,QAAQ,GAAG,MAAM,KAAK,KAAK,MAAM;CAExD,IAAI,MAAM,SAAS,KAAK,MAAM,UAAU,aACtC,OAAO;EAAE,GAAG;EAAO,OAAO,KAAA;EAAW;EAAM,UAAU;EAAO;EAAO,KAAK,4BAA4B,OAAO,MAAM,MAAM,EAAE;CAA6E;CAExM,IAAI,UAAU,KAAK,KAAK,KAAK,SAAS,GACpC,OAAO;EAAE,GAAG;EAAO,OAAO,KAAA;EAAW;EAAM,UAAU;EAAO;EAAO,KAAK;CAAuE;CAEjJ,MAAM,OAAqB;EAAE,MAAM;EAAW,OAAO,MAAM;EAAO,QAAQ,KAAK,KAAK;EAAO;EAAO,QAAQ,MAAM,UAAU,cAAA;CAAyB;CACnJ,OAAO;EACL,GAAG;EACH,OAAO;GACL,QAAQ;GACR,QAAQ,CAAC,GAAI,MAAM,UAAU,CAAC,CAAE;GAChC;GACA;GACA,OAAO,CAAC,IAAI;GACZ,QAAQ,SAAS,KAAK,SAAS,EAAE,GAAG,IAAI,EAAE;EAC5C;EACA;EACA,UAAU;EACV,SAAS;CACX;AACF"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/calorie.ts","../src/data.ts","../src/check.ts","../src/uses.ts","../src/household.ts"],"sourcesContent":["import { quantity, valueIn, type Quantity } from \"@mark1russell7/quantity\";\nimport type { Source } from \"@mark1russell7/guidebook\";\n\n// The energy need of the persons of a household, from a cited table of estimated calorie needs.\n// The package names no person. The persons and their activity level are input data.\n// A person record has a sex, an age in months and a count. Each table finds its own row from its own age ranges.\n\n/** The activity levels of the table, as the source names them: sedentary, moderately active and active. */\nexport const ACTIVITY_LEVELS: readonly [\"sedentary\", \"moderately-active\", \"active\"] = [\"sedentary\", \"moderately-active\", \"active\"];\n\n/** An activity level of the table. */\nexport type ActivityLevel = (typeof ACTIVITY_LEVELS)[number];\n\n/** The sexes of the table. */\nexport const CALORIE_SEXES: readonly [\"female\", \"male\"] = [\"female\", \"male\"];\n\n/** A sex of the table. */\nexport type CalorieSex = (typeof CALORIE_SEXES)[number];\n\n/**\n * The estimated calorie need of one person of a row for each day. A row gives a need for each activity level, or one need for all levels.\n * The table of the toddlers gives one need for each age and sex only. Each need has a unit of energy for each day, for example `{ \"value\": 2000, \"unit\": \"kcal/d\" }`.\n */\nexport type CalorieNeed = { readonly levels: Readonly<Record<ActivityLevel, Quantity>>; readonly each?: never } | { readonly each: Quantity; readonly levels?: never };\n\n/** A row of a table of calorie needs: a sex, a range of ages in months, and the need. */\nexport interface CalorieRow {\n readonly sex: CalorieSex;\n /** The age as the source names it, for example `19-20` (years) or `21 through 23 months`. */\n readonly age: string;\n /** The first age of the row, in whole months. */\n readonly from: number;\n /** The last age of the row, in whole months. Without it, the row applies to each larger age. */\n readonly to?: number | undefined;\n readonly need: CalorieNeed;\n}\n\n/**\n * A change of the daily need of a person at a stage, for example the second trimester of a pregnancy. The change adds\n * to the need of the row of the person. It can be 0.\n */\nexport interface CalorieChange {\n /** The id of the stage, for example `pregnancy-2`. */\n readonly stage: string;\n /** The stage as the source names it, for example `Pregnancy: 2nd trimester`. */\n readonly title: string;\n /** The sex of the persons of the stage. */\n readonly sex: CalorieSex;\n /** The change of the need for each day, in a unit of energy for each day, for example `{ \"value\": 340, \"unit\": \"kcal/d\" }`. */\n readonly change: Quantity;\n /** The condition of the source for the change, for example a healthy weight before the pregnancy. */\n readonly condition?: string | undefined;\n /** True when the persons of the stage make the milk of an infant: a stage of lactation. */\n readonly milk?: true | undefined;\n}\n\n/** A table of estimated calorie needs from one source. */\nexport interface CalorieTable {\n /** The id, for example `dga.2020-2025:calorie-needs`. */\n readonly id: string;\n readonly title: string;\n readonly source: Source;\n /** The place of the tables in the source: the tables and their pages. */\n readonly locator: string;\n /** The rows of the table. The age ranges of the rows of one sex do not overlap. */\n readonly rows: readonly CalorieRow[];\n /** The changes of the need at each stage. The stage and the sex of each change are unique. */\n readonly changes?: readonly CalorieChange[] | undefined;\n}\n\n/**\n * One table, or tables in order. For each person, the first table with a row for the age gives the need.\n * An example is `CALORIE_CHAIN`: the guidelines from 12 months, and the infant table below 12 months.\n */\nexport type CalorieTables = CalorieTable | readonly CalorieTable[];\n\n/**\n * The ways to feed an infant.\n *\n * - `breast-milk`: only the milk of a person of the household.\n * - `formula`: infant formula.\n * - `food`: the food of the household, also with milk.\n */\nexport const INFANT_FEEDINGS: readonly [\"breast-milk\", \"formula\", \"food\"] = [\"breast-milk\", \"formula\", \"food\"];\n\n/** A way to feed an infant. */\nexport type InfantFeeding = (typeof INFANT_FEEDINGS)[number];\n\n/** A group of persons of the same sex and age, and their count. */\nexport interface Person {\n readonly sex: CalorieSex;\n /** The age, in whole months, for example 420 for 35 years. */\n readonly ageMonths: number;\n readonly count: number;\n /** The activity level of the persons. Without it, the level of the call applies. */\n readonly level?: ActivityLevel | undefined;\n /** The stage of the persons, for example `pregnancy-2`: the stage of a change of the table. Without it, no change applies. */\n readonly stage?: string | undefined;\n /**\n * The way to feed the persons. The household fragment must have it for each record below `INFANT_MONTHS`.\n * `calorieNeed` does not read it, because the energy need is the same.\n */\n readonly feeding?: InfantFeeding | undefined;\n}\n\n/** The need of one person record for the days, or no read when the table has no row for the age. */\nexport type CalorieNeedLine =\n | { readonly person: Person; readonly read: true; readonly level: ActivityLevel; readonly table: string; readonly row: string; readonly stage?: string | undefined; readonly need: Quantity }\n | { readonly person: Person; readonly read: false; readonly why: string };\n\n/** The energy need of the persons of a household for a count of days. */\nexport interface CalorieNeedTotal {\n /** The need of each person record, in the order of the input. */\n readonly lines: readonly CalorieNeedLine[];\n /** True when each line has a read. When it is false, `need` is a lower limit. */\n readonly read: boolean;\n /** The sum of the needs of the lines with a read, in `kcal`. */\n readonly need: Quantity;\n /** The count of the persons of all the records, also of the records with no read. */\n readonly persons: number;\n}\n\n/** The unit of each food energy. */\nconst ENERGY_UNIT = \"kcal\";\n/** The unit of each daily need. */\nconst DAILY_UNIT = \"kcal/d\";\n\n/** This function tells if a value is an activity level of the table. */\nexport function isActivityLevel(level: unknown): level is ActivityLevel {\n return (ACTIVITY_LEVELS as readonly unknown[]).includes(level);\n}\n\n/**\n * This function gives the row of a table for a sex and an age in months, or `undefined` when the table has no row.\n *\n * @param table - The table of calorie needs\n * @param sex - The sex\n * @param ageMonths - The age, in whole months\n */\nexport function calorieRow(table: CalorieTable, sex: CalorieSex, ageMonths: number): CalorieRow | undefined {\n return table.rows.find((row) => row.sex === sex && ageMonths >= row.from && (row.to === undefined || ageMonths <= row.to));\n}\n\n/**\n * This function gives the first table with a row for a sex and an age in months, and its row.\n * It gives `undefined` when no table has a row.\n *\n * @param tables - One table, or tables in order\n * @param sex - The sex\n * @param ageMonths - The age, in whole months\n */\nexport function calorieRowOf(tables: CalorieTables, sex: CalorieSex, ageMonths: number): { readonly table: CalorieTable; readonly row: CalorieRow } | undefined {\n for (const table of tableList(tables)) {\n const row = calorieRow(table, sex, ageMonths);\n if (row !== undefined) return { table, row };\n }\n return undefined;\n}\n\n/** This function gives the tables of the input as a list. */\nfunction tableList(tables: CalorieTables): readonly CalorieTable[] {\n return \"rows\" in tables ? [tables] : tables;\n}\n\n/**\n * This function gives the change of a table for a sex and a stage, or `undefined` when the table has no such change.\n *\n * @param table - The table of calorie needs\n * @param sex - The sex\n * @param stage - The id of the stage, for example `pregnancy-2`\n */\nexport function calorieChange(table: CalorieTable, sex: CalorieSex, stage: string): CalorieChange | undefined {\n return table.changes?.find((change) => change.sex === sex && change.stage === stage);\n}\n\n/**\n * This function gives the energy need of the persons of a household for a count of days, in `kcal`.\n * It adds the need of each person at the activity level of that person. The first table with a row for the age of a person gives the row.\n *\n * - An age with no row in the tables gives a line with no read, for example 6 months in `DGA_CALORIES` alone. Then the total is a lower limit.\n * - Each line with a read has the `id` of the table of its row.\n * - The table of the toddlers gives one need for each age and sex. Thus the level does not change the need of a toddler.\n * - A record with a stage adds the change of the stage to the need of its row, for example 340 kcal/d in the second trimester. The change comes from the table of the row.\n * - One stage holds for each day of the call. For a period that crosses stages, the planner selects the stage, for example the stage with the largest change.\n *\n * The activity level is an explicit input. This package has no default level. The planner selects it, also for the worst case of a long power cut.\n * In that case, work can make the level higher, for example the carry of water. The function is pure.\n *\n * @param tables - The table of calorie needs, or tables in order\n * @param persons - The person records of the household: a sex, an age in months, a count and, as an option, a level\n * @param level - The activity level of each record with no level of its own\n * @param days - The count of days, a finite number of 0 or more\n * @throws RangeError when a count of persons or an age is not a whole number of 0 or more, or when the household has no person\n * @throws RangeError when a level is not a level of the table, or when a sex is not a sex of the table\n * @throws RangeError when the count of days is not a finite number of 0 or more, or when the list of tables is empty\n * @throws RangeError when no table has the change for the stage and the sex of a record\n * @throws RangeError when the table of the row of a record has no change for the stage and the sex of the record\n * @throws RangeError when the daily need of a record, with the change of its stage, is not above 0\n */\nexport function calorieNeed(tables: CalorieTables, persons: readonly Person[], level: ActivityLevel, days: number): CalorieNeedTotal {\n if (!(Number.isFinite(days) && days >= 0)) throw new RangeError(`The count of days is ${String(days)}. It must be a finite number of 0 or more.`);\n if (!isActivityLevel(level)) throw new RangeError(`The activity level ${String(level)} is not a level of the table.`);\n const list = tableList(tables);\n if (list.length === 0) throw new RangeError(\"The list of tables is empty.\");\n const ids = list.map((table) => table.id).join(\", \");\n let count = 0;\n const lines = persons.map((person): CalorieNeedLine => {\n const name = `${String(person.sex)} of ${String(person.ageMonths)} months`;\n if (!(Number.isSafeInteger(person.count) && person.count >= 0)) throw new RangeError(`The count of the persons ${name} is ${String(person.count)}. It must be a whole number of 0 or more.`);\n if (!(Number.isSafeInteger(person.ageMonths) && person.ageMonths >= 0)) throw new RangeError(`The age of the persons ${name} is not a whole number of months of 0 or more.`);\n if (!(CALORIE_SEXES as readonly unknown[]).includes(person.sex)) throw new RangeError(`The sex ${String(person.sex)} is not a sex of the table.`);\n const own = person.level ?? level;\n if (!isActivityLevel(own)) throw new RangeError(`The activity level ${String(own)} of the persons ${name} is not a level of the table.`);\n // A stage that the table does not have is an error, not a no read: the option leave-out would remove the persons from a draw.\n const { stage } = person;\n if (stage !== undefined && list.every((table) => calorieChange(table, person.sex, stage) === undefined)) throw new RangeError(`The tables ${ids} have no change for the stage ${String(stage)} of the persons ${name}.`);\n count += person.count;\n const found = calorieRowOf(list, person.sex, person.ageMonths);\n if (found === undefined) return { person, read: false, why: `The tables ${ids} have no row for a ${name}.` };\n const { table, row } = found;\n const change = stage === undefined ? undefined : calorieChange(table, person.sex, stage);\n if (stage !== undefined && change === undefined) throw new RangeError(`The table ${table.id} of the row of the persons ${name} has no change for the stage ${String(stage)}.`);\n const daily = valueIn(row.need.levels === undefined ? row.need.each : row.need.levels[own], DAILY_UNIT) + (change === undefined ? 0 : valueIn(change.change, DAILY_UNIT));\n if (!(daily > 0)) throw new RangeError(`The daily need of the persons ${name} at the stage ${String(person.stage)} is ${String(daily)} kcal/d. It must be above 0.`);\n const line = { person, read: true as const, level: own, table: table.id, row: row.age, need: quantity(person.count * daily * days, ENERGY_UNIT) };\n return change === undefined ? line : { ...line, stage: change.stage };\n });\n if (count === 0) throw new RangeError(\"The household has no person.\");\n const total = lines.reduce((sum, line) => sum + (line.read ? line.need.value : 0), 0);\n return { lines, read: lines.every((line) => line.read), need: quantity(total, ENERGY_UNIT), persons: count };\n}\n","import type { CalorieChange, CalorieNeed, CalorieTable } from \"./calorie.ts\";\nimport type { Source } from \"@mark1russell7/guidebook\";\n\n// The estimated calorie needs of the Dietary Guidelines for Americans, 2020-2025. Each value is from the tables of\n// Appendix 2 of the PDF, read on 2026-11-22. A calorie of the source is a food calorie, thus 1 kcal. The source gives\n// each need for a reference height and weight, to keep the weight of a person. A person can need more or less.\n// The rows of the toddlers are at 12, 15, 18 and 21 through 23 months. Each row here covers the months up to the next row.\n// The changes of pregnancy and lactation are from Table A2-3. The source gives them for women with a healthy weight before\n// the pregnancy.\n// The notes b and c of Table A2-3 (page 141, read on 2026-11-24, the PDF of the recorded sha256) give the two changes of lactation:\n// - The 1st 6 months: 500 calories/day for the milk production, minus 170 calories/day for the weight loss after the birth. That is 330.\n// - The 2nd 6 months: 400 calories/day for the milk production. The source assumes a stable weight after 6 months.\n// Thus below 6 months, 170 kcal/d of the milk comes from the stores of the mother, and not from the food of the household.\n// The source gives the energy of the milk production of the mother, not the energy that the infant gets from the milk.\n// It gives no change for a mother of two or more infants.\n// The 2025-2030 edition of the guidelines (read on 2026-11-24) has no table of calorie needs. It sends the reader to the\n// DRI calculator of the USDA. Its daily servings by calorie level start at a calorie level and do not give a need. So\n// this table stays the table of the 2020-2025 edition.\n\n/** The source of the calorie table: the PDF of the Dietary Guidelines for Americans, 2020-2025, 9th Edition. It is a work of the United States federal government. */\nexport const DGA_SOURCE: Source = {\n id: \"dga-2020-2025\",\n title: \"Dietary Guidelines for Americans, 2020-2025, 9th Edition\",\n url: \"https://www.dietaryguidelines.gov/sites/default/files/2020-12/Dietary_Guidelines_for_Americans_2020-2025.pdf\",\n license: \"us-public-domain\",\n checked: \"2026-11-22\",\n by: \"U.S. Department of Agriculture and U.S. Department of Health and Human Services\",\n terms: \"https://www.dietaryguidelines.gov/policy-and-links\",\n sha256: \"ceea04ce1a7c13a95a170f3548ed3926ad6dd49599bd730fb58bc9c02711d16e\",\n};\n\nconst day = (value: number): { readonly value: number; readonly unit: string } => ({ value, unit: \"kcal/d\" });\nconst levels = (sedentary: number, moderate: number, active: number): CalorieNeed => ({ levels: { sedentary: day(sedentary), \"moderately-active\": day(moderate), active: day(active) } });\nconst each = (value: number): CalorieNeed => ({ each: day(value) });\nconst HEALTHY = \"For women with a healthy weight before the pregnancy. Other women ask their health care provider.\";\nconst change = (stage: string, title: string, value: number): CalorieChange => ({ stage, title, sex: \"female\", change: day(value), condition: HEALTHY });\nconst milk = (stage: string, title: string, value: number): CalorieChange => ({ ...change(stage, title, value), milk: true });\n\n/** The table of estimated calorie needs of the Dietary Guidelines for Americans, 2020-2025: 68 rows, 34 for each sex, and 5 changes of pregnancy and lactation. */\nexport const DGA_CALORIES: CalorieTable = {\n id: \"dga.2020-2025:calorie-needs\",\n title: \"Dietary Guidelines for Americans, 2020-2025: Estimated Calorie Needs\",\n source: DGA_SOURCE,\n locator: \"Appendix 2: Table A2-1 (ages 12 through 23 months, page 139), Table A2-2 (ages 2 and older, pages 140 and 141) and Table A2-3 (pregnancy and lactation, page 141)\",\n changes: [\n change(\"pregnancy-1\", \"Pregnancy: 1st trimester\", 0),\n change(\"pregnancy-2\", \"Pregnancy: 2nd trimester\", 340),\n change(\"pregnancy-3\", \"Pregnancy: 3rd trimester\", 452),\n milk(\"lactation-1\", \"Lactation: 1st 6 months\", 330),\n milk(\"lactation-2\", \"Lactation: 2nd 6 months\", 400),\n ],\n rows: [\n { sex: \"female\", age: \"12 months\", from: 12, to: 14, need: each(800) },\n { sex: \"female\", age: \"15 months\", from: 15, to: 17, need: each(800) },\n { sex: \"female\", age: \"18 months\", from: 18, to: 20, need: each(900) },\n { sex: \"female\", age: \"21 through 23 months\", from: 21, to: 23, need: each(1000) },\n { sex: \"female\", age: \"2\", from: 24, to: 35, need: levels(1000, 1000, 1000) },\n { sex: \"female\", age: \"3\", from: 36, to: 47, need: levels(1000, 1200, 1400) },\n { sex: \"female\", age: \"4\", from: 48, to: 59, need: levels(1200, 1400, 1400) },\n { sex: \"female\", age: \"5\", from: 60, to: 71, need: levels(1200, 1400, 1600) },\n { sex: \"female\", age: \"6\", from: 72, to: 83, need: levels(1200, 1400, 1600) },\n { sex: \"female\", age: \"7\", from: 84, to: 95, need: levels(1200, 1600, 1800) },\n { sex: \"female\", age: \"8\", from: 96, to: 107, need: levels(1400, 1600, 1800) },\n { sex: \"female\", age: \"9\", from: 108, to: 119, need: levels(1400, 1600, 1800) },\n { sex: \"female\", age: \"10\", from: 120, to: 131, need: levels(1400, 1800, 2000) },\n { sex: \"female\", age: \"11\", from: 132, to: 143, need: levels(1600, 1800, 2000) },\n { sex: \"female\", age: \"12\", from: 144, to: 155, need: levels(1600, 2000, 2200) },\n { sex: \"female\", age: \"13\", from: 156, to: 167, need: levels(1600, 2000, 2200) },\n { sex: \"female\", age: \"14\", from: 168, to: 179, need: levels(1800, 2000, 2400) },\n { sex: \"female\", age: \"15\", from: 180, to: 191, need: levels(1800, 2000, 2400) },\n { sex: \"female\", age: \"16\", from: 192, to: 203, need: levels(1800, 2000, 2400) },\n { sex: \"female\", age: \"17\", from: 204, to: 215, need: levels(1800, 2000, 2400) },\n { sex: \"female\", age: \"18\", from: 216, to: 227, need: levels(1800, 2000, 2400) },\n { sex: \"female\", age: \"19-20\", from: 228, to: 251, need: levels(2000, 2200, 2400) },\n { sex: \"female\", age: \"21-25\", from: 252, to: 311, need: levels(2000, 2200, 2400) },\n { sex: \"female\", age: \"26-30\", from: 312, to: 371, need: levels(1800, 2000, 2400) },\n { sex: \"female\", age: \"31-35\", from: 372, to: 431, need: levels(1800, 2000, 2200) },\n { sex: \"female\", age: \"36-40\", from: 432, to: 491, need: levels(1800, 2000, 2200) },\n { sex: \"female\", age: \"41-45\", from: 492, to: 551, need: levels(1800, 2000, 2200) },\n { sex: \"female\", age: \"46-50\", from: 552, to: 611, need: levels(1800, 2000, 2200) },\n { sex: \"female\", age: \"51-55\", from: 612, to: 671, need: levels(1600, 1800, 2200) },\n { sex: \"female\", age: \"56-60\", from: 672, to: 731, need: levels(1600, 1800, 2200) },\n { sex: \"female\", age: \"61-65\", from: 732, to: 791, need: levels(1600, 1800, 2000) },\n { sex: \"female\", age: \"66-70\", from: 792, to: 851, need: levels(1600, 1800, 2000) },\n { sex: \"female\", age: \"71-75\", from: 852, to: 911, need: levels(1600, 1800, 2000) },\n { sex: \"female\", age: \"76 and up\", from: 912, need: levels(1600, 1800, 2000) },\n { sex: \"male\", age: \"12 months\", from: 12, to: 14, need: each(800) },\n { sex: \"male\", age: \"15 months\", from: 15, to: 17, need: each(900) },\n { sex: \"male\", age: \"18 months\", from: 18, to: 20, need: each(1000) },\n { sex: \"male\", age: \"21 through 23 months\", from: 21, to: 23, need: each(1000) },\n { sex: \"male\", age: \"2\", from: 24, to: 35, need: levels(1000, 1000, 1000) },\n { sex: \"male\", age: \"3\", from: 36, to: 47, need: levels(1000, 1400, 1400) },\n { sex: \"male\", age: \"4\", from: 48, to: 59, need: levels(1200, 1400, 1600) },\n { sex: \"male\", age: \"5\", from: 60, to: 71, need: levels(1200, 1400, 1600) },\n { sex: \"male\", age: \"6\", from: 72, to: 83, need: levels(1400, 1600, 1800) },\n { sex: \"male\", age: \"7\", from: 84, to: 95, need: levels(1400, 1600, 1800) },\n { sex: \"male\", age: \"8\", from: 96, to: 107, need: levels(1400, 1600, 2000) },\n { sex: \"male\", age: \"9\", from: 108, to: 119, need: levels(1600, 1800, 2000) },\n { sex: \"male\", age: \"10\", from: 120, to: 131, need: levels(1600, 1800, 2200) },\n { sex: \"male\", age: \"11\", from: 132, to: 143, need: levels(1800, 2000, 2200) },\n { sex: \"male\", age: \"12\", from: 144, to: 155, need: levels(1800, 2200, 2400) },\n { sex: \"male\", age: \"13\", from: 156, to: 167, need: levels(2000, 2200, 2600) },\n { sex: \"male\", age: \"14\", from: 168, to: 179, need: levels(2000, 2400, 2800) },\n { sex: \"male\", age: \"15\", from: 180, to: 191, need: levels(2200, 2600, 3000) },\n { sex: \"male\", age: \"16\", from: 192, to: 203, need: levels(2400, 2800, 3200) },\n { sex: \"male\", age: \"17\", from: 204, to: 215, need: levels(2400, 2800, 3200) },\n { sex: \"male\", age: \"18\", from: 216, to: 227, need: levels(2400, 2800, 3200) },\n { sex: \"male\", age: \"19-20\", from: 228, to: 251, need: levels(2600, 2800, 3000) },\n { sex: \"male\", age: \"21-25\", from: 252, to: 311, need: levels(2400, 2800, 3000) },\n { sex: \"male\", age: \"26-30\", from: 312, to: 371, need: levels(2400, 2600, 3000) },\n { sex: \"male\", age: \"31-35\", from: 372, to: 431, need: levels(2400, 2600, 3000) },\n { sex: \"male\", age: \"36-40\", from: 432, to: 491, need: levels(2400, 2600, 2800) },\n { sex: \"male\", age: \"41-45\", from: 492, to: 551, need: levels(2200, 2600, 2800) },\n { sex: \"male\", age: \"46-50\", from: 552, to: 611, need: levels(2200, 2400, 2800) },\n { sex: \"male\", age: \"51-55\", from: 612, to: 671, need: levels(2200, 2400, 2800) },\n { sex: \"male\", age: \"56-60\", from: 672, to: 731, need: levels(2200, 2400, 2600) },\n { sex: \"male\", age: \"61-65\", from: 732, to: 791, need: levels(2000, 2400, 2600) },\n { sex: \"male\", age: \"66-70\", from: 792, to: 851, need: levels(2000, 2200, 2600) },\n { sex: \"male\", age: \"71-75\", from: 852, to: 911, need: levels(2000, 2200, 2600) },\n { sex: \"male\", age: \"76 and up\", from: 912, need: levels(2000, 2200, 2400) },\n ],\n};\n\n// The Estimated Energy Requirements of the report Dietary Reference Intakes for Energy (2023) of the National Academies,\n// for the ages of 0 to 35 months. Each value is from Table 7-5 (boys, page 160) and Table 7-6 (girls, page 161) of the\n// PDF, read on 2026-11-24. The report gives each need for the median length and weight of the age group in the United\n// States (NHANES 2015-2018). The age groups are 3 months wide. The report predicts each group at one age, for example\n// 1 month for the group Birth-2.\n// The report is all rights reserved. The values are facts with a citation, and the gate of the sources permits them.\n// The Infant Nutrition and Feeding guide of the WIC program of the USDA (read on 2026-11-24) gives no table of daily needs.\n\n/** The source of the infant table: the PDF of the report Dietary Reference Intakes for Energy (2023) of the National Academies. */\nexport const NASEM_ENERGY_SOURCE: Source = {\n id: \"nasem-dri-energy-2023\",\n title: \"Dietary Reference Intakes for Energy (2023)\",\n url: \"https://nap.nationalacademies.org/26818\",\n license: \"all-rights-reserved\",\n checked: \"2026-11-24\",\n by: \"National Academies of Sciences, Engineering, and Medicine\",\n terms: \"https://nap.nationalacademies.org/26818\",\n note: \"DOI 10.17226/26818. The terms are on the first page of the PDF. The table cites its values as facts and copies no text.\",\n sha256: \"e6a7d9c9104053d4925c621b659b06de4c8dd6c64ed4534e6f5bc5cf0dd41b27\",\n};\n\n/**\n * The table of the Estimated Energy Requirements of the ages of 0 to 35 months, from the report Dietary Reference Intakes\n * for Energy (2023): 24 rows, 12 for each sex. Each row gives one need for each age group and sex. The last row ends at\n * 35 months, so the table is for a chain of tables, for example `CALORIE_CHAIN`.\n */\nexport const NASEM_INFANT_CALORIES: CalorieTable = {\n id: \"nasem.2023:eer-0-35-months\",\n title: \"Dietary Reference Intakes for Energy (2023): Estimated Energy Requirements of the ages of 0 to 35 months\",\n source: NASEM_ENERGY_SOURCE,\n locator: \"Chapter 7: Table 7-5 (boys of 0 to 35 months, page 160) and Table 7-6 (girls of 0 to 35 months, page 161)\",\n rows: [\n { sex: \"female\", age: \"Birth-2\", from: 0, to: 2, need: each(531) },\n { sex: \"female\", age: \"3-5\", from: 3, to: 5, need: each(546) },\n { sex: \"female\", age: \"6-8\", from: 6, to: 8, need: each(604) },\n { sex: \"female\", age: \"9-11\", from: 9, to: 11, need: each(689) },\n { sex: \"female\", age: \"12-14\", from: 12, to: 14, need: each(780) },\n { sex: \"female\", age: \"15-17\", from: 15, to: 17, need: each(817) },\n { sex: \"female\", age: \"18-20\", from: 18, to: 20, need: each(881) },\n { sex: \"female\", age: \"21-23\", from: 21, to: 23, need: each(956) },\n { sex: \"female\", age: \"24-26\", from: 24, to: 26, need: each(1011) },\n { sex: \"female\", age: \"27-29\", from: 27, to: 29, need: each(1051) },\n { sex: \"female\", age: \"30-32\", from: 30, to: 32, need: each(1122) },\n { sex: \"female\", age: \"33-35\", from: 33, to: 35, need: each(1192) },\n { sex: \"male\", age: \"Birth-2\", from: 0, to: 2, need: each(566) },\n { sex: \"male\", age: \"3-5\", from: 3, to: 5, need: each(589) },\n { sex: \"male\", age: \"6-8\", from: 6, to: 8, need: each(675) },\n { sex: \"male\", age: \"9-11\", from: 9, to: 11, need: each(745) },\n { sex: \"male\", age: \"12-14\", from: 12, to: 14, need: each(821) },\n { sex: \"male\", age: \"15-17\", from: 15, to: 17, need: each(881) },\n { sex: \"male\", age: \"18-20\", from: 18, to: 20, need: each(952) },\n { sex: \"male\", age: \"21-23\", from: 21, to: 23, need: each(1027) },\n { sex: \"male\", age: \"24-26\", from: 24, to: 26, need: each(1058) },\n { sex: \"male\", age: \"27-29\", from: 27, to: 29, need: each(1136) },\n { sex: \"male\", age: \"30-32\", from: 30, to: 32, need: each(1183) },\n { sex: \"male\", age: \"33-35\", from: 33, to: 35, need: each(1213) },\n ],\n};\n\n/** The tables of estimated calorie needs, one record for each source. */\nexport const CALORIE_TABLES: readonly CalorieTable[] = [DGA_CALORIES, NASEM_INFANT_CALORIES];\n\n/**\n * The default tables of `householdFragment`, in order: the guidelines first, then the infant table. The guidelines give\n * each age from 12 months. The infant table gives the ages below 12 months. Together they give a row for each age.\n */\nexport const CALORIE_CHAIN: readonly CalorieTable[] = [DGA_CALORIES, NASEM_INFANT_CALORIES];\n","import { checkSources, type Finding, type FindingCode, type GateOptions, type SourceField } from \"@mark1russell7/guidebook\";\nimport { valueIn, type Quantity } from \"@mark1russell7/quantity\";\nimport { ACTIVITY_LEVELS, CALORIE_SEXES, type CalorieRow, type CalorieTable, type CalorieTables } from \"./calorie.ts\";\n\n// The gate of a table of calorie needs: the gate of the sources of guidebook, and the rows.\n\n/**\n * These are the codes of the gate of the rows. Each code is an error. The gate of the sources of `@mark1russell7/guidebook` gives its own codes.\n *\n * - `needs-row`: a row has no age or a wrong sex. Or its range of months is not a range of whole numbers of 0 or more.\n * - `needs-overlap`: two rows of one sex have ages in common.\n * - `needs-gap`: the rows of one sex in a table have a gap between two rows. Or the rows of one sex in a chain of tables\n * do not cover each month from 0 to an open last row.\n * - `needs-value`: a need is not a finite number above 0 in a unit of energy for each day.\n * - `needs-change`: a change has no stage, no title or a wrong sex, or a stage with a space at an end. Or a different\n * change has its stage and sex. Or its value is not a finite number in a unit of energy for each day. Or its sum with\n * the smallest need of its sex is not above 0.\n * - `needs-id`: two tables of a chain have the same `id`. Each line of a need names its table by the `id`.\n */\nexport const NEEDS_CODES: readonly [\"needs-row\", \"needs-overlap\", \"needs-gap\", \"needs-value\", \"needs-change\", \"needs-id\"] = [\n \"needs-row\",\n \"needs-overlap\",\n \"needs-gap\",\n \"needs-value\",\n \"needs-change\",\n \"needs-id\",\n];\n\n/** A code of the gate of a table of calorie needs. */\nexport type NeedsCode = (typeof NEEDS_CODES)[number];\n\n/** A finding of the gate of a table of calorie needs: a finding of the gate of the sources, or a finding of a row. */\nexport type NeedsFinding = Finding<NeedsCode | FindingCode, \"source\" | \"unit\" | \"row\" | \"change\" | \"chain\">;\n\n/** This function tells if a need is a finite number in a unit of energy for each day, and above 0 when `positive` is true. */\nfunction goodNeed(need: Quantity, positive = true): boolean {\n try {\n const value = valueIn(need, \"kcal/d\");\n return Number.isFinite(value) && (!positive || value > 0);\n } catch {\n return false;\n }\n}\n\n/** The fields that the source of each table must have: the credit, the evidence of the license and the hash of the file. */\nconst TABLE_FIELDS: readonly SourceField[] = [\"by\", \"terms\", \"sha256\"];\n\n/**\n * This function gives each finding of a table of calorie needs. A list with no error tells that the gate passes.\n *\n * - The findings of the source come from `checkSources` of `@mark1russell7/guidebook`, with the options of the call and the rules of a table.\n * - The rules of a table: the source has a publisher (`by`), a page of its terms and a hash, and its addresses start with `https:`.\n * - The hash of the source is part of the gate of the sources (`bad-sha256`).\n * - The rows have the codes of `NEEDS_CODES`.\n *\n * The findings are in the order of the table. The function is pure.\n *\n * @param table - The table of calorie needs\n * @param options - The options of the gate of the sources, for example the date of the gate\n */\nexport function checkCalorieTable(table: CalorieTable, options?: GateOptions): NeedsFinding[] {\n const require = [...new Set([...(options?.require ?? []), ...TABLE_FIELDS])];\n const findings: NeedsFinding[] = [...checkSources([table.source], { ...options, require, https: true })];\n const add = (code: NeedsCode, record: \"source\" | \"row\" | \"change\", id: string, message: string): void => {\n findings.push({ level: \"error\", code, record, id, message });\n };\n\n const whole = (value: number | undefined): boolean => value === undefined || (Number.isSafeInteger(value) && value >= 0);\n const range = (row: CalorieRow): boolean => whole(row.from) && whole(row.to) && (row.to === undefined || row.to >= row.from);\n const idOf = (index: number): string => `${table.id}.rows[${String(index)}]`;\n table.rows.forEach((row, index) => {\n const id = idOf(index);\n if (row.age.trim() === \"\" || !(CALORIE_SEXES as readonly unknown[]).includes(row.sex)) add(\"needs-row\", \"row\", id, `The row \"${id}\" has no age or a sex that is not a sex of the table.`);\n if (!range(row)) add(\"needs-row\", \"row\", id, `The row \"${id}\" has a range of months that is not a range of whole numbers of 0 or more.`);\n const needs = row.need.levels === undefined ? [row.need.each] : ACTIVITY_LEVELS.map((level) => row.need.levels?.[level]);\n if (!needs.every((need) => need !== undefined && goodNeed(need))) add(\"needs-value\", \"row\", id, `The row \"${id}\" has a need that is not a number above 0 in kcal/d.`);\n for (const other of table.rows.slice(0, index)) {\n if (other.sex !== row.sex) continue;\n if (row.from <= (other.to ?? Infinity) && other.from <= (row.to ?? Infinity)) add(\"needs-overlap\", \"row\", id, `The row \"${id}\" (${row.sex}, ${row.age}) has ages in common with the row ${other.age}.`);\n }\n });\n\n // The rows of each sex, in the order of their first month, have no gap. A row with a bad range has its own finding.\n // A table can start after month 0 and end at a closed row: the gate of a chain checks the cover of all months.\n for (const sex of CALORIE_SEXES) {\n const rows = table.rows.map((row, index) => ({ row, index })).filter(({ row }) => row.sex === sex && range(row));\n rows.sort((a, b) => a.row.from - b.row.from);\n rows.slice(1).forEach(({ row, index }, at) => {\n const before = rows[at]?.row.to;\n if (before !== undefined && row.from > before + 1) add(\"needs-gap\", \"row\", idOf(index), `The table has no row of a ${sex} for the months ${String(before + 1)} to ${String(row.from - 1)}.`);\n });\n }\n\n // The changes: a stage, a title and a sex of the table, one change for each stage and sex, and a finite value.\n // A change with the smallest need of its sex stays above 0. A row with a bad need has its own finding.\n const smallest = (sex: string): number =>\n Math.min(\n ...table.rows\n .filter((row) => row.sex === sex)\n .flatMap((row) => (row.need.levels === undefined ? [row.need.each] : ACTIVITY_LEVELS.map((level) => row.need.levels?.[level])))\n .filter((need): need is Quantity => need !== undefined && goodNeed(need))\n .map((need) => valueIn(need, \"kcal/d\")),\n );\n const seen = new Set<string>();\n (table.changes ?? []).forEach((change, index) => {\n const id = `${table.id}.changes[${String(index)}]`;\n const stage = typeof change.stage === \"string\" ? change.stage.trim() : \"\";\n const title = typeof change.title === \"string\" ? change.title.trim() : \"\";\n if (stage === \"\" || stage !== change.stage || title === \"\" || !(CALORIE_SEXES as readonly unknown[]).includes(change.sex)) add(\"needs-change\", \"change\", id, `The change \"${id}\" has no stage, no title, a stage with a space at an end or a sex that is not a sex of the table.`);\n else if (seen.has(`${change.sex} ${stage}`)) add(\"needs-change\", \"change\", id, `The change \"${id}\" has the stage ${stage} of a ${change.sex}, and a different change has it too.`);\n seen.add(`${String(change.sex)} ${stage}`);\n if (!goodNeed(change.change, false)) add(\"needs-change\", \"change\", id, `The change \"${id}\" has a value that is not a finite number in kcal/d.`);\n else if (smallest(change.sex) + valueIn(change.change, \"kcal/d\") <= 0) add(\"needs-change\", \"change\", id, `The change \"${id}\" makes the smallest need of a ${change.sex} 0 or less.`);\n });\n return findings;\n}\n\n/**\n * This function gives each finding of a chain of tables. First come the findings of `checkCalorieTable` for each table,\n * in the order of the chain. Then come the findings of the cover. For each sex, the rows of all the tables cover each month from 0 to an\n * open last row (`needs-gap`, record `chain`). A row of a later table can overlap a row of an earlier table: the earlier\n * table gives the need. Two tables of the chain with the same `id` give `needs-id`.\n *\n * The limit of the first match: when an earlier table loses a row at its start, a later table can give those months.\n * Then the gate gives no finding. A caller that needs each month from one table tests the `id` of the table of each month.\n *\n * A list with no error tells that the gate passes. The function is pure.\n *\n * @param tables - One table, or tables in order\n * @param options - The options of the gate of the sources, for example the date of the gate\n */\nexport function checkCalorieChain(tables: CalorieTables, options?: GateOptions): NeedsFinding[] {\n const list = \"rows\" in tables ? [tables] : tables;\n const findings = list.flatMap((table) => checkCalorieTable(table, options));\n const id = list.map((table) => table.id).join(\" + \");\n const add = (message: string, code: NeedsCode = \"needs-gap\"): void => {\n findings.push({ level: \"error\", code, record: \"chain\", id, message });\n };\n if (list.length === 0) add(\"The chain has no table.\");\n list.forEach((table, index) => {\n if (list.findIndex((other) => other.id === table.id) < index) add(`The chain has the table ${table.id} two times or more.`, \"needs-id\");\n });\n for (const sex of CALORIE_SEXES) {\n const rows = list.flatMap((table) => table.rows).filter((row) => row.sex === sex && Number.isSafeInteger(row.from) && row.from >= 0);\n if (rows.length === 0) {\n add(`The tables have no row of a ${sex}.`);\n continue;\n }\n rows.sort((a, b) => a.from - b.from);\n // The first month with no row so far. It is Infinity after an open row.\n let next = 0;\n for (const row of rows) {\n if (row.from > next) add(`The tables have no row of a ${sex} for the months ${String(next)} to ${String(row.from - 1)}.`);\n next = Math.max(next, row.to === undefined ? Infinity : row.to + 1);\n }\n if (next !== Infinity) add(`The rows of a ${sex} end at ${String(next - 1)} months. The chain has no open last row.`);\n }\n return findings;\n}\n\n/** This function tells if a list of findings has an error. */\nexport function hasNeedsError(findings: readonly NeedsFinding[]): boolean {\n return findings.some((finding) => finding.level === \"error\");\n}\n","import type { Finding } from \"@mark1russell7/guidebook\";\nimport type { SupplyCatalog } from \"@mark1russell7/market/supplies\";\nimport { valueIn } from \"@mark1russell7/quantity\";\n\n// The uses and the supply parts of the needs, and the gate of their joins with the reference lists.\n// An add-on does not import a different add-on. Thus the reference lists are parameters, and a test joins the real lists.\n\n/** The code of the need of the food draw: food energy, in `kcal` for each day. */\nexport const FOOD_NEED = \"food.energy\";\n\n/**\n * The code of the need of the infants on formula below `FORMULA_DRAW_MONTHS`, in `kcal` for each day.\n * It is a need of its own. Thus the food of the adults does not feed the infants, and the formula does not feed the adults.\n */\nexport const FORMULA_NEED = \"food.infant-formula\";\n/** The code of the need of drinking water, in `L` for each day. */\nexport const WATER_NEED = \"hydration.drink\";\n\n/** The resource of the food to eat with no water and no fuel, in `kcal`. It has a direct use for the food draw. */\nexport const NO_COOK = \"food.no-cook\";\n\n/** The resource of the ready-to-feed infant formula, in `kcal`. It has a direct use for the formula need. It needs no water and no fuel. */\nexport const FORMULA_READY = \"food.infant-formula-ready\";\n/** The resource of the stored drinking water, in `L`. It has a direct use for the water need. */\nexport const STORED_WATER = \"water.stored\";\n\n/** The direct use of a resource for a need: 1 unit of the resource gives `amount` of the need. */\nexport interface FragmentDirectUse {\n readonly resource: string;\n readonly need: string;\n readonly amount: number;\n}\n\n/**\n * The default reference part that supplies each need when no case stops it, by the code of the need.\n * The parts are `id` values of `SUPPLY_PARTS` of `@mark1russell7/stack-hazards`. A household with a well gives a different part.\n * The type has the exact keys. The annotation replaces `as const`, because the package has isolated declarations.\n */\nexport const NEED_SUPPLIES: { readonly \"hydration.drink\": \"water.main\"; readonly \"food.energy\": \"food.retail\"; readonly \"food.infant-formula\": \"food.retail\" } = {\n \"hydration.drink\": \"water.main\",\n \"food.energy\": \"food.retail\",\n \"food.infant-formula\": \"food.retail\",\n};\n\n/**\n * The direct uses of the resources of the buy list. Each use gives 1 unit of its need for each unit of its resource.\n *\n * - 1 L of stored drinking water gives 1 L of drink. This is a definition, not a read.\n * - 1 kcal of food to eat with no water and no fuel gives 1 kcal of food energy.\n * - 1 kcal of ready-to-feed infant formula gives 1 kcal of the formula need.\n *\n * These records have the form of `DirectUse` of `@mark1russell7/stack-endurance`.\n */\nexport const DIRECT_USES: readonly FragmentDirectUse[] = [\n { resource: STORED_WATER, need: WATER_NEED, amount: 1 },\n { resource: NO_COOK, need: FOOD_NEED, amount: 1 },\n { resource: FORMULA_READY, need: FORMULA_NEED, amount: 1 },\n];\n\n/**\n * These are the codes of the join gate. Each code is an error.\n *\n * - `join-use-resource`: a direct use names a resource that is not in the catalog.\n * - `join-use-need`: a direct use names a need that is not in the reference needs.\n * - `join-use-unit`: the unit of the resource of a direct use does not convert to the unit of its need.\n * - `join-use-amount`: the amount of a direct use is not the factor from the unit of its resource to the unit of its need.\n * - `join-supply-need`: a supply names a need that is not in the reference needs.\n * - `join-supply-part`: a supply names a part that is not in the reference parts.\n */\nexport const JOIN_CODES: readonly [\"join-use-resource\", \"join-use-need\", \"join-use-unit\", \"join-use-amount\", \"join-supply-need\", \"join-supply-part\"] = [\n \"join-use-resource\",\n \"join-use-need\",\n \"join-use-unit\",\n \"join-use-amount\",\n \"join-supply-need\",\n \"join-supply-part\",\n];\n\n/** A code of the join gate. */\nexport type JoinCode = (typeof JOIN_CODES)[number];\n\n/**\n * A finding of the join gate, in the form of a finding of `@mark1russell7/guidebook`. Each finding of the gate is an error.\n * The record is `use` for a direct use, with the resource of the use as its `id`. It is `supply` for a supply, with the need as its `id`.\n */\nexport type JoinFinding = Finding<JoinCode, \"use\" | \"supply\">;\n\n/** This function gives the factor from a unit to a different unit, or `undefined` when the units do not convert. */\nfunction factorOf(from: string, to: string): number | undefined {\n try {\n const factor = valueIn({ value: 1, unit: from }, to);\n return Number.isFinite(factor) ? factor : undefined;\n } catch {\n return undefined;\n }\n}\n\n/** A reference need: its code and its unit. Each record of `NEEDS` of `@mark1russell7/alerts` has this form. */\nexport interface ReferenceNeed {\n readonly code: string;\n readonly unit: string;\n}\n\n/** A reference part: its `id`. Each record of `SUPPLY_PARTS` of `@mark1russell7/stack-hazards` has this form. */\nexport interface ReferencePart {\n readonly id: string;\n}\n\n/** The reference lists of the join gate. */\nexport interface JoinReferences {\n /** The reference needs, for example `NEEDS` of `@mark1russell7/alerts`. */\n readonly needs: readonly ReferenceNeed[];\n /** The reference parts, for example `SUPPLY_PARTS` of `@mark1russell7/stack-hazards`. */\n readonly parts: readonly ReferencePart[];\n}\n\n/**\n * This function examines the joins of a catalog, the direct uses and the supply parts with the reference lists.\n *\n * - The resource of each direct use is a resource of the catalog, and its need is a reference need.\n * - The unit of the resource of each direct use converts to the unit of its need.\n * - The amount of each direct use is the factor of that conversion. A direct use is a definition, so a different rate is a converter with a cited source.\n * - Each supply names a reference need and a reference part.\n *\n * The findings are in the order of the uses, then in the order of the supplies. The function is pure.\n *\n * @param catalog - The catalog of supplies of `@mark1russell7/market`\n * @param uses - The direct uses, for example `DIRECT_USES`\n * @param supplies - The part that supplies each need, by the code of the need, for example `NEED_SUPPLIES`\n * @param references - The reference needs and the reference parts\n * @returns The findings of the joins. An empty list is a pass.\n */\nexport function checkJoins(\n catalog: SupplyCatalog,\n uses: readonly FragmentDirectUse[],\n supplies: Readonly<Record<string, string>>,\n references: JoinReferences,\n): JoinFinding[] {\n const findings: JoinFinding[] = [];\n const add = (code: JoinCode, record: \"use\" | \"supply\", id: string, message: string): void => {\n findings.push({ level: \"error\", code, record, id, message });\n };\n const units = new Map(catalog.resources.map((resource) => [resource.code, resource.unit] as const));\n const needs = new Map(references.needs.map((need) => [need.code, need.unit] as const));\n for (const use of uses) {\n const unit = units.get(use.resource);\n const needUnit = needs.get(use.need);\n if (unit === undefined) add(\"join-use-resource\", \"use\", use.resource, `The direct use of ${use.resource} names no resource of the catalog.`);\n if (needUnit === undefined) add(\"join-use-need\", \"use\", use.resource, `The direct use of ${use.resource} names the need ${use.need}, which is not a reference need.`);\n if (unit === undefined || needUnit === undefined) continue;\n const factor = factorOf(unit, needUnit);\n if (factor === undefined) {\n add(\"join-use-unit\", \"use\", use.resource, `The direct use of ${use.resource} for ${use.need} takes ${unit}, which does not convert to ${needUnit}.`);\n } else if (use.amount !== factor) {\n add(\n \"join-use-amount\",\n \"use\",\n use.resource,\n `The direct use of ${use.resource} for ${use.need} gives ${String(use.amount)} ${needUnit} for each ${unit}, not ${String(factor)}. A direct use is a definition: a different rate is a converter with a cited source.`,\n );\n }\n }\n const parts = new Set(references.parts.map((part) => part.id));\n for (const [need, part] of Object.entries(supplies)) {\n if (!needs.has(need)) add(\"join-supply-need\", \"supply\", need, `The supply of ${need} names no reference need.`);\n if (!parts.has(part)) add(\"join-supply-part\", \"supply\", need, `The supply of ${need} names the part ${part}, which is not a reference part.`);\n }\n return findings;\n}\n","import { buyListEnergy, giftsOf, type BuyListEnergy, type SupplyCatalog } from \"@mark1russell7/market/supplies\";\nimport { calorieChange, calorieNeed, INFANT_FEEDINGS, type ActivityLevel, type CalorieNeedTotal, type CalorieTable, type CalorieTables, type Person } from \"./calorie.ts\";\nimport { CALORIE_CHAIN } from \"./data.ts\";\nimport { DIRECT_USES, FOOD_NEED, FORMULA_NEED, NEED_SUPPLIES, type FragmentDirectUse } from \"./uses.ts\";\n\n// The join of a household and a buy list into a fragment of an endurance layer: a draw of food energy, a draw of infant formula and the stores of the list.\n// The records have the form of the records of `@mark1russell7/stack-endurance`. An add-on does not import a different add-on, so the form is a copy.\n// A test assigns the layer to `EnduranceLayer` of stack-endurance. That test is the type gate of the copy.\n// The fragment has no converter. No cited source gives the water and the fuel to cook 1 kg of dry food, and a number with no source is not data.\n\n/** A resource of a store, with its unit. */\nexport interface FragmentResource {\n readonly code: string;\n readonly unit: string;\n}\n\n/** A store of the buy list: an amount of one resource, in its unit. */\nexport interface FragmentStore {\n readonly id: string;\n readonly resource: string;\n readonly amount: number;\n}\n\n/** A draw: the food energy or the formula of the persons of the draw for each day. */\nexport interface FragmentDraw {\n readonly need: string;\n readonly level: string;\n /** The energy of the persons of the draw for each day, in `kcal`. It is above 0. */\n readonly perDay: number;\n /** The count of the persons of the draw. */\n readonly users: number;\n readonly supply: string;\n}\n\n/** A fragment of an endurance layer, with the form of `EnduranceLayer` of `@mark1russell7/stack-endurance`. It has no converter. */\nexport interface HouseholdFragment {\n /** The format of an endurance layer, `endurance/1`. */\n readonly schema: \"endurance/1\";\n readonly levels: readonly string[];\n readonly resources: readonly FragmentResource[];\n readonly stores: readonly FragmentStore[];\n readonly draws: readonly FragmentDraw[];\n readonly direct: readonly FragmentDirectUse[];\n}\n\n/** The age in months below which a person record must have a `feeding`: 12, the first month of the guidelines. */\nexport const INFANT_MONTHS = 12;\n\n/**\n * The age in months from which an infant cannot have `feeding: \"breast-milk\"`: 6.\n * From 6 months, the infant table gives more than the change of a stage of lactation, so a part of the need is in no draw. Give `food` from this age.\n */\nexport const BREAST_MILK_MONTHS = 6;\n\n/**\n * The age in months below which an infant on formula is in the formula draw with the whole need of its row: 6.\n * Below this age, an infant has milk only, as for `BREAST_MILK_MONTHS`. From this age, no cited source gives the part of formula.\n */\nexport const FORMULA_DRAW_MONTHS = 6;\n\n/** The action for the persons that no draw can serve: no row in the table, or an infant on formula from `FORMULA_DRAW_MONTHS`. The only action is `leave-out`. */\nexport type NoRowAction = \"leave-out\";\n\n/** The inputs of the household fragment. */\nexport interface HouseholdFragmentInput {\n /** The person records of the household. */\n readonly persons: readonly Person[];\n /** The activity level of each person record with no level of its own. It has no default. */\n readonly activity: ActivityLevel;\n /** The catalog of supplies of `@mark1russell7/market`. */\n readonly catalog: SupplyCatalog;\n /** The count of units of each product of the buy list, by the `id` of the product. */\n readonly units: Readonly<Record<string, number>>;\n /** The `id` of the part of the stack that supplies the food and the formula when no case stops it. The default is `food.retail`, from `NEED_SUPPLIES`. */\n readonly supply?: string | undefined;\n /** The direct uses. The fragment takes each use for the need of one of its draws. The default is `DIRECT_USES`. */\n readonly uses?: readonly FragmentDirectUse[] | undefined;\n /** The level of the draws. It is one of the levels of the joined layer. */\n readonly level: string;\n /** The levels of the fragment. The default is no levels: a different fragment of the stack gives them. */\n readonly levels?: readonly string[] | undefined;\n /** The table of calorie needs, or tables in order. The default is `CALORIE_CHAIN`, which gives a row for each age. */\n readonly table?: CalorieTables | undefined;\n /** The start of the `id` of each store. The default is `buy`. */\n readonly prefix?: string | undefined;\n /**\n * The action for the persons with no row in the table, and for the infants on formula from `FORMULA_DRAW_MONTHS`. Without it, such a person gives no layer.\n * With `leave-out`, the draw has no need of those persons, and the result lists them.\n */\n readonly noRow?: NoRowAction | undefined;\n}\n\n/** A gift of the buy list with no read. The fragment has no store for it. A no read is not 0. */\nexport interface GiftNoRead {\n readonly product: string;\n readonly resource: string;\n readonly why: string;\n}\n\n/** The parts of the result that do not change with the draw. */\nexport interface HouseholdStoresResult {\n /** The food energy of each product of the buy list. A caller gets the energy of the dry food for its converters from it. */\n readonly energy: BuyListEnergy;\n /** The gifts of the buy list with no read. */\n readonly noReads: readonly GiftNoRead[];\n /** True when each gift of the buy list has a read. When it is false, the stores are a lower limit. */\n readonly storesRead: boolean;\n}\n\n/** The household fragment with its draw. The draw is exact for its users. */\nexport interface HouseholdFragmentRead extends HouseholdStoresResult {\n readonly layer: HouseholdFragment;\n /**\n * The food energy of the household for one day, with a line for each person record. Its `read` covers the whole\n * household. It is false when a person is left out, or when a record with count 0 has no row. The flag of the draw\n * is `needRead`.\n */\n readonly need: CalorieNeedTotal;\n /** This field is true: the draw has a read for each of its users. */\n readonly needRead: true;\n /**\n * The persons with no row, and the infants on formula from `FORMULA_DRAW_MONTHS`, that the option `leave-out` left out of the draws.\n * With no option, the list is empty.\n */\n readonly leftOut: readonly Person[];\n /**\n * The infants on formula. Each infant below `FORMULA_DRAW_MONTHS` is in the formula draw. The option `leave-out` left the other\n * infants out, so `leftOut` also lists them.\n */\n readonly formula: readonly Person[];\n /**\n * The infants on breast milk only. Each has a line with a read in `need`, and no part of the draw.\n * The stage of lactation of a person of the draw holds that energy.\n */\n readonly breastMilk: readonly Person[];\n}\n\n/** No household fragment: the draw has no read. A low rate gives too many days, so the function gives no layer. */\nexport interface HouseholdFragmentNoRead extends HouseholdStoresResult {\n readonly layer: undefined;\n /** The food energy of the household for one day. It is `undefined` when the household has no person. */\n readonly need: CalorieNeedTotal | undefined;\n readonly needRead: false;\n /** The persons with no row in the table. */\n readonly noRow: readonly Person[];\n /** The infants on formula. */\n readonly formula: readonly Person[];\n /** The infants on breast milk only. */\n readonly breastMilk: readonly Person[];\n /** The reason for no layer. */\n readonly why: string;\n}\n\n/** The household fragment, or a no read of the draw. Both have the reads of the buy list. */\nexport type HouseholdFragmentResult = HouseholdFragmentRead | HouseholdFragmentNoRead;\n\n/** This function gives the stores of the buy list, its resources and its gifts with no read. */\nfunction buyListStores(input: HouseholdFragmentInput): { stores: FragmentStore[]; parts: HouseholdStoresResult } {\n const { catalog, units } = input;\n const energy = buyListEnergy(catalog, units);\n const prefix = input.prefix ?? \"buy\";\n const stores: FragmentStore[] = [];\n const noReads: GiftNoRead[] = [];\n for (const [product, count] of Object.entries(units)) {\n for (const gift of giftsOf(catalog, product, count)) {\n if (!gift.read) noReads.push({ product, resource: gift.resource, why: gift.why });\n else if (gift.amount > 0) stores.push({ id: `${prefix}:${product}:${gift.resource}`, resource: gift.resource, amount: gift.amount });\n }\n }\n return { stores, parts: { energy, noReads, storesRead: noReads.length === 0 } };\n}\n\n/**\n * This function gives the resources of the stores and of the uses, with the units of the catalog.\n *\n * @throws RangeError when the resource of a use is not in the catalog in kcal\n */\nfunction layerResources(catalog: SupplyCatalog, stores: readonly FragmentStore[], uses: readonly FragmentDirectUse[]): FragmentResource[] {\n const unitOf = new Map(catalog.resources.map((resource) => [resource.code, resource.unit]));\n for (const use of uses) {\n if (unitOf.get(use.resource) !== \"kcal\") throw new RangeError(`The catalog has no resource \"${use.resource}\" in kcal for the use of ${use.need}.`);\n }\n const codes = [...new Set([...stores.map((store) => store.resource), ...uses.map((use) => use.resource)])];\n return codes.map((code) => ({ code, unit: unitOf.get(code) ?? \"\" }));\n}\n\n/**\n * This function joins a household and a buy list into a fragment of an endurance layer.\n *\n * - The draw of food energy has the rate of the need of its persons for one day, and its users are the persons.\n * - The draw of formula has the infants on formula below `FORMULA_DRAW_MONTHS`, with the whole need of their rows.\n * - The fragment has each draw with one or more users. The draw of food energy is first.\n * - Each gift of the buy list with a read is one store, with the `id` `<prefix>:<product>:<resource>`. A gift with no read has no store.\n * - The direct uses are each use of `uses` for the need of a draw. The default `DIRECT_USES` gives 1 kcal for each kcal.\n * `food.no-cook` feeds the food draw, and `food.infant-formula-ready` feeds the formula draw.\n * - The resources are the resources of the stores and of the direct uses, with the units of the catalog.\n * - The supply part of each draw is `supply`. Its default is the part of `NEED_SUPPLIES` for the need of the draw.\n * - The fragment has no converter. A caller adds converters for the dry food, with the water and the fuel of each run.\n *\n * A person with no row in the tables gives no layer, because a low rate gives too many days. The default tables give a row for each age.\n * The option `noRow: \"leave-out\"` leaves those persons out of the draw. A draw of 0 kcal gives no layer.\n *\n * Each person record below `INFANT_MONTHS` must have a `feeding`. It has no default.\n *\n * - `food`: the need of the infant is in the draw of food energy.\n * - `breast-milk`: the infant has a line, and no part of the draw. It is only for an infant below `BREAST_MILK_MONTHS`.\n * A person of the household must have a stage of lactation. Each infant on breast milk needs one person of the draw with a stage of lactation.\n * When the infants are more, the function gives no layer: the change of a stage is the milk of one infant.\n * - `formula`: below `FORMULA_DRAW_MONTHS`, the whole need of the infant is in the draw of formula, because the infant has milk only.\n * From `FORMULA_DRAW_MONTHS`, no cited source gives the part of formula, so the infant gives no layer, as a person with no row.\n * The option `leave-out` also applies. The feeding is only for an infant below `INFANT_MONTHS`.\n *\n * The function is pure.\n *\n * @param input - The persons, the activity level, the catalog and the buy list, the supply part and the level of the draw\n * @returns The fragment or a no read of the draw, with the energy of the list and the gifts with no read\n * @throws RangeError for the errors of `calorieNeed`, `giftsOf` and `buyListEnergy`, except a household with no person\n * @throws RangeError when the catalog has no resource in `kcal` for the direct use of a draw\n * @throws RangeError when a record below `INFANT_MONTHS` has no `feeding`, or when a `feeding` is not a way of `INFANT_FEEDINGS`\n * @throws RangeError for `breast-milk` from `BREAST_MILK_MONTHS`, and for `formula` from `INFANT_MONTHS`\n * @throws RangeError when an infant drinks only breast milk and no person of the household has a stage of lactation\n */\nexport function householdFragment(input: HouseholdFragmentInput): HouseholdFragmentResult {\n const { stores, parts } = buyListStores(input);\n checkFeedings(input.persons);\n if (input.persons.every((person) => person.count === 0)) {\n return { ...parts, layer: undefined, need: undefined, needRead: false, noRow: [], formula: [], breastMilk: [], why: \"The household has no person, so the draw is 0 kcal.\" };\n }\n const tables = input.table ?? CALORIE_CHAIN;\n const need = calorieNeed(tables, input.persons, input.activity, 1);\n const noRow: Person[] = [];\n const formula: Person[] = [];\n const formulaLater: Person[] = [];\n const breastMilk: Person[] = [];\n let users = 0;\n let perDay = 0;\n let formulaUsers = 0;\n let formulaPerDay = 0;\n // The persons of the draw with a stage of lactation, and the infants on breast milk.\n let mothers = 0;\n let nursed = 0;\n for (const line of need.lines) {\n const { person } = line;\n if (person.count === 0) continue;\n if (person.feeding === \"breast-milk\") {\n breastMilk.push(person);\n nursed += person.count;\n } else if (person.feeding === \"formula\") {\n formula.push(person);\n if (line.read && person.ageMonths < FORMULA_DRAW_MONTHS) {\n formulaUsers += person.count;\n formulaPerDay += line.need.value;\n } else formulaLater.push(person);\n } else if (!line.read) noRow.push(person);\n else {\n users += person.count;\n perDay += line.need.value;\n if (makesMilk(tables, person)) mothers += person.count;\n }\n }\n if (breastMilk.length > 0 && !input.persons.some((person) => person.count > 0 && makesMilk(tables, person))) {\n throw new RangeError(\n `The infants ${breastMilk.map(nameOf).join(\", \")} drink only breast milk, but no person of the household has a stage of lactation. ` +\n \"The milk comes from the food of the mother, so give the mother a stage of lactation, for example lactation-1.\",\n );\n }\n const reasons = [\n ...(nursed > mothers\n ? [`${String(nursed)} infants drink only breast milk, but the draw has ${String(mothers)} persons with a stage of lactation. The change of a stage is the milk of one infant. Give feeding: food to the other infants.`]\n : []),\n ...(noRow.length > 0 ? [`The table has no row for ${String(noRow.length)} person records.`] : []),\n ...(formulaLater.length > 0\n ? [`${String(formulaLater.length)} infant records of ${String(FORMULA_DRAW_MONTHS)} months or more are on formula. No cited source gives the part of their need that formula gives.`]\n : []),\n ];\n if (nursed > mothers) {\n return { ...parts, layer: undefined, need, needRead: false, noRow, formula, breastMilk, why: reasons.join(\" \") };\n }\n if (reasons.length > 0 && input.noRow !== \"leave-out\") {\n return { ...parts, layer: undefined, need, needRead: false, noRow, formula, breastMilk, why: `${reasons.join(\" \")} The option noRow: \"leave-out\" leaves them out of the draw.` };\n }\n const draws: FragmentDraw[] = [];\n if (users > 0 && perDay > 0) draws.push({ need: FOOD_NEED, level: input.level, perDay, users, supply: input.supply ?? NEED_SUPPLIES[FOOD_NEED] });\n if (formulaUsers > 0 && formulaPerDay > 0) {\n draws.push({ need: FORMULA_NEED, level: input.level, perDay: formulaPerDay, users: formulaUsers, supply: input.supply ?? NEED_SUPPLIES[FORMULA_NEED] });\n }\n if (draws.length === 0) {\n return { ...parts, layer: undefined, need, needRead: false, noRow, formula, breastMilk, why: \"No person of the draws has a need of food in the draws, so the draws are 0 kcal.\" };\n }\n const needs = new Set(draws.map((draw) => draw.need));\n const uses = (input.uses ?? DIRECT_USES).filter((use) => needs.has(use.need));\n return {\n ...parts,\n layer: {\n schema: \"endurance/1\",\n levels: [...(input.levels ?? [])],\n resources: layerResources(input.catalog, stores, uses),\n stores,\n draws,\n direct: uses.map((use) => ({ ...use })),\n },\n need,\n needRead: true,\n leftOut: [...noRow, ...formulaLater],\n formula,\n breastMilk,\n };\n}\n\n/** This function gives the name of a person record in a message. */\nfunction nameOf(person: Person): string {\n return `${String(person.sex)} of ${String(person.ageMonths)} months`;\n}\n\n/**\n * This function examines the feeding of each record. A record below `INFANT_MONTHS` must have one.\n * Each feeding is a way of `INFANT_FEEDINGS`, and each way holds at the age of the record.\n */\nfunction checkFeedings(persons: readonly Person[]): void {\n for (const person of persons) {\n const { feeding } = person;\n if (feeding === undefined) {\n if (person.count > 0 && person.ageMonths < INFANT_MONTHS) {\n throw new RangeError(`The persons ${nameOf(person)} are below ${String(INFANT_MONTHS)} months and have no feeding. Give feeding: ${INFANT_FEEDINGS.join(\", \")}.`);\n }\n } else if (!(INFANT_FEEDINGS as readonly unknown[]).includes(feeding)) {\n throw new RangeError(`The feeding ${String(feeding)} of the persons ${nameOf(person)} is not a way of ${INFANT_FEEDINGS.join(\", \")}.`);\n } else if (feeding === \"breast-milk\" && !(person.ageMonths < BREAST_MILK_MONTHS)) {\n throw new RangeError(\n `The persons ${nameOf(person)} have feeding: breast-milk, which is only for an infant below ${String(BREAST_MILK_MONTHS)} months. ` +\n \"From that age, the need is more than the change of a stage of lactation. Give feeding: food.\",\n );\n } else if (feeding === \"formula\" && !(person.ageMonths < INFANT_MONTHS)) {\n throw new RangeError(`The persons ${nameOf(person)} have feeding: formula, which is only for an infant below ${String(INFANT_MONTHS)} months. Give feeding: food.`);\n }\n }\n}\n\n/** This function tells if the stage of a person record is a stage that makes milk, in one of the tables. */\nfunction makesMilk(tables: CalorieTables, person: Person): boolean {\n const { stage } = person;\n if (stage === undefined) return false;\n const list: readonly CalorieTable[] = \"rows\" in tables ? [tables] : tables;\n return list.some((table) => calorieChange(table, person.sex, stage)?.milk === true);\n}\n"],"mappings":";;;;;AAQA,MAAa,kBAAyE;CAAC;CAAa;CAAqB;AAAQ;;AAMjI,MAAa,gBAA6C,CAAC,UAAU,MAAM;;;;;;;;AAqE3E,MAAa,kBAA+D;CAAC;CAAe;CAAW;AAAM;;AAwC7G,MAAM,cAAc;;AAEpB,MAAM,aAAa;;AAGnB,SAAgB,gBAAgB,OAAwC;CACtE,OAAQ,gBAAuC,SAAS,KAAK;AAC/D;;;;;;;;AASA,SAAgB,WAAW,OAAqB,KAAiB,WAA2C;CAC1G,OAAO,MAAM,KAAK,MAAM,QAAQ,IAAI,QAAQ,OAAO,aAAa,IAAI,SAAS,IAAI,OAAO,KAAA,KAAa,aAAa,IAAI,GAAG;AAC3H;;;;;;;;;AAUA,SAAgB,aAAa,QAAuB,KAAiB,WAA2F;CAC9J,KAAK,MAAM,SAAS,UAAU,MAAM,GAAG;EACrC,MAAM,MAAM,WAAW,OAAO,KAAK,SAAS;EAC5C,IAAI,QAAQ,KAAA,GAAW,OAAO;GAAE;GAAO;EAAI;CAC7C;AAEF;;AAGA,SAAS,UAAU,QAAgD;CACjE,OAAO,UAAU,SAAS,CAAC,MAAM,IAAI;AACvC;;;;;;;;AASA,SAAgB,cAAc,OAAqB,KAAiB,OAA0C;CAC5G,OAAO,MAAM,SAAS,MAAM,WAAW,OAAO,QAAQ,OAAO,OAAO,UA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MAAM,EAAE,YAAY;EACpB,IAAI,YAAY,KAAA,GACV;OAAA,OAAO,QAAQ,KAAK,OAAO,YAAA,IAC7B,MAAM,IAAI,WAAW,eAAe,OAAO,MAAM,EAAE,aAAa,OAAA,EAAoB,EAAE,6CAA6C,gBAAgB,KAAK,IAAI,EAAE,EAAE;EAAA,OAE7J,IAAI,CAAE,gBAAuC,SAAS,OAAO,GAClE,MAAM,IAAI,WAAW,eAAe,OAAO,OAAO,EAAE,kBAAkB,OAAO,MAAM,EAAE,mBAAmB,gBAAgB,KAAK,IAAI,EAAE,EAAE;OAChI,IAAI,YAAY,iBAAiB,EAAE,OAAO,YAAA,IAC/C,MAAM,IAAI,WACR,eAAe,OAAO,MAAM,EAAE,gEAAgE,OAAA,CAAyB,EAAE,sGAE3H;OACK,IAAI,YAAY,aAAa,EAAE,OAAO,YAAA,KAC3C,MAAM,IAAI,WAAW,eAAe,OAAO,MAAM,EAAE,4DAA4D,OAAA,EAAoB,EAAE,6BAA6B;CAEtK;AACF;;AAGA,SAAS,UAAU,QAAuB,QAAyB;CACjE,MAAM,EAAE,UAAU;CAClB,IAAI,UAAU,KAAA,GAAW,OAAO;CAEhC,QADsC,UAAU,SAAS,CAAC,MAAM,IAAI,OAAA,CACxD,MAAM,UAAU,cAAc,OAAO,OAAO,KAAK,KAAK,CAAC,EAAE,SAAS,IAAI;AACpF"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@mark1russell7/stack-needs",
4
- "version": "0.6.0",
4
+ "version": "0.8.0",
5
5
  "description": "The need rates of draws as reference data: the daily food energy of each person by age, sex and activity, from the Dietary Guidelines for Americans, with its source. An add-on of system-stack.",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -39,14 +39,14 @@
39
39
  ],
40
40
  "dependencies": {
41
41
  "@mark1russell7/guidebook": "^0.4.0",
42
- "@mark1russell7/market": "^0.8.0",
42
+ "@mark1russell7/market": "^0.8.2",
43
43
  "@mark1russell7/quantity": "^0.4.4"
44
44
  },
45
45
  "devDependencies": {
46
- "@mark1russell7/alerts": "^0.1.5",
46
+ "@mark1russell7/alerts": "^0.1.26",
47
47
  "@mark1russell7/cue": "^2.0.0",
48
48
  "@mark1russell7/stack-endurance": "0.6.4",
49
- "@mark1russell7/stack-hazards": "0.5.1",
49
+ "@mark1russell7/stack-hazards": "0.6.0",
50
50
  "@types/node": "^26.6.5",
51
51
  "@vitest/coverage-v8": "^5.0.3",
52
52
  "fast-check": "^4.10.2",