@mark1russell7/stack-needs 0.9.2 → 0.9.3

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
@@ -109,7 +109,7 @@ The infant table gives the need of an infant below 12 months (`INFANT_MONTHS`).
109
109
  | --- | --- |
110
110
  | `food` | The draw holds the need of the infant, from the infant table. |
111
111
  | `breast-milk` | Only below 12 months. 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. From 6 months, the infant also has food. The draw holds the need of the row minus the milk energy (`MILK_LATER`, 381 kcal/d). The result lists the infant in `breastMilk`. |
112
- | `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. With `formulaLater: "whole"`, the formula draw holds the whole need: the upper limit of formula. The result lists each infant on formula in `formula`. |
112
+ | `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. With `formulaLater: "whole"`, the formula draw holds the whole need: the upper limit of formula. With `formulaLater: "least"`, the formula draw holds the lower limit, and the food draw holds the rest. The result lists each infant on formula in `formula`. |
113
113
 
114
114
  With the default tables, the line of each infant in `need` has a read, so `need` gives the energy of the whole household.
115
115
 
@@ -118,7 +118,9 @@ The limits of formula from 6 months:
118
118
  - The upper limit is the whole need of the row. Formula cannot give more energy than the whole need. Give `formulaLater: "whole"` for this limit.
119
119
  - Table 5.2 of the WIC guide (page 137) gives the formula of one day. It is approximately 24 to 32 ounces at 6 to 8 months.
120
120
  - At 8 to 12 months, the table gives approximately 24 ounces.
121
- - The lower limit needs the energy of one ounce of the formula. The guide does not give it, and the label of a product gives it. Thus the lower limit is a no read.
121
+ - The lower limit is 24 fl oz a day (`FORMULA_LATER_LEAST`). Give `formulaLater: "least"` for this limit. When the need of the row is less, the formula draw holds the need.
122
+ - The FDC item 172319 (ready-to-feed formula) gives 63 kcal in 100 g and 30.4 g in 1 fl oz. Thus 1 fl oz gives 19.152 kcal, and 24 fl oz give 459.648 kcal.
123
+ - The two limits give the same total energy. Only the split between the formula draw and the food draw changes.
122
124
 
123
125
  The rules of breast milk:
124
126
 
package/build/index.d.ts CHANGED
@@ -190,6 +190,24 @@ export interface CitedFeeds {
190
190
  * 24 hours divided by 3 hours is 8. More feeds give smaller feeds and thus more waste, so this value is the most feeds.
191
191
  */
192
192
  export declare const FORMULA_FEEDS: CitedFeeds;
193
+ /** The source of the energy of one fluid ounce of ready-to-feed formula: the SR Legacy file of FoodData Central. */
194
+ export declare const FDC_SR_LEGACY_SOURCE: Source;
195
+ /** The energy of the least formula of one infant for one day, from a cited volume and a cited energy of one fluid ounce. */
196
+ export interface CitedFormulaLeast {
197
+ /** The energy, in `kcal`: `ounces` times `kcalPerOunce`. */
198
+ readonly perDay: number;
199
+ readonly ounces: number;
200
+ readonly ouncesSource: Source;
201
+ readonly ouncesLocator: string;
202
+ readonly kcalPerOunce: number;
203
+ readonly kcalSource: Source;
204
+ readonly kcalLocator: string;
205
+ }
206
+ /**
207
+ * The least formula of one infant from 6 months: 24 fl oz a day. Table 5.2 of the WIC guide gives 24 to 32 ounces at 6 to 8 months,
208
+ * and 24 ounces at 8 to 12 months. The FDC item 172319 gives 63 kcal in 100 g and 30.4 g in 1 fl oz, thus 19.152 kcal in 1 fl oz.
209
+ */
210
+ export declare const FORMULA_LATER_LEAST: CitedFormulaLeast;
193
211
  /** The source of the infant table: the PDF of the report Dietary Reference Intakes for Energy (2023) of the National Academies. */
194
212
  export declare const NASEM_ENERGY_SOURCE: Source;
195
213
  /** The energy of the breast milk of one infant for one day, with its source and its place in the source. */
@@ -439,8 +457,9 @@ export interface HouseholdFragmentInput {
439
457
  /**
440
458
  * The rule for an infant on formula from `FORMULA_DRAW_MONTHS`. Without it, the infant is a person with no row.
441
459
  * With `whole`, the formula draw holds the whole need of the row: the upper limit of formula. The food draw holds none of it.
460
+ * With `least`, the formula draw holds `FORMULA_LATER_LEAST`, or the need of the row when it is less. The food draw holds the rest.
442
461
  */
443
- readonly formulaLater?: "whole" | undefined;
462
+ readonly formulaLater?: "whole" | "least" | undefined;
444
463
  }
445
464
  /** The waste of the opened containers of one product of the buy list with no cold storage. */
446
465
  export interface OpenedWaste {
@@ -524,6 +543,7 @@ export type HouseholdFragmentResult = HouseholdFragmentRead | HouseholdFragmentN
524
543
  * - The draw of food energy has the rate of the need of its persons for one day, and its users are the persons.
525
544
  * - The draw of formula has the infants on formula below `FORMULA_DRAW_MONTHS`, with the whole need of their rows.
526
545
  * With `formulaLater: "whole"`, it also has the older infants on formula, with the whole need of their rows.
546
+ * With `formulaLater: "least"`, it has `FORMULA_LATER_LEAST` of each older infant, and the food draw has the rest.
527
547
  * - The fragment has each draw with one or more users. The draw of food energy is first.
528
548
  * - 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.
529
549
  * - The direct uses are each use of `uses` for the need of a draw. The default `DIRECT_USES` gives 1 kcal for each kcal.
@@ -547,7 +567,8 @@ export type HouseholdFragmentResult = HouseholdFragmentRead | HouseholdFragmentN
547
567
  * When the infants are more, the function gives no layer: the change of a stage is the milk of one infant.
548
568
  * - `formula`: below `FORMULA_DRAW_MONTHS`, the whole need of the infant is in the draw of formula, because the infant has milk only.
549
569
  * From `FORMULA_DRAW_MONTHS`, no cited source gives the part of formula, so the infant gives no layer, as a person with no row.
550
- * The option `leave-out` also applies. The option `formulaLater: "whole"` puts the whole need in the formula draw: the upper limit. The feeding is only for an infant below `INFANT_MONTHS`.
570
+ * The option `leave-out` also applies. The option `formulaLater: "whole"` puts the whole need in the formula draw: the upper limit.
571
+ * The option `formulaLater: "least"` puts the lower limit in the formula draw, and the rest of the need in the food draw. The feeding is only for an infant below `INFANT_MONTHS`.
551
572
  *
552
573
  * The function is pure.
553
574
  *
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/calorie.ts","../src/data.ts","../src/check.ts","../src/uses.ts","../src/household.ts","../src/cook.ts","../src/daily.ts"],"mappings":";;;;qBAQa;;YAGD,wBAAwB;;qBAGvB;;YAGD,qBAAqB;;;;;YAMrB;WAAyB,QAAQ,SAAS,OAAO,eAAe;WAAqB;;WAA4B,MAAM;WAAmB;;;iBAGrI;WACN,KAAK;;WAEL;;WAEA;;WAEA;WACA,MAAM;;;;;;iBAOA;;WAEN;;WAEA;;WAEA,KAAK;;WAEL,QAAQ;;WAER;;WAEA;;;iBAIM;;WAEN;WACA;WACA,QAAQ;;WAER;;WAEA,eAAe;;WAEf,mBAAmB;;;;;;YAOlB,gBAAgB,wBAAwB;;;;;;;;qBASvC;;YAGD,wBAAwB;;iBAGnB;WACN,KAAK;;WAEL;WACA;;WAEA,QAAQ;;WAER;;;;;WAKA,UAAU;;;YAIT;WACG,QAAQ;WAAiB;WAAqB,OAAO;WAAwB;WAAwB;WAAsB;WAAqC,MAAM;;WACtK,QAAQ;WAAiB;WAAsB;;;iBAG7C;;WAEN,gBAAgB;;WAEhB;;WAEA,MAAM;;WAEN;;;wBASK,gBAAgB,iBAAiB,SAAS;;;;;;;;wBAW1C,WAAW,OAAO,cAAc,KAAK,YAAY,oBAAoB;;;;;;;;;wBAYrE,aAAa,QAAQ,eAAe,KAAK,YAAY;WAA+B,OAAO;WAAuB,KAAK;;;;;;;;;wBAoBvH,cAAc,OAAO,cAAc,KAAK,YAAY,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;wBA4BpE,YAAY,QAAQ,eAAe,kBAAkB,UAAU,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,QAAQ;WACR,kBAAkB;;WAElB;;;iBAIM;WACN;WACA;;;iBAIM;;WAEN;;WAEA;WACA,OAAO;WACP,MAAM,gBAAgB;;;qBAIpB,sBAAsB;;qBAWtB,mBAAmB;;;;;;;;;;qBAmBnB,sBAAsB;;;;;;;;;qBAiDtB;;YAGD,wBAAwB;;YAGxB,mBAAmB,QAAQ,gBAAgB;;;;;;;;;wBA4BvC,gBAAgB,gBAAgB,aAAa,UAAU,cAAc"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/calorie.ts","../src/data.ts","../src/check.ts","../src/uses.ts","../src/household.ts","../src/cook.ts","../src/daily.ts"],"mappings":";;;;qBAQa;;YAGD,wBAAwB;;qBAGvB;;YAGD,qBAAqB;;;;;YAMrB;WAAyB,QAAQ,SAAS,OAAO,eAAe;WAAqB;;WAA4B,MAAM;WAAmB;;;iBAGrI;WACN,KAAK;;WAEL;;WAEA;;WAEA;WACA,MAAM;;;;;;iBAOA;;WAEN;;WAEA;;WAEA,KAAK;;WAEL,QAAQ;;WAER;;WAEA;;;iBAIM;;WAEN;WACA;WACA,QAAQ;;WAER;;WAEA,eAAe;;WAEf,mBAAmB;;;;;;YAOlB,gBAAgB,wBAAwB;;;;;;;;qBASvC;;YAGD,wBAAwB;;iBAGnB;WACN,KAAK;;WAEL;WACA;;WAEA,QAAQ;;WAER;;;;;WAKA,UAAU;;;YAIT;WACG,QAAQ;WAAiB;WAAqB,OAAO;WAAwB;WAAwB;WAAsB;WAAqC,MAAM;;WACtK,QAAQ;WAAiB;WAAsB;;;iBAG7C;;WAEN,gBAAgB;;WAEhB;;WAEA,MAAM;;WAEN;;;wBASK,gBAAgB,iBAAiB,SAAS;;;;;;;;wBAW1C,WAAW,OAAO,cAAc,KAAK,YAAY,oBAAoB;;;;;;;;;wBAYrE,aAAa,QAAQ,eAAe,KAAK,YAAY;WAA+B,OAAO;WAAuB,KAAK;;;;;;;;;wBAoBvH,cAAc,OAAO,cAAc,KAAK,YAAY,gB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;WACN,OAAO;;WAEP,gBAAgB;;WAEhB,kBAAkB;;WAElB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAmKK,aAAa,OAAO,oBAAoB;;qBC9U3C;;qBAEA;;qBAEA;;YAGD;;iBAGK;WACN;;WAEA,QAAQ;WACR,kBAAkB;;WAElB;;;iBAIM;WACN;WACA;;;iBAIM;;WAEN;;WAEA;WACA,OAAO;WACP,MAAM,gBAAgB;;;qBAIpB,sBAAsB;;qBAWtB,mBAAmB;;;;;;;;;;qBAmBnB,sBAAsB;;;;;;;;;qBAiDtB;;YAGD,wBAAwB;;YAGxB,mBAAmB,QAAQ,gBAAgB;;;;;;;;;wBA4BvC,gBAAgB,gBAAgB,aAAa,UAAU,cAAc"}
package/build/index.js CHANGED
@@ -689,6 +689,30 @@ const FORMULA_FEEDS = {
689
689
  source: WIC_INFANT_SOURCE,
690
690
  locator: "Table 5.2, Guidelines for Feeding Healthy Infants, Birth to 12 Months Old, page 137"
691
691
  };
692
+ /** The source of the energy of one fluid ounce of ready-to-feed formula: the SR Legacy file of FoodData Central. */
693
+ const FDC_SR_LEGACY_SOURCE = {
694
+ id: "fdc-sr-legacy-2018-04",
695
+ title: "FoodData Central, SR Legacy (April 2018)",
696
+ url: "https://fdc.nal.usda.gov/fdc-datasets/FoodData_Central_sr_legacy_food_csv_2018-04.zip",
697
+ license: "cc0",
698
+ checked: "2026-11-24",
699
+ by: "USDA Agricultural Research Service",
700
+ terms: "https://fdc.nal.usda.gov/download-datasets",
701
+ sha256: "b80817294b8850530aaedf2e515c02593b1824f763a0ff356e5c2081643e6fd0"
702
+ };
703
+ /**
704
+ * The least formula of one infant from 6 months: 24 fl oz a day. Table 5.2 of the WIC guide gives 24 to 32 ounces at 6 to 8 months,
705
+ * and 24 ounces at 8 to 12 months. The FDC item 172319 gives 63 kcal in 100 g and 30.4 g in 1 fl oz, thus 19.152 kcal in 1 fl oz.
706
+ */
707
+ const FORMULA_LATER_LEAST = {
708
+ perDay: 459.648,
709
+ ounces: 24,
710
+ ouncesSource: WIC_INFANT_SOURCE,
711
+ ouncesLocator: "Table 5.2, Guidelines for Feeding Healthy Infants, Birth to 12 Months Old, page 137",
712
+ kcalPerOunce: 19.152,
713
+ kcalSource: FDC_SR_LEGACY_SOURCE,
714
+ kcalLocator: "FDC ID 172319: 63 kcal in 100 g (food_nutrient.csv), and 30.4 g in 1 fl oz (food_portion.csv)"
715
+ };
692
716
  /** The source of the infant table: the PDF of the report Dietary Reference Intakes for Energy (2023) of the National Academies. */
693
717
  const NASEM_ENERGY_SOURCE = {
694
718
  id: "nasem-dri-energy-2023",
@@ -1298,6 +1322,7 @@ function openedStores(input, stores, noReads, feed) {
1298
1322
  * - The draw of food energy has the rate of the need of its persons for one day, and its users are the persons.
1299
1323
  * - The draw of formula has the infants on formula below `FORMULA_DRAW_MONTHS`, with the whole need of their rows.
1300
1324
  * With `formulaLater: "whole"`, it also has the older infants on formula, with the whole need of their rows.
1325
+ * With `formulaLater: "least"`, it has `FORMULA_LATER_LEAST` of each older infant, and the food draw has the rest.
1301
1326
  * - The fragment has each draw with one or more users. The draw of food energy is first.
1302
1327
  * - 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.
1303
1328
  * - The direct uses are each use of `uses` for the need of a draw. The default `DIRECT_USES` gives 1 kcal for each kcal.
@@ -1321,7 +1346,8 @@ function openedStores(input, stores, noReads, feed) {
1321
1346
  * When the infants are more, the function gives no layer: the change of a stage is the milk of one infant.
1322
1347
  * - `formula`: below `FORMULA_DRAW_MONTHS`, the whole need of the infant is in the draw of formula, because the infant has milk only.
1323
1348
  * From `FORMULA_DRAW_MONTHS`, no cited source gives the part of formula, so the infant gives no layer, as a person with no row.
1324
- * The option `leave-out` also applies. The option `formulaLater: "whole"` puts the whole need in the formula draw: the upper limit. The feeding is only for an infant below `INFANT_MONTHS`.
1349
+ * The option `leave-out` also applies. The option `formulaLater: "whole"` puts the whole need in the formula draw: the upper limit.
1350
+ * The option `formulaLater: "least"` puts the lower limit in the formula draw, and the rest of the need in the food draw. The feeding is only for an infant below `INFANT_MONTHS`.
1325
1351
  *
1326
1352
  * The function is pure.
1327
1353
  *
@@ -1379,6 +1405,16 @@ function householdFragment(input) {
1379
1405
  formulaUsers += person.count;
1380
1406
  formulaPerDay += line.need.value;
1381
1407
  formulaLeast = Math.min(formulaLeast, line.need.value / person.count);
1408
+ } else if (line.read && input.formulaLater === "least") {
1409
+ const each = Math.min(FORMULA_LATER_LEAST.perDay, line.need.value / person.count);
1410
+ formulaUsers += person.count;
1411
+ formulaPerDay += each * person.count;
1412
+ formulaLeast = Math.min(formulaLeast, each);
1413
+ const rest = line.need.value - each * person.count;
1414
+ if (rest > 0) {
1415
+ users += person.count;
1416
+ perDay += rest;
1417
+ }
1382
1418
  } else formulaLater.push(person);
1383
1419
  } else if (!line.read) noRow.push(person);
1384
1420
  else {
@@ -1955,6 +1991,6 @@ function checkDailyNeeds(needs, options) {
1955
1991
  });
1956
1992
  return findings;
1957
1993
  }
1958
- export { ACTIVITY_LEVELS, ALERT_WATCH_NEED, BOIL_CELSIUS, BREAST_MILK_MONTHS, CALORIE_CHAIN, CALORIE_SEXES, CALORIE_TABLES, COLD_START_CELSIUS, DAILY_NEEDS, DAILY_NEED_CODES, DGA_CALORIES, DGA_SOURCE, DIRECT_USES, FOOD_NEED, FORMULA_DRAW_MONTHS, FORMULA_FEEDS, FORMULA_NEED, FORMULA_READY, INFANT_FEEDINGS, INFANT_MONTHS, JOIN_CODES, LIGHT_NEED, MILK_LATER, NASEM_ENERGY_SOURCE, NASEM_INFANT_CALORIES, NEEDS_CODES, NEED_SUPPLIES, NIST_SI_GUIDE_SOURCE, NO_COOK, NWS_ALARMS_SOURCE, NWS_RECEIVERS_SOURCE, STORED_WATER, USGS_WATER_DENSITY_SOURCE, WARMTH_NEED, WATER_DENSITY_MAX, WATER_NEED, WATER_SPECIFIC_HEAT, WIC_INFANT_SOURCE, calorieChange, calorieNeed, calorieRow, calorieRowOf, checkCalorieChain, checkCalorieTable, checkDailyNeeds, checkJoins, cookFragment, hasNeedsError, householdFragment, isActivityLevel };
1994
+ export { ACTIVITY_LEVELS, ALERT_WATCH_NEED, BOIL_CELSIUS, BREAST_MILK_MONTHS, CALORIE_CHAIN, CALORIE_SEXES, CALORIE_TABLES, COLD_START_CELSIUS, DAILY_NEEDS, DAILY_NEED_CODES, DGA_CALORIES, DGA_SOURCE, DIRECT_USES, FDC_SR_LEGACY_SOURCE, FOOD_NEED, FORMULA_DRAW_MONTHS, FORMULA_FEEDS, FORMULA_LATER_LEAST, FORMULA_NEED, FORMULA_READY, INFANT_FEEDINGS, INFANT_MONTHS, JOIN_CODES, LIGHT_NEED, MILK_LATER, NASEM_ENERGY_SOURCE, NASEM_INFANT_CALORIES, NEEDS_CODES, NEED_SUPPLIES, NIST_SI_GUIDE_SOURCE, NO_COOK, NWS_ALARMS_SOURCE, NWS_RECEIVERS_SOURCE, STORED_WATER, USGS_WATER_DENSITY_SOURCE, WARMTH_NEED, WATER_DENSITY_MAX, WATER_NEED, WATER_SPECIFIC_HEAT, WIC_INFANT_SOURCE, calorieChange, calorieNeed, calorieRow, calorieRowOf, checkCalorieChain, checkCalorieTable, checkDailyNeeds, checkJoins, cookFragment, hasNeedsError, householdFragment, isActivityLevel };
1959
1995
 
1960
1996
  //# 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","../src/cook.ts","../src/daily.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`: the milk of a person of the household. Below 6 months, the infant has only milk. From 6 months, the infant also has food.\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 feeds of formula: the PDF of the infant guide of the WIC program. It is a work of the United States federal government. */\nexport const WIC_INFANT_SOURCE: Source = {\n id: \"wic-infant-guide-2019\",\n title: \"Infant Nutrition and Feeding: A Guide for Use in the WIC and CSF Programs\",\n url: \"https://wicworks.fna.usda.gov/sites/default/files/media/document/infant-feeding-guide.pdf\",\n license: \"us-public-domain\",\n checked: \"2026-11-24\",\n by: \"USDA Food and Nutrition Service\",\n terms: \"https://wicworks.fna.usda.gov/resources/infant-nutrition-and-feeding-guide\",\n sha256: \"d0c043cc70dedf16920673f57cc4771692974db30761df351faec4e56db45b1d\",\n};\n\n/** A count of feeds in one day, with its source and its place in the source. */\nexport interface CitedFeeds {\n readonly perDay: number;\n readonly source: Source;\n readonly locator: string;\n}\n\n/**\n * The most feeds of formula in one day below 6 months: 8. Table 5.2 of the WIC guide gives 2 to 3 ounces every 3 to 4 hours.\n * 24 hours divided by 3 hours is 8. More feeds give smaller feeds and thus more waste, so this value is the most feeds.\n */\nexport const FORMULA_FEEDS: CitedFeeds = { perDay: 8, source: WIC_INFANT_SOURCE, locator: \"Table 5.2, Guidelines for Feeding Healthy Infants, Birth to 12 Months Old, page 137\" };\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/** The energy of the breast milk of one infant for one day, with its source and its place in the source. */\nexport interface CitedMilk {\n readonly perDay: number;\n readonly source: Source;\n readonly locator: string;\n}\n\n/**\n * The energy of the breast milk of one infant from 6 months: 381 kcal/d. Table 5-14 of the NASEM report gives 568 g/d of milk\n * at 7 to 12 months for women that partly breastfeed, at 0.67 kcal/g. Its value at 6 months, 599 kcal/d, is for women that\n * only breastfeed. An infant from 6 months also has food, so the lower value gives the larger draw, the worst case.\n */\nexport const MILK_LATER: CitedMilk = { perDay: 381, source: NASEM_ENERGY_SOURCE, locator: \"Table 5-14, Energy Cost of Milk Production in Breastfeeding Women During the First Year Postpartum, page 97\" };\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 { canonicalUnit, quantity, valueIn } from \"@mark1russell7/quantity\";\nimport { calorieChange, calorieNeed, INFANT_FEEDINGS, type ActivityLevel, type CalorieNeedTotal, type CalorieTable, type CalorieTables, type Person } from \"./calorie.ts\";\nimport { CALORIE_CHAIN, FORMULA_FEEDS, MILK_LATER } 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. `cookFragment` gives the converters of the dry food, with the water and the fuel of each pot.\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 the food draw holds a part of the need of an infant on breast milk: 6.\n * Below this age, the infant has milk only, and the stage of lactation of the mother holds that energy.\n * From this age, the food draw holds the need of the row minus the milk energy `MILK_LATER`.\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 * True when the household has cold storage for an opened container. The default is false: the worst case of no power.\n * Then an opened container of formula serves one feed, and the rest is waste.\n */\n readonly cold?: boolean | undefined;\n /**\n * The rule for an infant on formula from `FORMULA_DRAW_MONTHS`. Without it, the infant is a person with no row.\n * With `whole`, the formula draw holds the whole need of the row: the upper limit of formula. The food draw holds none of it.\n */\n readonly formulaLater?: \"whole\" | undefined;\n}\n\n/** The waste of the opened containers of one product of the buy list with no cold storage. */\nexport interface OpenedWaste {\n readonly product: string;\n readonly resource: string;\n /** The count of containers in the buy list. */\n readonly containers: number;\n /** The energy of one container, in `kcal`. */\n readonly container: number;\n /** The energy of the smallest feed of the formula draw, in `kcal`. */\n readonly feed: number;\n /** The energy that the infants use from the containers, in `kcal`. It is the amount of the store. */\n readonly used: number;\n /** The energy of the containers that is waste, in `kcal`. */\n readonly waste: number;\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. Each infant below `BREAST_MILK_MONTHS` 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. From that age, the draw holds the row minus `MILK_LATER`.\n */\n readonly breastMilk: readonly Person[];\n /** The waste of each product with opened containers, with no cold storage. With `cold: true`, the list is empty. */\n readonly waste: readonly OpenedWaste[];\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. */\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 applies the rule of an opened container with no cold storage to the stores of the buy list.\n * An opened container serves one feed. A feed that is more than a container takes more containers, and the rest of the last is waste.\n * Thus each container gives `feed / ceil(feed / container)` kcal. The feed is the smallest feed of the formula draw, the worst case.\n * A product with a container of no read gives no store, and a gift with no read.\n *\n * @throws RangeError when a product with opened containers gives a resource that feeds no formula draw\n */\nfunction openedStores(\n input: HouseholdFragmentInput,\n stores: readonly FragmentStore[],\n noReads: readonly GiftNoRead[],\n feed: number | undefined,\n): { stores: FragmentStore[]; noReads: GiftNoRead[]; waste: OpenedWaste[] } {\n const out = { stores: [...stores], noReads: [...noReads], waste: [] as OpenedWaste[] };\n if (input.cold === true) return out;\n const prefix = input.prefix ?? \"buy\";\n const formulaResources = new Set((input.uses ?? DIRECT_USES).filter((use) => use.need === FORMULA_NEED).map((use) => use.resource));\n for (const [id, count] of Object.entries(input.units)) {\n const product = input.catalog.products.find((each) => each.id === id);\n const opened = product?.opened;\n if (product === undefined || opened === undefined || !(count > 0)) continue;\n for (const store of stores.filter((each) => each.id.startsWith(`${prefix}:${id}:`))) {\n if (!formulaResources.has(store.resource)) {\n throw new RangeError(`The product ${id} spoils after its container is opened, and its resource ${store.resource} feeds no formula draw. Only the formula draw has a cited size of one feed.`);\n }\n if (feed === undefined) continue;\n const { container } = opened;\n const size = product.size;\n out.stores = out.stores.filter((each) => each.id !== store.id);\n if (!container.read || size === undefined || !size.read) {\n const why = container.read ? \"The size of the product is no read.\" : `The size of a container is no read: ${container.why}`;\n out.noReads.push({ product: id, resource: store.resource, why: `With no cold storage, an opened container serves one feed (fact ${opened.noCold}). ${why}` });\n continue;\n }\n const unit = canonicalUnit(container.unit);\n const perUnit = Math.round(valueIn(quantity(size.amount, canonicalUnit(size.unit)), unit) / valueIn(quantity(container.amount, unit), unit));\n const containers = count * perUnit;\n const each = store.amount / containers;\n // A small margin keeps a feed of exactly k containers at k containers.\n const used = containers * (feed / Math.ceil(feed / each - 1e-9));\n out.stores.push({ ...store, amount: used });\n out.waste.push({ product: id, resource: store.resource, containers, container: each, feed, used, waste: store.amount - used });\n }\n }\n return out;\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 * With `formulaLater: \"whole\"`, it also has the older infants on formula, 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. `cookFragment` gives the converters for the dry food, with the water and the fuel of each pot.\n * - With no cold storage (the default), an opened container of formula serves one feed. The store has only the energy of the feeds,\n * and `waste` gives the rest. The smallest feed is the smallest need of an infant of the draw, divided by `FORMULA_FEEDS`.\n * A container of no read gives no store and a gift with no read, so the stores are a lower limit.\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`: below `BREAST_MILK_MONTHS`, the infant has a line, and no part of the draw. From that age, the food draw\n * holds the need of the row minus the milk energy `MILK_LATER`. The feeding is only for an infant below `INFANT_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 option `formulaLater: \"whole\"` puts the whole need in the formula draw: the upper limit. 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 product with opened containers gives a resource that feeds no formula draw, with no cold storage\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` and `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 smallest daily need of one infant of the formula draw, for the smallest feed.\n let formulaLeast = Number.POSITIVE_INFINITY;\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 if (person.ageMonths >= BREAST_MILK_MONTHS) {\n // The infant also has food. The food draw holds the need of the row minus the milk energy.\n if (!line.read) noRow.push(person);\n else {\n users += person.count;\n perDay += Math.max(0, line.need.value - MILK_LATER.perDay * person.count);\n }\n }\n } else if (person.feeding === \"formula\") {\n formula.push(person);\n if (line.read && (person.ageMonths < FORMULA_DRAW_MONTHS || input.formulaLater === \"whole\")) {\n formulaUsers += person.count;\n formulaPerDay += line.need.value;\n formulaLeast = Math.min(formulaLeast, line.need.value / person.count);\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 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 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 const feed = formulaUsers > 0 && formulaPerDay > 0 ? formulaLeast / FORMULA_FEEDS.perDay : undefined;\n const opened = openedStores(input, stores, parts.noReads, feed);\n return {\n ...parts,\n noReads: opened.noReads,\n storesRead: opened.noReads.length === 0,\n layer: {\n schema: \"endurance/1\",\n levels: [...(input.levels ?? [])],\n resources: layerResources(input.catalog, opened.stores, uses),\n stores: opened.stores,\n draws,\n direct: uses.map((use) => ({ ...use })),\n },\n need,\n needRead: true,\n leftOut: [...noRow, ...formulaLater],\n formula,\n breastMilk,\n waste: opened.waste,\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 !== \"food\" && !(person.ageMonths < INFANT_MONTHS)) {\n throw new RangeError(`The persons ${nameOf(person)} have feeding: ${feeding}, 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","import type { Source } from \"@mark1russell7/guidebook\";\nimport { fuelEnergyPerMass, giftsOf, cookWater, type CitedRate, type HeatingValue, type StoveFacts, type SupplyCatalog, type SupplyProduct } from \"@mark1russell7/market/supplies\";\nimport { valueIn, type Quantity } from \"@mark1russell7/quantity\";\nimport { FOOD_NEED, STORED_WATER } from \"./uses.ts\";\n\n// The water and the fuel to cook the dry food of a buy list, as converters of an endurance layer.\n// One run of a converter is one pot: the dry food, the cook water and the fuel of the pot give the food energy of the pot.\n// Thus a dry food with no fuel or no water gives no meal. The records have the form of `Converter` of stack-endurance.\n// Each value comes from a cited fact of the catalog, a cited input or a cited constant. A missing fact gives a no read.\n\n/** The source of the specific heat of water: the NIST Guide to the SI (Special Publication 811). It is a work of the United States federal government. */\nexport const NIST_SI_GUIDE_SOURCE: Source = {\n id: \"nist-sp-811\",\n title: \"NIST Guide to the SI (Special Publication 811), Appendix B.8 and footnotes\",\n url: \"https://www.nist.gov/pml/special-publication-811/nist-guide-si-appendix-b-conversion-factors/nist-guide-si-appendix-b8\",\n license: \"us-public-domain\",\n checked: \"2026-11-24\",\n by: \"National Institute of Standards and Technology\",\n terms: \"https://www.nist.gov/oism/copyrights\",\n note: \"The footnotes are at https://www.nist.gov/pml/special-publication-811/nist-guide-si-footnotes.\",\n};\n\n/** The source of the density of water: the page Water Density of the USGS Water Science School. It is a work of the United States federal government. */\nexport const USGS_WATER_DENSITY_SOURCE: Source = {\n id: \"usgs-water-density\",\n title: \"Water Density, USGS Water Science School\",\n url: \"https://www.usgs.gov/special-topics/water-science-school/science/water-density\",\n license: \"us-public-domain\",\n checked: \"2026-11-24\",\n by: \"U.S. Geological Survey\",\n terms: \"https://www.usgs.gov/information-policies-and-instructions/copyrights-and-credits\",\n};\n\n/** A physical constant of the cook model, with its source and the place of the value in the source. */\nexport interface CookConstant {\n readonly value: number;\n readonly unit: string;\n readonly source: Source;\n readonly locator: string;\n /** How the value comes from the source. */\n readonly note: string;\n}\n\n/**\n * The mean specific heat of liquid water from 0 °C to 100 °C: 4.19002 kJ/(kg.K).\n * The NIST Guide to the SI gives 4.190 02 J for the calorie (mean). The common definition of that calorie is the mean over this range.\n * SP 811 does not state the range. Its footnote 10 tells that the calorie is the energy to raise 1 g of water\n * by 1 kelvin. For the default start (0 °C), the value is the mean of the rise. For a warmer start, the mean of the\n * rise can be a little higher. The model also heats the dry food with this value, above the specific heat of a dry food.\n * That term holds the heat of the pot above the true value.\n */\nexport const WATER_SPECIFIC_HEAT: CookConstant = {\n value: 4.19002,\n unit: \"kJ/(kg.K)\",\n source: NIST_SI_GUIDE_SOURCE,\n locator: \"Appendix B.8, row calorie (mean): 4.190 02 E+00 J. Footnotes, footnote 10: the energy to raise 1 gram of water by 1 °C.\",\n note: \"The calorie (mean) in joules, for 1 g of water and 1 K. By its common definition, the mean is over the range from 0 °C to 100 °C. SP 811 does not state the range.\",\n};\n\n/**\n * The largest density of liquid water: 1 kg/L. The USGS table gives 1.00000 g/cm3 at 4.0 °C, its largest value.\n * Thus 1 L of cook water is 1 kg or less.\n */\nexport const WATER_DENSITY_MAX: CookConstant = {\n value: 1,\n unit: \"kg/L\",\n source: USGS_WATER_DENSITY_SOURCE,\n locator: \"Table of the density and the weight of water by temperature, row 39.2 °F/4.0 °C: 1.00000 g/cm3\",\n note: \"The largest density of the table, from 0 °C to 100 °C. Each other row is less.\",\n};\n\n/**\n * The temperature at the end of the heat to boil, in °C.\n * Water boils at a lower temperature at a high place. Then the heat is less.\n * But the cook time is longer there, and the model does not give that time. Thus at a high place the fuel is not an upper limit.\n */\nexport const BOIL_CELSIUS = 100;\n\n/**\n * The default start temperature of the cook water, in °C: 0, the freezing point. Liquid water at the pressure of the sea is\n * not colder. Thus the default gives the most heat. A caller gives a warmer start with its citation.\n */\nexport const COLD_START_CELSIUS = 0;\n\n/** The start temperature of the cook water, with the citation of the caller, for example a read of the stored water. */\nexport interface CookStart {\n /** The temperature in °C, from 0 up to less than `BOIL_CELSIUS`. */\n readonly celsius: number;\n /** The citation of the value: the `id` of a fact or a source of the caller. */\n readonly cite: string;\n}\n\n/**\n * The stove share is the part of the heat of the fuel that goes into the water and the food of the pot.\n * Its value is from more than 0 to 1, with its citation. The heat of the pot itself is in the losses. `heating` tells the heating value of the fuel energy that the share applies to.\n */\nexport interface StoveShare {\n readonly value: number;\n readonly heating: HeatingValue;\n /** The citation of the value: the `id` of a fact or a source of the caller. */\n readonly cite: string;\n}\n\n/** The inputs of the cook fragment. */\nexport interface CookFragmentInput {\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 stove: the `id` of a product of the catalog with stove facts, or the cited stove facts of the caller. */\n readonly stove: string | StoveFacts;\n /**\n * The dry mass of the food of one pot, for example `{ \"value\": 0.5, \"unit\": \"kg\" }`. It is a plan of the caller. It has no default.\n * Give the smallest pot that the cook makes. A batch above the real pot gives too little fuel, because each pot takes its own cook time.\n */\n readonly batch: Quantity;\n /** The stove share. Without it, the fuel of the boil is a no read, so each fuel is a no read. It has no default. */\n readonly share?: StoveShare | undefined;\n /** The start temperature of the cook water. The default is `COLD_START_CELSIUS`. */\n readonly start?: CookStart | undefined;\n /** The `id` of the stove in the stack. The converters stop when the stove stops. */\n readonly device?: string | undefined;\n /** The start of the `id` of each converter. The default is `cook`. */\n readonly prefix?: string | undefined;\n}\n\n/** A value of the cook model with a read, in its unit, or no read with the reasons. A no read is not 0. */\nexport type CookRead = { readonly read: true; readonly value: number; readonly unit: string } | { readonly read: false; readonly why: string };\n\n/** The cook values of one dry food of the buy list, for one pot. */\nexport interface CookLine {\n readonly product: string;\n /** The dry resource of the product, for example `food.grain-dry`. */\n readonly resource: string;\n /** The food energy of the dry food, in `kcal/kg`. */\n readonly energy: CookRead;\n /** The cook water, in `L/kg` of dry food, from `cookWater` of market. */\n readonly water: CookRead;\n /** The heat to boil the cook water of one pot, in `kJ`. */\n readonly heat: CookRead;\n /** The time of the stove for one pot: the boil time and the high end of the cook time, in `min`. */\n readonly minutes: CookRead;\n /** The fuel of one pot, in `kg`. */\n readonly fuel: CookRead;\n}\n\n/** A converter of the cook fragment, with the form of `Converter` of `@mark1russell7/stack-endurance`. */\nexport interface FragmentConverter {\n readonly id: string;\n readonly device?: string | undefined;\n readonly takes: readonly { readonly resource: string; readonly amount: number }[];\n readonly gives: { readonly need: string; readonly amount: number };\n}\n\n/** The cook fragment of an endurance layer: the resources and one converter for each dry resource with a read. It has no store and no draw. */\nexport interface CookFragment {\n /** The format of an endurance layer, `endurance/1`. */\n readonly schema: \"endurance/1\";\n readonly levels: readonly string[];\n readonly resources: readonly { readonly code: string; readonly unit: string }[];\n readonly stores: readonly never[];\n readonly draws: readonly never[];\n readonly converters: readonly FragmentConverter[];\n}\n\n/** A dry resource of the buy list with no converter, and the reasons. */\nexport interface CookNoRead {\n readonly resource: string;\n readonly why: string;\n}\n\n/** The cook fragment, the line of each dry food and the dry resources with no converter. */\nexport interface CookFragmentResult {\n readonly layer: CookFragment;\n /** The line of each dry food of the buy list, in the order of the list. */\n readonly lines: readonly CookLine[];\n /** The dry resources with no converter. Their dry food gives no meal in the layer. */\n readonly noReads: readonly CookNoRead[];\n /** True when each dry resource of the buy list has a converter. When it is false, the cooked days are a lower limit. */\n readonly read: boolean;\n}\n\n/** This function gives the value of an amount in a unit, or `undefined` when the units do not convert. */\nfunction inUnit(value: number, from: string, to: string): number | undefined {\n try {\n const out = valueIn({ value, unit: from }, to);\n return Number.isFinite(out) ? out : undefined;\n } catch {\n return undefined;\n }\n}\n\n/** A fuel rate of a stove, in an energy or in a mass for each minute. */\ntype StoveRate = { readonly kind: \"energy\"; readonly perMin: number } | { readonly kind: \"mass\"; readonly perMin: number };\n\n/** This function gives the fuel rate of a stove in `kJ/min` or `kg/min`. It gives `undefined` for a rate that is not an energy or a mass in a time. */\nfunction stoveRate(rate: CitedRate): StoveRate | undefined {\n const minutes = inUnit(rate.per.amount, rate.per.unit, \"min\");\n if (minutes === undefined || !(minutes > 0)) return undefined;\n const energy = inUnit(rate.amount, rate.unit, \"kJ\");\n if (energy !== undefined) return { kind: \"energy\", perMin: energy / minutes };\n const mass = inUnit(rate.amount, rate.unit, \"kg\");\n if (mass !== undefined) return { kind: \"mass\", perMin: mass / minutes };\n return undefined;\n}\n\nconst read = (value: number, unit: string): CookRead => ({ read: true, value, unit });\nconst noRead = (why: string): CookRead => ({ read: false, why });\n\n/** The inputs of one line that do not change with the product. */\ninterface StoveContext {\n readonly stove: StoveFacts;\n readonly batchKg: number;\n readonly share: StoveShare | undefined;\n readonly startC: number;\n /** The energy of the fuel in `kJ/kg`, and its heating value, or `undefined` when the fuel has no cited energy. */\n readonly fuelEnergy: { readonly perKg: number; readonly heating: HeatingValue } | undefined;\n}\n\n/**\n * This function gives the cook line of one dry food. Each missing fact gives a no read with its reason.\n * The fuel is a safe upper limit: the stove burns at its full rate for the boil time and the cook time.\n * At a high place the cook time is longer. The model does not give that time, so there the fuel is not an upper limit.\n */\nfunction cookLine(product: SupplyProduct, resource: string, perUnitKg: number | undefined, foodGifts: number, context: StoveContext): CookLine {\n const { stove, batchKg, share, startC, fuelEnergy } = context;\n\n let energy: CookRead;\n if (foodGifts > 1) energy = noRead(`The product ${product.id} gives ${String(foodGifts)} foods. The catalog gives one energy for the whole product, not the energy of each food.`);\n else if (product.energy === undefined) energy = noRead(`The product ${product.id} has no food energy in the catalog.`);\n else if (!product.energy.read) energy = noRead(`The food energy of the product ${product.id} is a no read: ${product.energy.why}`);\n else {\n const kcal = inUnit(product.energy.amount, product.energy.unit, \"kcal\");\n if (kcal === undefined) energy = noRead(`The food energy of the product ${product.id} is in ${product.energy.unit}, which does not convert to kcal.`);\n else if (perUnitKg === undefined || !(perUnitKg > 0)) energy = noRead(`The gift of ${resource} of the product ${product.id} has no read in kg.`);\n else energy = read(kcal / perUnitKg, \"kcal/kg\");\n }\n\n const litres = cookWater(product);\n const water = litres === undefined ? noRead(`The catalog cites no cook water for the product ${product.id}, or no bulk mass for its water rate.`) : read(valueIn(litres, \"L/kg\"), \"L/kg\");\n\n // The heat to boil one pot: the mass of the water and the dry food times the specific heat of water times the rise to the boil.\n const heat = water.read ? read((water.value * WATER_DENSITY_MAX.value + 1) * batchKg * WATER_SPECIFIC_HEAT.value * (BOIL_CELSIUS - startC), \"kJ\") : noRead(`The heat to boil is a no read: ${water.why}`);\n\n const why: string[] = [];\n if (!heat.read) why.push(heat.why);\n const time = product.cook?.time;\n const cookMin = time === undefined ? undefined : inUnit(time.high, time.unit, \"min\");\n if (time === undefined) why.push(`The catalog cites no cook time for the product ${product.id}.`);\n else if (cookMin === undefined) why.push(`The cook time of the product ${product.id} is in ${time.unit}, which does not convert to min.`);\n\n const rate = stove.rate === undefined ? undefined : stoveRate(stove.rate);\n if (stove.rate === undefined) why.push(`The stove of ${stove.fuel} has no cited fuel rate.`);\n else if (rate === undefined) why.push(`The fuel rate of the stove is in ${stove.rate.unit} for each ${stove.rate.per.unit}, which is not an energy or a mass in a time.`);\n\n // The heat of the stove into the pot for each minute, in kJ/min. It needs a cited share with the same heating value as the energy rate.\n let potPerMin: number | undefined;\n if (share === undefined) why.push(\"No cited stove share gives the part of the stove heat that goes into the pot. Thus the fuel of the boil is a no read.\");\n else if (rate !== undefined) {\n if (rate.kind === \"energy\") {\n if (stove.heating !== share.heating) why.push(`The stove share is for the ${share.heating} heating value, and the stove rate is for the ${String(stove.heating ?? \"unknown\")} heating value.`);\n else potPerMin = rate.perMin * share.value;\n } else if (fuelEnergy === undefined) why.push(`The fuel ${stove.fuel} has no cited energy, so its mass rate gives no heat for the boil.`);\n else if (fuelEnergy.heating !== share.heating) why.push(`The stove share is for the ${share.heating} heating value, and the energy of the fuel ${stove.fuel} is the ${fuelEnergy.heating} value.`);\n else potPerMin = rate.perMin * fuelEnergy.perKg * share.value;\n }\n\n // The fuel mass for each minute at the full rate, in kg/min. An energy rate converts only through the cited fuel energy of the same heating value.\n let fuelPerMin: number | undefined;\n if (rate?.kind === \"mass\") fuelPerMin = rate.perMin;\n else if (rate?.kind === \"energy\") {\n if (fuelEnergy === undefined) why.push(`The fuel ${stove.fuel} has no cited energy, so the energy rate of the stove gives no fuel mass.`);\n else if (stove.heating === undefined) why.push(\"The energy rate of the stove has no heating value.\");\n else if (stove.heating !== fuelEnergy.heating) why.push(`The stove rate is for the ${stove.heating} heating value, and the energy of the fuel ${stove.fuel} is the ${fuelEnergy.heating} value.`);\n else fuelPerMin = rate.perMin / fuelEnergy.perKg;\n }\n\n if (why.length > 0 || !heat.read || cookMin === undefined || potPerMin === undefined || fuelPerMin === undefined || !(potPerMin > 0)) {\n const text = why.join(\" \");\n return { product: product.id, resource, energy, water, heat, minutes: noRead(text), fuel: noRead(text) };\n }\n const minutes = heat.value / potPerMin + cookMin;\n return { product: product.id, resource, energy, water, heat, minutes: read(minutes, \"min\"), fuel: read(minutes * fuelPerMin, \"kg\") };\n}\n\n/** This function gives the stove facts of the input: the facts of the caller, or the facts of a product of the catalog. */\nfunction stoveOf(catalog: SupplyCatalog, stove: string | StoveFacts): StoveFacts {\n if (typeof stove !== \"string\") return stove;\n const product = catalog.products.find((item) => item.id === stove);\n if (product === undefined) throw new RangeError(`The catalog has no product \"${stove}\".`);\n if (product.stove === undefined) throw new RangeError(`The product \"${stove}\" has no stove facts.`);\n return product.stove;\n}\n\n/** This function tells if a resource of the catalog is a food. */\nfunction isFood(catalog: SupplyCatalog, code: string): boolean {\n return catalog.resources.find((item) => item.code === code)?.kind === \"food\";\n}\n\n/** This function tells if a resource of the catalog is a dry food: a food resource in a unit of mass. */\nfunction isDryFood(catalog: SupplyCatalog, code: string): boolean {\n const resource = catalog.resources.find((item) => item.code === code);\n return resource !== undefined && resource.kind === \"food\" && inUnit(1, resource.unit, \"kg\") !== undefined;\n}\n\n/**\n * This function gives the converters that cook the dry food of a buy list, with the water and the fuel of each pot.\n *\n * - One run of a converter is one pot of `batch`. It takes the dry food, the cook water from `water.stored` and the fuel of the stove.\n * It gives the food energy of the pot to the need `food.energy`. Thus a dry food with no fuel or no water gives no meal.\n * - The cook water is `cookWater` of market times the dry mass. It is the resource of the drinking water.\n * - The heat to boil is the mass of the water and the dry food times `WATER_SPECIFIC_HEAT` times the rise from the start to `BOIL_CELSIUS`.\n * The water mass takes `WATER_DENSITY_MAX`. The dry food takes the specific heat of water, which is higher than its own.\n * - The boil time is the heat divided by the stove rate times the share. The time of the stove is the boil time plus the high end of the cook time.\n * - The fuel is a safe upper limit: the stove burns at its full rate for all of that time. At a high place the cook time is longer.\n * The model does not give that time, so there the fuel is not an upper limit.\n * - A rate in a mass gives the fuel directly. A rate in an energy gives a mass only through the cited energy of the fuel, with the same heating value.\n *\n * A dry food is a gift of a food resource in a unit of mass. Each missing fact gives a line with no read and its reasons, not a figure.\n * Two products of the list can give one dry resource, for example rice and oats. The converter then takes the worst case of their lines:\n * the most water, the most fuel and the least food energy. When a line of the resource has no read, the resource has no converter.\n * A store of the resource from a different fragment gets the converter of this list.\n *\n * The catalog of market gives no soak water. A food that needs a soak, for example dry beans, has a second water draw that this function does not give.\n * A product that gives more than one food has no energy for each food, so its energy is a no read.\n *\n * The cook water is `water.stored`, the store of the drinking water. A drinking draw at a higher level of the same store takes\n * its water first, by the take order of `enduranceOf`. The drinking draw keeps back its days times its demand, which is all of the store.\n * Thus, when a case cuts the water supply, the dry food adds 0 days at each amount of stored water.\n *\n * The function is pure.\n *\n * @param input - The catalog and the buy list, the stove, the dry mass of one pot, the share and the start temperature\n * @returns The fragment, the line of each dry food and the dry resources with no converter\n * @throws RangeError when the batch is not a mass above 0, or when the share is not above 0 and up to 1\n * @throws RangeError when the start is not from 0 up to less than 100 °C\n * @throws RangeError when the stove is a product with no stove facts\n * @throws RangeError when the catalog has no product of an `id` of the buy list\n * @throws RangeError when the catalog has no resource of the fuel in a unit of mass\n * @throws RangeError when a converter has a read and the catalog has no resource `water.stored` in a unit of volume\n * @throws RangeError for the errors of `giftsOf`\n */\nexport function cookFragment(input: CookFragmentInput): CookFragmentResult {\n const { catalog, units } = input;\n const batchKg = inUnit(input.batch.value, input.batch.unit, \"kg\");\n if (batchKg === undefined || !(batchKg > 0)) throw new RangeError(`The batch ${String(input.batch.value)} ${input.batch.unit} is not a mass above 0.`);\n const { share } = input;\n if (share !== undefined && !(share.value > 0 && share.value <= 1)) throw new RangeError(`The stove share is ${String(share.value)}. It must be above 0 and up to 1.`);\n const startC = input.start?.celsius ?? COLD_START_CELSIUS;\n if (!(startC >= 0 && startC < BOIL_CELSIUS)) throw new RangeError(`The start temperature is ${String(startC)} °C. It must be from 0 up to less than ${String(BOIL_CELSIUS)} °C.`);\n const stove = stoveOf(catalog, input.stove);\n const fuel = catalog.resources.find((resource) => resource.code === stove.fuel);\n const fuelUnitPerKg = fuel === undefined ? undefined : inUnit(1, \"kg\", fuel.unit);\n if (fuel === undefined || fuelUnitPerKg === undefined) throw new RangeError(`The catalog has no resource \"${stove.fuel}\" in a unit of mass for the fuel of the stove.`);\n const perKg = fuelEnergyPerMass(fuel);\n const context: StoveContext = {\n stove,\n batchKg,\n share,\n startC,\n fuelEnergy: perKg === undefined || fuel.fuelEnergy === undefined ? undefined : { perKg: valueIn(perKg, \"kJ/kg\"), heating: fuel.fuelEnergy.heating },\n };\n\n const unitOf = new Map(catalog.resources.map((resource) => [resource.code, resource.unit]));\n const lines: CookLine[] = [];\n for (const [id, count] of Object.entries(units)) {\n if (!(count > 0)) continue;\n const product = catalog.products.find((item) => item.id === id);\n if (product === undefined) throw new RangeError(`The catalog has no product \"${id}\".`);\n if (product.kind !== \"food\") continue;\n const gifts = giftsOf(catalog, id, 1);\n const foodGifts = gifts.filter((gift) => isFood(catalog, gift.resource)).length;\n for (const gift of gifts) {\n if (!isDryFood(catalog, gift.resource)) continue;\n const perUnitKg = gift.read ? inUnit(gift.amount, gift.unit, \"kg\") : undefined;\n lines.push(cookLine(product, gift.resource, perUnitKg, foodGifts, context));\n }\n }\n\n const prefix = input.prefix ?? \"cook\";\n const converters: FragmentConverter[] = [];\n const noReads: CookNoRead[] = [];\n for (const resource of [...new Set(lines.map((line) => line.resource))]) {\n const own = lines.filter((line) => line.resource === resource);\n const why = own.flatMap((line) => [line.energy, line.water, line.fuel].flatMap((value) => (value.read ? [] : [`${line.product}: ${value.why}`])));\n if (why.length > 0) {\n noReads.push({ resource, why: [...new Set(why)].join(\" \") });\n continue;\n }\n const most = (pick: (line: CookLine) => CookRead): number => Math.max(...own.map((line) => valueOf(pick(line))));\n const least = (pick: (line: CookLine) => CookRead): number => Math.min(...own.map((line) => valueOf(pick(line))));\n const dryPerKg = inUnit(1, \"kg\", unitOf.get(resource) ?? \"\") ?? 1;\n const waterPerL = inUnit(1, \"L\", unitOf.get(STORED_WATER) ?? \"\");\n if (waterPerL === undefined) throw new RangeError(`The catalog has no resource \"${STORED_WATER}\" in a unit of volume for the cook water.`);\n converters.push({\n id: `${prefix}:${resource}`,\n ...(input.device === undefined ? {} : { device: input.device }),\n takes: [\n { resource, amount: batchKg * dryPerKg },\n { resource: STORED_WATER, amount: most((line) => line.water) * batchKg * waterPerL },\n { resource: stove.fuel, amount: most((line) => line.fuel) * fuelUnitPerKg },\n ],\n gives: { need: FOOD_NEED, amount: least((line) => line.energy) * batchKg },\n });\n }\n\n const codes = [...new Set(converters.flatMap((converter) => converter.takes.map((take) => take.resource)))];\n return {\n layer: {\n schema: \"endurance/1\",\n levels: [],\n resources: codes.map((code) => ({ code, unit: unitOf.get(code) ?? \"\" })),\n stores: [],\n draws: [],\n converters,\n },\n lines,\n noReads,\n read: noReads.length === 0,\n };\n}\n\n/** This function gives the value of a read. The caller tests the read first. */\nfunction valueOf(value: CookRead): number {\n return value.read ? value.value : Number.NaN;\n}\n","import { checkSources, type Finding, type FindingCode, type GateOptions, type Source } from \"@mark1russell7/guidebook\";\nimport { valueIn, type Quantity } from \"@mark1russell7/quantity\";\n\n// The daily needs of the kit: light, the watch of an alert receiver and warmth.\n// Each need has a cited daily rate, or a no read with its reason. A no read is not 0, and the list keeps it.\n// The rate of a device, for example the watts of a radio in standby, is a fact of the device and not of the need.\n\n/** The code of the need of light to see in the dark in a home, in hours. */\nexport const LIGHT_NEED = \"light.see\";\n/** The code of the need of an alert receiver that is on, in hours. */\nexport const ALERT_WATCH_NEED = \"alert.watch\";\n/** The code of the need of the space heat of a home, in `kWh`. The blankets and the sleeping bags of each person are gear, not this need. */\nexport const WARMTH_NEED = \"warmth.shelter\";\n\n/** The users of a daily rate: each person, or each household. */\nexport type DailyNeedUsers = \"person\" | \"household\";\n\n/** A daily rate with a read: an amount for each day, its sources and what the sources tell. */\nexport interface DailyRateRead {\n readonly read: true;\n /** The amount for each user each day, in the unit of the need for each day, for example `h/d`. */\n readonly perDay: Quantity;\n readonly sources: readonly Source[];\n /** This text tells how the sources give the amount. */\n readonly note: string;\n}\n\n/** A daily rate with no read, and the reason. A no read is not 0. */\nexport interface DailyRateNoRead {\n readonly read: false;\n readonly why: string;\n}\n\n/** A need of the kit, its unit, its users and its daily rate. */\nexport interface DailyNeed {\n /** The code of the need, in the form `<area>.<what>`. */\n readonly code: string;\n /** The unit of the need, in the grammar of `@mark1russell7/quantity`. */\n readonly unit: string;\n readonly users: DailyNeedUsers;\n readonly rate: DailyRateRead | DailyRateNoRead;\n}\n\n/** The page of the National Weather Service on the receivers of NOAA Weather Radio. It is a work of the United States federal government. */\nexport const NWS_RECEIVERS_SOURCE: Source = {\n id: \"nws-nwr-receivers\",\n title: \"NOAA Weather Radio All Hazards: Receiver Information\",\n url: \"https://www.weather.gov/nwr/nwr_receivers\",\n license: \"us-public-domain\",\n checked: \"2026-11-24\",\n by: \"National Weather Service\",\n terms: \"https://www.weather.gov/disclaimer\",\n};\n\n/** The page of the National Weather Service on the alarms of NOAA Weather Radio. It is a work of the United States federal government. */\nexport const NWS_ALARMS_SOURCE: Source = {\n id: \"nws-nwr-alarms\",\n title: \"NOAA Weather Radio All Hazards: NWR Alarms\",\n url: \"https://www.weather.gov/nwr/nwr_warning\",\n license: \"us-public-domain\",\n checked: \"2026-11-24\",\n by: \"National Weather Service\",\n terms: \"https://www.weather.gov/disclaimer\",\n};\n\n/**\n * The daily needs of the kit, with a cited rate or a no read.\n *\n * - `alert.watch`: 24 hours each day for each household. The sources give a standby mode that turns on at an alert, and warnings at night.\n * Thus a receiver stays on at all hours to get a warning. One receiver for each home is a choice of this model.\n * - `light.see`: no read, for each household. The kit lists of official sources give a flashlight and extra batteries, but no hours of use.\n * The count of lights of each person is a fact of the plan or the device.\n * - `warmth.shelter`: no read. The heat of a home changes with the weather, the building and the persons. It is space heat only.\n */\nexport const DAILY_NEEDS: readonly DailyNeed[] = [\n {\n code: ALERT_WATCH_NEED,\n unit: \"h\",\n users: \"household\",\n rate: {\n read: true,\n perDay: { value: 24, unit: \"h/d\" },\n sources: [NWS_RECEIVERS_SOURCE, NWS_ALARMS_SOURCE],\n note:\n \"The alarms page tells that many receivers can stay in a muted standby mode and turn on when a warning comes. \" +\n \"The receivers page tells that the tone alarm is useful for warnings during the night. \" +\n \"Thus a receiver stays on and listens at all hours to get a warning, so 24 hours each day. \" +\n \"One receiver for each home is a choice of this model, not of the sources.\",\n },\n },\n {\n code: LIGHT_NEED,\n unit: \"h\",\n users: \"household\",\n rate: {\n read: false,\n why:\n \"The kit lists of Ready.gov give a flashlight and extra batteries, but no hours of use each day. \" +\n \"No official source that we found gives a daily amount. A user gives the hours as input data.\",\n },\n },\n {\n code: WARMTH_NEED,\n unit: \"kWh\",\n users: \"household\",\n rate: {\n read: false,\n why:\n \"The heat that a home needs changes with the weather, the building and the persons. \" +\n \"This need is space heat only. The blankets and the sleeping bags of each person are gear, not this need. \" +\n \"No official source that we found gives a daily amount. A user gives the heat as input data.\",\n },\n },\n];\n\n/**\n * These are the codes of the gate of the daily needs. Each code is an error. The gate of the sources of `@mark1russell7/guidebook` gives its own codes.\n *\n * - `daily-need-id`: a need has an empty code, or a different need has its code.\n * - `daily-need-unit`: the unit of a need is not a unit of `@mark1russell7/quantity`.\n * - `daily-need-rate`: a read has no source. Or its amount is not a finite number of 0 or more in the unit of the need for each day.\n * Or a no read has no reason.\n */\nexport const DAILY_NEED_CODES: readonly [\"daily-need-id\", \"daily-need-unit\", \"daily-need-rate\"] = [\"daily-need-id\", \"daily-need-unit\", \"daily-need-rate\"];\n\n/** A code of the gate of the daily needs. */\nexport type DailyNeedCode = (typeof DAILY_NEED_CODES)[number];\n\n/** A finding of the gate of the daily needs: a finding of the gate of the sources, or a finding of a need. */\nexport type DailyNeedFinding = Finding<DailyNeedCode | FindingCode, \"source\" | \"unit\" | \"need\">;\n\n/** This function tells if a text is a unit that `@mark1russell7/quantity` reads. */\nfunction isUnit(unit: string): boolean {\n try {\n return Number.isFinite(valueIn({ value: 0, unit }, unit));\n } catch {\n return false;\n }\n}\n\n/** This function gives the amount of a rate in the unit of its need for each day, or `undefined` when the units do not convert. */\nfunction amountOf(perDay: Quantity, unit: string): number | undefined {\n try {\n return valueIn(perDay, `${unit}/d`);\n } catch {\n return undefined;\n }\n}\n\n/**\n * This function gives each finding of a list of daily needs. `resultOf` of `@mark1russell7/guidebook` tells if the gate passes.\n *\n * Each source must have a publisher (`by`) and a page of its terms, with HTTPS addresses. The findings are in the order of the list. The function is pure.\n *\n * @param needs - The daily needs, for example `DAILY_NEEDS`\n * @param options - The options of the gate of the sources, for example the date of the gate\n */\nexport function checkDailyNeeds(needs: readonly DailyNeed[], options?: GateOptions): DailyNeedFinding[] {\n const sources = new Map<string, Source>();\n for (const need of needs) if (need.rate.read) for (const source of need.rate.sources) sources.set(source.id, source);\n const fields = [...new Set([...(options?.require ?? []), \"by\" as const, \"terms\" as const])];\n const findings: DailyNeedFinding[] = [...checkSources([...sources.values()], { ...options, require: fields, https: true })];\n const add = (code: DailyNeedCode, id: string, message: string): void => {\n findings.push({ level: \"error\", code, record: \"need\", id, message });\n };\n\n const seen = new Set<string>();\n needs.forEach((need, index) => {\n const id = need.code.trim() === \"\" ? `needs[${String(index)}]` : need.code;\n if (need.code.trim() === \"\") add(\"daily-need-id\", id, `The need \"${id}\" has no code.`);\n else if (seen.has(need.code)) add(\"daily-need-id\", id, `Two needs have the code \"${id}\".`);\n seen.add(need.code);\n if (!isUnit(need.unit)) add(\"daily-need-unit\", id, `The unit \"${need.unit}\" of the need \"${id}\" is not a unit of quantity.`);\n if (need.rate.read) {\n const amount = amountOf(need.rate.perDay, need.unit);\n if (amount === undefined || !Number.isFinite(amount) || amount < 0) add(\"daily-need-rate\", id, `The rate of the need \"${id}\" is not a finite number of 0 or more in ${need.unit}/d.`);\n if (need.rate.sources.length === 0) add(\"daily-need-rate\", id, `The rate of the need \"${id}\" has no source.`);\n } else if (need.rate.why.trim() === \"\") add(\"daily-need-rate\", id, `The no read of the need \"${id}\" has no reason.`);\n });\n return findings;\n}\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,a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,QAAQ;GAAQ;GAAI;EAAQ,CAAC;CACrE;CAEA,MAAM,uBAAO,IAAI,IAAY;CAC7B,MAAM,SAAS,MAAM,UAAU;EAC7B,MAAM,KAAK,KAAK,KAAK,KAAK,MAAM,KAAK,SAAS,OAAO,KAAK,EAAE,KAAK,KAAK;EACtE,IAAI,KAAK,KAAK,KAAK,MAAM,IAAI,IAAI,iBAAiB,IAAI,aAAa,GAAG,eAAe;OAChF,IAAI,KAAK,IAAI,KAAK,IAAI,GAAG,IAAI,iBAAiB,IAAI,4BAA4B,GAAG,GAAG;EACzF,KAAK,IAAI,KAAK,IAAI;EAClB,IAAI,CAAC,OAAO,KAAK,IAAI,GAAG,IAAI,mBAAmB,IAAI,aAAa,KAAK,KAAK,iBAAiB,GAAG,6BAA6B;EAC3H,IAAI,KAAK,KAAK,MAAM;GAClB,MAAM,SAAS,SAAS,KAAK,KAAK,QAAQ,KAAK,IAAI;GACnD,IAAI,WAAW,KAAA,KAAa,CAAC,OAAO,SAAS,MAAM,KAAK,SAAS,GAAG,IAAI,mBAAmB,IAAI,yBAAyB,GAAG,2CAA2C,KAAK,KAAK,IAAI;GACpL,IAAI,KAAK,KAAK,QAAQ,WAAW,GAAG,IAAI,mBAAmB,IAAI,yBAAyB,GAAG,iBAAiB;EAC9G,OAAO,IAAI,KAAK,KAAK,IAAI,KAAK,MAAM,IAAI,IAAI,mBAAmB,IAAI,4BAA4B,GAAG,iBAAiB;CACrH,CAAC;CACD,OAAO;AACT"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/calorie.ts","../src/data.ts","../src/check.ts","../src/uses.ts","../src/household.ts","../src/cook.ts","../src/daily.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`: the milk of a person of the household. Below 6 months, the infant has only milk. From 6 months, the infant also has food.\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 feeds of formula: the PDF of the infant guide of the WIC program. It is a work of the United States federal government. */\nexport const WIC_INFANT_SOURCE: Source = {\n id: \"wic-infant-guide-2019\",\n title: \"Infant Nutrition and Feeding: A Guide for Use in the WIC and CSF Programs\",\n url: \"https://wicworks.fna.usda.gov/sites/default/files/media/document/infant-feeding-guide.pdf\",\n license: \"us-public-domain\",\n checked: \"2026-11-24\",\n by: \"USDA Food and Nutrition Service\",\n terms: \"https://wicworks.fna.usda.gov/resources/infant-nutrition-and-feeding-guide\",\n sha256: \"d0c043cc70dedf16920673f57cc4771692974db30761df351faec4e56db45b1d\",\n};\n\n/** A count of feeds in one day, with its source and its place in the source. */\nexport interface CitedFeeds {\n readonly perDay: number;\n readonly source: Source;\n readonly locator: string;\n}\n\n/**\n * The most feeds of formula in one day below 6 months: 8. Table 5.2 of the WIC guide gives 2 to 3 ounces every 3 to 4 hours.\n * 24 hours divided by 3 hours is 8. More feeds give smaller feeds and thus more waste, so this value is the most feeds.\n */\nexport const FORMULA_FEEDS: CitedFeeds = { perDay: 8, source: WIC_INFANT_SOURCE, locator: \"Table 5.2, Guidelines for Feeding Healthy Infants, Birth to 12 Months Old, page 137\" };\n\n/** The source of the energy of one fluid ounce of ready-to-feed formula: the SR Legacy file of FoodData Central. */\nexport const FDC_SR_LEGACY_SOURCE: Source = {\n id: \"fdc-sr-legacy-2018-04\",\n title: \"FoodData Central, SR Legacy (April 2018)\",\n url: \"https://fdc.nal.usda.gov/fdc-datasets/FoodData_Central_sr_legacy_food_csv_2018-04.zip\",\n license: \"cc0\",\n checked: \"2026-11-24\",\n by: \"USDA Agricultural Research Service\",\n terms: \"https://fdc.nal.usda.gov/download-datasets\",\n sha256: \"b80817294b8850530aaedf2e515c02593b1824f763a0ff356e5c2081643e6fd0\",\n};\n\n/** The energy of the least formula of one infant for one day, from a cited volume and a cited energy of one fluid ounce. */\nexport interface CitedFormulaLeast {\n /** The energy, in `kcal`: `ounces` times `kcalPerOunce`. */\n readonly perDay: number;\n readonly ounces: number;\n readonly ouncesSource: Source;\n readonly ouncesLocator: string;\n readonly kcalPerOunce: number;\n readonly kcalSource: Source;\n readonly kcalLocator: string;\n}\n\n/**\n * The least formula of one infant from 6 months: 24 fl oz a day. Table 5.2 of the WIC guide gives 24 to 32 ounces at 6 to 8 months,\n * and 24 ounces at 8 to 12 months. The FDC item 172319 gives 63 kcal in 100 g and 30.4 g in 1 fl oz, thus 19.152 kcal in 1 fl oz.\n */\nexport const FORMULA_LATER_LEAST: CitedFormulaLeast = {\n perDay: 24 * 19.152,\n ounces: 24,\n ouncesSource: WIC_INFANT_SOURCE,\n ouncesLocator: \"Table 5.2, Guidelines for Feeding Healthy Infants, Birth to 12 Months Old, page 137\",\n kcalPerOunce: 19.152,\n kcalSource: FDC_SR_LEGACY_SOURCE,\n kcalLocator: \"FDC ID 172319: 63 kcal in 100 g (food_nutrient.csv), and 30.4 g in 1 fl oz (food_portion.csv)\",\n};\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/** The energy of the breast milk of one infant for one day, with its source and its place in the source. */\nexport interface CitedMilk {\n readonly perDay: number;\n readonly source: Source;\n readonly locator: string;\n}\n\n/**\n * The energy of the breast milk of one infant from 6 months: 381 kcal/d. Table 5-14 of the NASEM report gives 568 g/d of milk\n * at 7 to 12 months for women that partly breastfeed, at 0.67 kcal/g. Its value at 6 months, 599 kcal/d, is for women that\n * only breastfeed. An infant from 6 months also has food, so the lower value gives the larger draw, the worst case.\n */\nexport const MILK_LATER: CitedMilk = { perDay: 381, source: NASEM_ENERGY_SOURCE, locator: \"Table 5-14, Energy Cost of Milk Production in Breastfeeding Women During the First Year Postpartum, page 97\" };\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 { canonicalUnit, quantity, valueIn } from \"@mark1russell7/quantity\";\nimport { calorieChange, calorieNeed, INFANT_FEEDINGS, type ActivityLevel, type CalorieNeedTotal, type CalorieTable, type CalorieTables, type Person } from \"./calorie.ts\";\nimport { CALORIE_CHAIN, FORMULA_FEEDS, FORMULA_LATER_LEAST, MILK_LATER } 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. `cookFragment` gives the converters of the dry food, with the water and the fuel of each pot.\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 the food draw holds a part of the need of an infant on breast milk: 6.\n * Below this age, the infant has milk only, and the stage of lactation of the mother holds that energy.\n * From this age, the food draw holds the need of the row minus the milk energy `MILK_LATER`.\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 * True when the household has cold storage for an opened container. The default is false: the worst case of no power.\n * Then an opened container of formula serves one feed, and the rest is waste.\n */\n readonly cold?: boolean | undefined;\n /**\n * The rule for an infant on formula from `FORMULA_DRAW_MONTHS`. Without it, the infant is a person with no row.\n * With `whole`, the formula draw holds the whole need of the row: the upper limit of formula. The food draw holds none of it.\n * With `least`, the formula draw holds `FORMULA_LATER_LEAST`, or the need of the row when it is less. The food draw holds the rest.\n */\n readonly formulaLater?: \"whole\" | \"least\" | undefined;\n}\n\n/** The waste of the opened containers of one product of the buy list with no cold storage. */\nexport interface OpenedWaste {\n readonly product: string;\n readonly resource: string;\n /** The count of containers in the buy list. */\n readonly containers: number;\n /** The energy of one container, in `kcal`. */\n readonly container: number;\n /** The energy of the smallest feed of the formula draw, in `kcal`. */\n readonly feed: number;\n /** The energy that the infants use from the containers, in `kcal`. It is the amount of the store. */\n readonly used: number;\n /** The energy of the containers that is waste, in `kcal`. */\n readonly waste: number;\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. Each infant below `BREAST_MILK_MONTHS` 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. From that age, the draw holds the row minus `MILK_LATER`.\n */\n readonly breastMilk: readonly Person[];\n /** The waste of each product with opened containers, with no cold storage. With `cold: true`, the list is empty. */\n readonly waste: readonly OpenedWaste[];\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. */\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 applies the rule of an opened container with no cold storage to the stores of the buy list.\n * An opened container serves one feed. A feed that is more than a container takes more containers, and the rest of the last is waste.\n * Thus each container gives `feed / ceil(feed / container)` kcal. The feed is the smallest feed of the formula draw, the worst case.\n * A product with a container of no read gives no store, and a gift with no read.\n *\n * @throws RangeError when a product with opened containers gives a resource that feeds no formula draw\n */\nfunction openedStores(\n input: HouseholdFragmentInput,\n stores: readonly FragmentStore[],\n noReads: readonly GiftNoRead[],\n feed: number | undefined,\n): { stores: FragmentStore[]; noReads: GiftNoRead[]; waste: OpenedWaste[] } {\n const out = { stores: [...stores], noReads: [...noReads], waste: [] as OpenedWaste[] };\n if (input.cold === true) return out;\n const prefix = input.prefix ?? \"buy\";\n const formulaResources = new Set((input.uses ?? DIRECT_USES).filter((use) => use.need === FORMULA_NEED).map((use) => use.resource));\n for (const [id, count] of Object.entries(input.units)) {\n const product = input.catalog.products.find((each) => each.id === id);\n const opened = product?.opened;\n if (product === undefined || opened === undefined || !(count > 0)) continue;\n for (const store of stores.filter((each) => each.id.startsWith(`${prefix}:${id}:`))) {\n if (!formulaResources.has(store.resource)) {\n throw new RangeError(`The product ${id} spoils after its container is opened, and its resource ${store.resource} feeds no formula draw. Only the formula draw has a cited size of one feed.`);\n }\n if (feed === undefined) continue;\n const { container } = opened;\n const size = product.size;\n out.stores = out.stores.filter((each) => each.id !== store.id);\n if (!container.read || size === undefined || !size.read) {\n const why = container.read ? \"The size of the product is no read.\" : `The size of a container is no read: ${container.why}`;\n out.noReads.push({ product: id, resource: store.resource, why: `With no cold storage, an opened container serves one feed (fact ${opened.noCold}). ${why}` });\n continue;\n }\n const unit = canonicalUnit(container.unit);\n const perUnit = Math.round(valueIn(quantity(size.amount, canonicalUnit(size.unit)), unit) / valueIn(quantity(container.amount, unit), unit));\n const containers = count * perUnit;\n const each = store.amount / containers;\n // A small margin keeps a feed of exactly k containers at k containers.\n const used = containers * (feed / Math.ceil(feed / each - 1e-9));\n out.stores.push({ ...store, amount: used });\n out.waste.push({ product: id, resource: store.resource, containers, container: each, feed, used, waste: store.amount - used });\n }\n }\n return out;\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 * With `formulaLater: \"whole\"`, it also has the older infants on formula, with the whole need of their rows.\n * With `formulaLater: \"least\"`, it has `FORMULA_LATER_LEAST` of each older infant, and the food draw has the rest.\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. `cookFragment` gives the converters for the dry food, with the water and the fuel of each pot.\n * - With no cold storage (the default), an opened container of formula serves one feed. The store has only the energy of the feeds,\n * and `waste` gives the rest. The smallest feed is the smallest need of an infant of the draw, divided by `FORMULA_FEEDS`.\n * A container of no read gives no store and a gift with no read, so the stores are a lower limit.\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`: below `BREAST_MILK_MONTHS`, the infant has a line, and no part of the draw. From that age, the food draw\n * holds the need of the row minus the milk energy `MILK_LATER`. The feeding is only for an infant below `INFANT_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 option `formulaLater: \"whole\"` puts the whole need in the formula draw: the upper limit.\n * The option `formulaLater: \"least\"` puts the lower limit in the formula draw, and the rest of the need in the food draw. 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 product with opened containers gives a resource that feeds no formula draw, with no cold storage\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` and `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 smallest daily need of one infant of the formula draw, for the smallest feed.\n let formulaLeast = Number.POSITIVE_INFINITY;\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 if (person.ageMonths >= BREAST_MILK_MONTHS) {\n // The infant also has food. The food draw holds the need of the row minus the milk energy.\n if (!line.read) noRow.push(person);\n else {\n users += person.count;\n perDay += Math.max(0, line.need.value - MILK_LATER.perDay * person.count);\n }\n }\n } else if (person.feeding === \"formula\") {\n formula.push(person);\n if (line.read && (person.ageMonths < FORMULA_DRAW_MONTHS || input.formulaLater === \"whole\")) {\n formulaUsers += person.count;\n formulaPerDay += line.need.value;\n formulaLeast = Math.min(formulaLeast, line.need.value / person.count);\n } else if (line.read && input.formulaLater === \"least\") {\n // The formula draw holds the least formula of each infant. The food draw holds the rest of the need of the row.\n const each = Math.min(FORMULA_LATER_LEAST.perDay, line.need.value / person.count);\n formulaUsers += person.count;\n formulaPerDay += each * person.count;\n formulaLeast = Math.min(formulaLeast, each);\n const rest = line.need.value - each * person.count;\n if (rest > 0) {\n users += person.count;\n perDay += rest;\n }\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 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 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 const feed = formulaUsers > 0 && formulaPerDay > 0 ? formulaLeast / FORMULA_FEEDS.perDay : undefined;\n const opened = openedStores(input, stores, parts.noReads, feed);\n return {\n ...parts,\n noReads: opened.noReads,\n storesRead: opened.noReads.length === 0,\n layer: {\n schema: \"endurance/1\",\n levels: [...(input.levels ?? [])],\n resources: layerResources(input.catalog, opened.stores, uses),\n stores: opened.stores,\n draws,\n direct: uses.map((use) => ({ ...use })),\n },\n need,\n needRead: true,\n leftOut: [...noRow, ...formulaLater],\n formula,\n breastMilk,\n waste: opened.waste,\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 !== \"food\" && !(person.ageMonths < INFANT_MONTHS)) {\n throw new RangeError(`The persons ${nameOf(person)} have feeding: ${feeding}, 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","import type { Source } from \"@mark1russell7/guidebook\";\nimport { fuelEnergyPerMass, giftsOf, cookWater, type CitedRate, type HeatingValue, type StoveFacts, type SupplyCatalog, type SupplyProduct } from \"@mark1russell7/market/supplies\";\nimport { valueIn, type Quantity } from \"@mark1russell7/quantity\";\nimport { FOOD_NEED, STORED_WATER } from \"./uses.ts\";\n\n// The water and the fuel to cook the dry food of a buy list, as converters of an endurance layer.\n// One run of a converter is one pot: the dry food, the cook water and the fuel of the pot give the food energy of the pot.\n// Thus a dry food with no fuel or no water gives no meal. The records have the form of `Converter` of stack-endurance.\n// Each value comes from a cited fact of the catalog, a cited input or a cited constant. A missing fact gives a no read.\n\n/** The source of the specific heat of water: the NIST Guide to the SI (Special Publication 811). It is a work of the United States federal government. */\nexport const NIST_SI_GUIDE_SOURCE: Source = {\n id: \"nist-sp-811\",\n title: \"NIST Guide to the SI (Special Publication 811), Appendix B.8 and footnotes\",\n url: \"https://www.nist.gov/pml/special-publication-811/nist-guide-si-appendix-b-conversion-factors/nist-guide-si-appendix-b8\",\n license: \"us-public-domain\",\n checked: \"2026-11-24\",\n by: \"National Institute of Standards and Technology\",\n terms: \"https://www.nist.gov/oism/copyrights\",\n note: \"The footnotes are at https://www.nist.gov/pml/special-publication-811/nist-guide-si-footnotes.\",\n};\n\n/** The source of the density of water: the page Water Density of the USGS Water Science School. It is a work of the United States federal government. */\nexport const USGS_WATER_DENSITY_SOURCE: Source = {\n id: \"usgs-water-density\",\n title: \"Water Density, USGS Water Science School\",\n url: \"https://www.usgs.gov/special-topics/water-science-school/science/water-density\",\n license: \"us-public-domain\",\n checked: \"2026-11-24\",\n by: \"U.S. Geological Survey\",\n terms: \"https://www.usgs.gov/information-policies-and-instructions/copyrights-and-credits\",\n};\n\n/** A physical constant of the cook model, with its source and the place of the value in the source. */\nexport interface CookConstant {\n readonly value: number;\n readonly unit: string;\n readonly source: Source;\n readonly locator: string;\n /** How the value comes from the source. */\n readonly note: string;\n}\n\n/**\n * The mean specific heat of liquid water from 0 °C to 100 °C: 4.19002 kJ/(kg.K).\n * The NIST Guide to the SI gives 4.190 02 J for the calorie (mean). The common definition of that calorie is the mean over this range.\n * SP 811 does not state the range. Its footnote 10 tells that the calorie is the energy to raise 1 g of water\n * by 1 kelvin. For the default start (0 °C), the value is the mean of the rise. For a warmer start, the mean of the\n * rise can be a little higher. The model also heats the dry food with this value, above the specific heat of a dry food.\n * That term holds the heat of the pot above the true value.\n */\nexport const WATER_SPECIFIC_HEAT: CookConstant = {\n value: 4.19002,\n unit: \"kJ/(kg.K)\",\n source: NIST_SI_GUIDE_SOURCE,\n locator: \"Appendix B.8, row calorie (mean): 4.190 02 E+00 J. Footnotes, footnote 10: the energy to raise 1 gram of water by 1 °C.\",\n note: \"The calorie (mean) in joules, for 1 g of water and 1 K. By its common definition, the mean is over the range from 0 °C to 100 °C. SP 811 does not state the range.\",\n};\n\n/**\n * The largest density of liquid water: 1 kg/L. The USGS table gives 1.00000 g/cm3 at 4.0 °C, its largest value.\n * Thus 1 L of cook water is 1 kg or less.\n */\nexport const WATER_DENSITY_MAX: CookConstant = {\n value: 1,\n unit: \"kg/L\",\n source: USGS_WATER_DENSITY_SOURCE,\n locator: \"Table of the density and the weight of water by temperature, row 39.2 °F/4.0 °C: 1.00000 g/cm3\",\n note: \"The largest density of the table, from 0 °C to 100 °C. Each other row is less.\",\n};\n\n/**\n * The temperature at the end of the heat to boil, in °C.\n * Water boils at a lower temperature at a high place. Then the heat is less.\n * But the cook time is longer there, and the model does not give that time. Thus at a high place the fuel is not an upper limit.\n */\nexport const BOIL_CELSIUS = 100;\n\n/**\n * The default start temperature of the cook water, in °C: 0, the freezing point. Liquid water at the pressure of the sea is\n * not colder. Thus the default gives the most heat. A caller gives a warmer start with its citation.\n */\nexport const COLD_START_CELSIUS = 0;\n\n/** The start temperature of the cook water, with the citation of the caller, for example a read of the stored water. */\nexport interface CookStart {\n /** The temperature in °C, from 0 up to less than `BOIL_CELSIUS`. */\n readonly celsius: number;\n /** The citation of the value: the `id` of a fact or a source of the caller. */\n readonly cite: string;\n}\n\n/**\n * The stove share is the part of the heat of the fuel that goes into the water and the food of the pot.\n * Its value is from more than 0 to 1, with its citation. The heat of the pot itself is in the losses. `heating` tells the heating value of the fuel energy that the share applies to.\n */\nexport interface StoveShare {\n readonly value: number;\n readonly heating: HeatingValue;\n /** The citation of the value: the `id` of a fact or a source of the caller. */\n readonly cite: string;\n}\n\n/** The inputs of the cook fragment. */\nexport interface CookFragmentInput {\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 stove: the `id` of a product of the catalog with stove facts, or the cited stove facts of the caller. */\n readonly stove: string | StoveFacts;\n /**\n * The dry mass of the food of one pot, for example `{ \"value\": 0.5, \"unit\": \"kg\" }`. It is a plan of the caller. It has no default.\n * Give the smallest pot that the cook makes. A batch above the real pot gives too little fuel, because each pot takes its own cook time.\n */\n readonly batch: Quantity;\n /** The stove share. Without it, the fuel of the boil is a no read, so each fuel is a no read. It has no default. */\n readonly share?: StoveShare | undefined;\n /** The start temperature of the cook water. The default is `COLD_START_CELSIUS`. */\n readonly start?: CookStart | undefined;\n /** The `id` of the stove in the stack. The converters stop when the stove stops. */\n readonly device?: string | undefined;\n /** The start of the `id` of each converter. The default is `cook`. */\n readonly prefix?: string | undefined;\n}\n\n/** A value of the cook model with a read, in its unit, or no read with the reasons. A no read is not 0. */\nexport type CookRead = { readonly read: true; readonly value: number; readonly unit: string } | { readonly read: false; readonly why: string };\n\n/** The cook values of one dry food of the buy list, for one pot. */\nexport interface CookLine {\n readonly product: string;\n /** The dry resource of the product, for example `food.grain-dry`. */\n readonly resource: string;\n /** The food energy of the dry food, in `kcal/kg`. */\n readonly energy: CookRead;\n /** The cook water, in `L/kg` of dry food, from `cookWater` of market. */\n readonly water: CookRead;\n /** The heat to boil the cook water of one pot, in `kJ`. */\n readonly heat: CookRead;\n /** The time of the stove for one pot: the boil time and the high end of the cook time, in `min`. */\n readonly minutes: CookRead;\n /** The fuel of one pot, in `kg`. */\n readonly fuel: CookRead;\n}\n\n/** A converter of the cook fragment, with the form of `Converter` of `@mark1russell7/stack-endurance`. */\nexport interface FragmentConverter {\n readonly id: string;\n readonly device?: string | undefined;\n readonly takes: readonly { readonly resource: string; readonly amount: number }[];\n readonly gives: { readonly need: string; readonly amount: number };\n}\n\n/** The cook fragment of an endurance layer: the resources and one converter for each dry resource with a read. It has no store and no draw. */\nexport interface CookFragment {\n /** The format of an endurance layer, `endurance/1`. */\n readonly schema: \"endurance/1\";\n readonly levels: readonly string[];\n readonly resources: readonly { readonly code: string; readonly unit: string }[];\n readonly stores: readonly never[];\n readonly draws: readonly never[];\n readonly converters: readonly FragmentConverter[];\n}\n\n/** A dry resource of the buy list with no converter, and the reasons. */\nexport interface CookNoRead {\n readonly resource: string;\n readonly why: string;\n}\n\n/** The cook fragment, the line of each dry food and the dry resources with no converter. */\nexport interface CookFragmentResult {\n readonly layer: CookFragment;\n /** The line of each dry food of the buy list, in the order of the list. */\n readonly lines: readonly CookLine[];\n /** The dry resources with no converter. Their dry food gives no meal in the layer. */\n readonly noReads: readonly CookNoRead[];\n /** True when each dry resource of the buy list has a converter. When it is false, the cooked days are a lower limit. */\n readonly read: boolean;\n}\n\n/** This function gives the value of an amount in a unit, or `undefined` when the units do not convert. */\nfunction inUnit(value: number, from: string, to: string): number | undefined {\n try {\n const out = valueIn({ value, unit: from }, to);\n return Number.isFinite(out) ? out : undefined;\n } catch {\n return undefined;\n }\n}\n\n/** A fuel rate of a stove, in an energy or in a mass for each minute. */\ntype StoveRate = { readonly kind: \"energy\"; readonly perMin: number } | { readonly kind: \"mass\"; readonly perMin: number };\n\n/** This function gives the fuel rate of a stove in `kJ/min` or `kg/min`. It gives `undefined` for a rate that is not an energy or a mass in a time. */\nfunction stoveRate(rate: CitedRate): StoveRate | undefined {\n const minutes = inUnit(rate.per.amount, rate.per.unit, \"min\");\n if (minutes === undefined || !(minutes > 0)) return undefined;\n const energy = inUnit(rate.amount, rate.unit, \"kJ\");\n if (energy !== undefined) return { kind: \"energy\", perMin: energy / minutes };\n const mass = inUnit(rate.amount, rate.unit, \"kg\");\n if (mass !== undefined) return { kind: \"mass\", perMin: mass / minutes };\n return undefined;\n}\n\nconst read = (value: number, unit: string): CookRead => ({ read: true, value, unit });\nconst noRead = (why: string): CookRead => ({ read: false, why });\n\n/** The inputs of one line that do not change with the product. */\ninterface StoveContext {\n readonly stove: StoveFacts;\n readonly batchKg: number;\n readonly share: StoveShare | undefined;\n readonly startC: number;\n /** The energy of the fuel in `kJ/kg`, and its heating value, or `undefined` when the fuel has no cited energy. */\n readonly fuelEnergy: { readonly perKg: number; readonly heating: HeatingValue } | undefined;\n}\n\n/**\n * This function gives the cook line of one dry food. Each missing fact gives a no read with its reason.\n * The fuel is a safe upper limit: the stove burns at its full rate for the boil time and the cook time.\n * At a high place the cook time is longer. The model does not give that time, so there the fuel is not an upper limit.\n */\nfunction cookLine(product: SupplyProduct, resource: string, perUnitKg: number | undefined, foodGifts: number, context: StoveContext): CookLine {\n const { stove, batchKg, share, startC, fuelEnergy } = context;\n\n let energy: CookRead;\n if (foodGifts > 1) energy = noRead(`The product ${product.id} gives ${String(foodGifts)} foods. The catalog gives one energy for the whole product, not the energy of each food.`);\n else if (product.energy === undefined) energy = noRead(`The product ${product.id} has no food energy in the catalog.`);\n else if (!product.energy.read) energy = noRead(`The food energy of the product ${product.id} is a no read: ${product.energy.why}`);\n else {\n const kcal = inUnit(product.energy.amount, product.energy.unit, \"kcal\");\n if (kcal === undefined) energy = noRead(`The food energy of the product ${product.id} is in ${product.energy.unit}, which does not convert to kcal.`);\n else if (perUnitKg === undefined || !(perUnitKg > 0)) energy = noRead(`The gift of ${resource} of the product ${product.id} has no read in kg.`);\n else energy = read(kcal / perUnitKg, \"kcal/kg\");\n }\n\n const litres = cookWater(product);\n const water = litres === undefined ? noRead(`The catalog cites no cook water for the product ${product.id}, or no bulk mass for its water rate.`) : read(valueIn(litres, \"L/kg\"), \"L/kg\");\n\n // The heat to boil one pot: the mass of the water and the dry food times the specific heat of water times the rise to the boil.\n const heat = water.read ? read((water.value * WATER_DENSITY_MAX.value + 1) * batchKg * WATER_SPECIFIC_HEAT.value * (BOIL_CELSIUS - startC), \"kJ\") : noRead(`The heat to boil is a no read: ${water.why}`);\n\n const why: string[] = [];\n if (!heat.read) why.push(heat.why);\n const time = product.cook?.time;\n const cookMin = time === undefined ? undefined : inUnit(time.high, time.unit, \"min\");\n if (time === undefined) why.push(`The catalog cites no cook time for the product ${product.id}.`);\n else if (cookMin === undefined) why.push(`The cook time of the product ${product.id} is in ${time.unit}, which does not convert to min.`);\n\n const rate = stove.rate === undefined ? undefined : stoveRate(stove.rate);\n if (stove.rate === undefined) why.push(`The stove of ${stove.fuel} has no cited fuel rate.`);\n else if (rate === undefined) why.push(`The fuel rate of the stove is in ${stove.rate.unit} for each ${stove.rate.per.unit}, which is not an energy or a mass in a time.`);\n\n // The heat of the stove into the pot for each minute, in kJ/min. It needs a cited share with the same heating value as the energy rate.\n let potPerMin: number | undefined;\n if (share === undefined) why.push(\"No cited stove share gives the part of the stove heat that goes into the pot. Thus the fuel of the boil is a no read.\");\n else if (rate !== undefined) {\n if (rate.kind === \"energy\") {\n if (stove.heating !== share.heating) why.push(`The stove share is for the ${share.heating} heating value, and the stove rate is for the ${String(stove.heating ?? \"unknown\")} heating value.`);\n else potPerMin = rate.perMin * share.value;\n } else if (fuelEnergy === undefined) why.push(`The fuel ${stove.fuel} has no cited energy, so its mass rate gives no heat for the boil.`);\n else if (fuelEnergy.heating !== share.heating) why.push(`The stove share is for the ${share.heating} heating value, and the energy of the fuel ${stove.fuel} is the ${fuelEnergy.heating} value.`);\n else potPerMin = rate.perMin * fuelEnergy.perKg * share.value;\n }\n\n // The fuel mass for each minute at the full rate, in kg/min. An energy rate converts only through the cited fuel energy of the same heating value.\n let fuelPerMin: number | undefined;\n if (rate?.kind === \"mass\") fuelPerMin = rate.perMin;\n else if (rate?.kind === \"energy\") {\n if (fuelEnergy === undefined) why.push(`The fuel ${stove.fuel} has no cited energy, so the energy rate of the stove gives no fuel mass.`);\n else if (stove.heating === undefined) why.push(\"The energy rate of the stove has no heating value.\");\n else if (stove.heating !== fuelEnergy.heating) why.push(`The stove rate is for the ${stove.heating} heating value, and the energy of the fuel ${stove.fuel} is the ${fuelEnergy.heating} value.`);\n else fuelPerMin = rate.perMin / fuelEnergy.perKg;\n }\n\n if (why.length > 0 || !heat.read || cookMin === undefined || potPerMin === undefined || fuelPerMin === undefined || !(potPerMin > 0)) {\n const text = why.join(\" \");\n return { product: product.id, resource, energy, water, heat, minutes: noRead(text), fuel: noRead(text) };\n }\n const minutes = heat.value / potPerMin + cookMin;\n return { product: product.id, resource, energy, water, heat, minutes: read(minutes, \"min\"), fuel: read(minutes * fuelPerMin, \"kg\") };\n}\n\n/** This function gives the stove facts of the input: the facts of the caller, or the facts of a product of the catalog. */\nfunction stoveOf(catalog: SupplyCatalog, stove: string | StoveFacts): StoveFacts {\n if (typeof stove !== \"string\") return stove;\n const product = catalog.products.find((item) => item.id === stove);\n if (product === undefined) throw new RangeError(`The catalog has no product \"${stove}\".`);\n if (product.stove === undefined) throw new RangeError(`The product \"${stove}\" has no stove facts.`);\n return product.stove;\n}\n\n/** This function tells if a resource of the catalog is a food. */\nfunction isFood(catalog: SupplyCatalog, code: string): boolean {\n return catalog.resources.find((item) => item.code === code)?.kind === \"food\";\n}\n\n/** This function tells if a resource of the catalog is a dry food: a food resource in a unit of mass. */\nfunction isDryFood(catalog: SupplyCatalog, code: string): boolean {\n const resource = catalog.resources.find((item) => item.code === code);\n return resource !== undefined && resource.kind === \"food\" && inUnit(1, resource.unit, \"kg\") !== undefined;\n}\n\n/**\n * This function gives the converters that cook the dry food of a buy list, with the water and the fuel of each pot.\n *\n * - One run of a converter is one pot of `batch`. It takes the dry food, the cook water from `water.stored` and the fuel of the stove.\n * It gives the food energy of the pot to the need `food.energy`. Thus a dry food with no fuel or no water gives no meal.\n * - The cook water is `cookWater` of market times the dry mass. It is the resource of the drinking water.\n * - The heat to boil is the mass of the water and the dry food times `WATER_SPECIFIC_HEAT` times the rise from the start to `BOIL_CELSIUS`.\n * The water mass takes `WATER_DENSITY_MAX`. The dry food takes the specific heat of water, which is higher than its own.\n * - The boil time is the heat divided by the stove rate times the share. The time of the stove is the boil time plus the high end of the cook time.\n * - The fuel is a safe upper limit: the stove burns at its full rate for all of that time. At a high place the cook time is longer.\n * The model does not give that time, so there the fuel is not an upper limit.\n * - A rate in a mass gives the fuel directly. A rate in an energy gives a mass only through the cited energy of the fuel, with the same heating value.\n *\n * A dry food is a gift of a food resource in a unit of mass. Each missing fact gives a line with no read and its reasons, not a figure.\n * Two products of the list can give one dry resource, for example rice and oats. The converter then takes the worst case of their lines:\n * the most water, the most fuel and the least food energy. When a line of the resource has no read, the resource has no converter.\n * A store of the resource from a different fragment gets the converter of this list.\n *\n * The catalog of market gives no soak water. A food that needs a soak, for example dry beans, has a second water draw that this function does not give.\n * A product that gives more than one food has no energy for each food, so its energy is a no read.\n *\n * The cook water is `water.stored`, the store of the drinking water. A drinking draw at a higher level of the same store takes\n * its water first, by the take order of `enduranceOf`. The drinking draw keeps back its days times its demand, which is all of the store.\n * Thus, when a case cuts the water supply, the dry food adds 0 days at each amount of stored water.\n *\n * The function is pure.\n *\n * @param input - The catalog and the buy list, the stove, the dry mass of one pot, the share and the start temperature\n * @returns The fragment, the line of each dry food and the dry resources with no converter\n * @throws RangeError when the batch is not a mass above 0, or when the share is not above 0 and up to 1\n * @throws RangeError when the start is not from 0 up to less than 100 °C\n * @throws RangeError when the stove is a product with no stove facts\n * @throws RangeError when the catalog has no product of an `id` of the buy list\n * @throws RangeError when the catalog has no resource of the fuel in a unit of mass\n * @throws RangeError when a converter has a read and the catalog has no resource `water.stored` in a unit of volume\n * @throws RangeError for the errors of `giftsOf`\n */\nexport function cookFragment(input: CookFragmentInput): CookFragmentResult {\n const { catalog, units } = input;\n const batchKg = inUnit(input.batch.value, input.batch.unit, \"kg\");\n if (batchKg === undefined || !(batchKg > 0)) throw new RangeError(`The batch ${String(input.batch.value)} ${input.batch.unit} is not a mass above 0.`);\n const { share } = input;\n if (share !== undefined && !(share.value > 0 && share.value <= 1)) throw new RangeError(`The stove share is ${String(share.value)}. It must be above 0 and up to 1.`);\n const startC = input.start?.celsius ?? COLD_START_CELSIUS;\n if (!(startC >= 0 && startC < BOIL_CELSIUS)) throw new RangeError(`The start temperature is ${String(startC)} °C. It must be from 0 up to less than ${String(BOIL_CELSIUS)} °C.`);\n const stove = stoveOf(catalog, input.stove);\n const fuel = catalog.resources.find((resource) => resource.code === stove.fuel);\n const fuelUnitPerKg = fuel === undefined ? undefined : inUnit(1, \"kg\", fuel.unit);\n if (fuel === undefined || fuelUnitPerKg === undefined) throw new RangeError(`The catalog has no resource \"${stove.fuel}\" in a unit of mass for the fuel of the stove.`);\n const perKg = fuelEnergyPerMass(fuel);\n const context: StoveContext = {\n stove,\n batchKg,\n share,\n startC,\n fuelEnergy: perKg === undefined || fuel.fuelEnergy === undefined ? undefined : { perKg: valueIn(perKg, \"kJ/kg\"), heating: fuel.fuelEnergy.heating },\n };\n\n const unitOf = new Map(catalog.resources.map((resource) => [resource.code, resource.unit]));\n const lines: CookLine[] = [];\n for (const [id, count] of Object.entries(units)) {\n if (!(count > 0)) continue;\n const product = catalog.products.find((item) => item.id === id);\n if (product === undefined) throw new RangeError(`The catalog has no product \"${id}\".`);\n if (product.kind !== \"food\") continue;\n const gifts = giftsOf(catalog, id, 1);\n const foodGifts = gifts.filter((gift) => isFood(catalog, gift.resource)).length;\n for (const gift of gifts) {\n if (!isDryFood(catalog, gift.resource)) continue;\n const perUnitKg = gift.read ? inUnit(gift.amount, gift.unit, \"kg\") : undefined;\n lines.push(cookLine(product, gift.resource, perUnitKg, foodGifts, context));\n }\n }\n\n const prefix = input.prefix ?? \"cook\";\n const converters: FragmentConverter[] = [];\n const noReads: CookNoRead[] = [];\n for (const resource of [...new Set(lines.map((line) => line.resource))]) {\n const own = lines.filter((line) => line.resource === resource);\n const why = own.flatMap((line) => [line.energy, line.water, line.fuel].flatMap((value) => (value.read ? [] : [`${line.product}: ${value.why}`])));\n if (why.length > 0) {\n noReads.push({ resource, why: [...new Set(why)].join(\" \") });\n continue;\n }\n const most = (pick: (line: CookLine) => CookRead): number => Math.max(...own.map((line) => valueOf(pick(line))));\n const least = (pick: (line: CookLine) => CookRead): number => Math.min(...own.map((line) => valueOf(pick(line))));\n const dryPerKg = inUnit(1, \"kg\", unitOf.get(resource) ?? \"\") ?? 1;\n const waterPerL = inUnit(1, \"L\", unitOf.get(STORED_WATER) ?? \"\");\n if (waterPerL === undefined) throw new RangeError(`The catalog has no resource \"${STORED_WATER}\" in a unit of volume for the cook water.`);\n converters.push({\n id: `${prefix}:${resource}`,\n ...(input.device === undefined ? {} : { device: input.device }),\n takes: [\n { resource, amount: batchKg * dryPerKg },\n { resource: STORED_WATER, amount: most((line) => line.water) * batchKg * waterPerL },\n { resource: stove.fuel, amount: most((line) => line.fuel) * fuelUnitPerKg },\n ],\n gives: { need: FOOD_NEED, amount: least((line) => line.energy) * batchKg },\n });\n }\n\n const codes = [...new Set(converters.flatMap((converter) => converter.takes.map((take) => take.resource)))];\n return {\n layer: {\n schema: \"endurance/1\",\n levels: [],\n resources: codes.map((code) => ({ code, unit: unitOf.get(code) ?? \"\" })),\n stores: [],\n draws: [],\n converters,\n },\n lines,\n noReads,\n read: noReads.length === 0,\n };\n}\n\n/** This function gives the value of a read. The caller tests the read first. */\nfunction valueOf(value: CookRead): number {\n return value.read ? value.value : Number.NaN;\n}\n","import { checkSources, type Finding, type FindingCode, type GateOptions, type Source } from \"@mark1russell7/guidebook\";\nimport { valueIn, type Quantity } from \"@mark1russell7/quantity\";\n\n// The daily needs of the kit: light, the watch of an alert receiver and warmth.\n// Each need has a cited daily rate, or a no read with its reason. A no read is not 0, and the list keeps it.\n// The rate of a device, for example the watts of a radio in standby, is a fact of the device and not of the need.\n\n/** The code of the need of light to see in the dark in a home, in hours. */\nexport const LIGHT_NEED = \"light.see\";\n/** The code of the need of an alert receiver that is on, in hours. */\nexport const ALERT_WATCH_NEED = \"alert.watch\";\n/** The code of the need of the space heat of a home, in `kWh`. The blankets and the sleeping bags of each person are gear, not this need. */\nexport const WARMTH_NEED = \"warmth.shelter\";\n\n/** The users of a daily rate: each person, or each household. */\nexport type DailyNeedUsers = \"person\" | \"household\";\n\n/** A daily rate with a read: an amount for each day, its sources and what the sources tell. */\nexport interface DailyRateRead {\n readonly read: true;\n /** The amount for each user each day, in the unit of the need for each day, for example `h/d`. */\n readonly perDay: Quantity;\n readonly sources: readonly Source[];\n /** This text tells how the sources give the amount. */\n readonly note: string;\n}\n\n/** A daily rate with no read, and the reason. A no read is not 0. */\nexport interface DailyRateNoRead {\n readonly read: false;\n readonly why: string;\n}\n\n/** A need of the kit, its unit, its users and its daily rate. */\nexport interface DailyNeed {\n /** The code of the need, in the form `<area>.<what>`. */\n readonly code: string;\n /** The unit of the need, in the grammar of `@mark1russell7/quantity`. */\n readonly unit: string;\n readonly users: DailyNeedUsers;\n readonly rate: DailyRateRead | DailyRateNoRead;\n}\n\n/** The page of the National Weather Service on the receivers of NOAA Weather Radio. It is a work of the United States federal government. */\nexport const NWS_RECEIVERS_SOURCE: Source = {\n id: \"nws-nwr-receivers\",\n title: \"NOAA Weather Radio All Hazards: Receiver Information\",\n url: \"https://www.weather.gov/nwr/nwr_receivers\",\n license: \"us-public-domain\",\n checked: \"2026-11-24\",\n by: \"National Weather Service\",\n terms: \"https://www.weather.gov/disclaimer\",\n};\n\n/** The page of the National Weather Service on the alarms of NOAA Weather Radio. It is a work of the United States federal government. */\nexport const NWS_ALARMS_SOURCE: Source = {\n id: \"nws-nwr-alarms\",\n title: \"NOAA Weather Radio All Hazards: NWR Alarms\",\n url: \"https://www.weather.gov/nwr/nwr_warning\",\n license: \"us-public-domain\",\n checked: \"2026-11-24\",\n by: \"National Weather Service\",\n terms: \"https://www.weather.gov/disclaimer\",\n};\n\n/**\n * The daily needs of the kit, with a cited rate or a no read.\n *\n * - `alert.watch`: 24 hours each day for each household. The sources give a standby mode that turns on at an alert, and warnings at night.\n * Thus a receiver stays on at all hours to get a warning. One receiver for each home is a choice of this model.\n * - `light.see`: no read, for each household. The kit lists of official sources give a flashlight and extra batteries, but no hours of use.\n * The count of lights of each person is a fact of the plan or the device.\n * - `warmth.shelter`: no read. The heat of a home changes with the weather, the building and the persons. It is space heat only.\n */\nexport const DAILY_NEEDS: readonly DailyNeed[] = [\n {\n code: ALERT_WATCH_NEED,\n unit: \"h\",\n users: \"household\",\n rate: {\n read: true,\n perDay: { value: 24, unit: \"h/d\" },\n sources: [NWS_RECEIVERS_SOURCE, NWS_ALARMS_SOURCE],\n note:\n \"The alarms page tells that many receivers can stay in a muted standby mode and turn on when a warning comes. \" +\n \"The receivers page tells that the tone alarm is useful for warnings during the night. \" +\n \"Thus a receiver stays on and listens at all hours to get a warning, so 24 hours each day. \" +\n \"One receiver for each home is a choice of this model, not of the sources.\",\n },\n },\n {\n code: LIGHT_NEED,\n unit: \"h\",\n users: \"household\",\n rate: {\n read: false,\n why:\n \"The kit lists of Ready.gov give a flashlight and extra batteries, but no hours of use each day. \" +\n \"No official source that we found gives a daily amount. A user gives the hours as input data.\",\n },\n },\n {\n code: WARMTH_NEED,\n unit: \"kWh\",\n users: \"household\",\n rate: {\n read: false,\n why:\n \"The heat that a home needs changes with the weather, the building and the persons. \" +\n \"This need is space heat only. The blankets and the sleeping bags of each person are gear, not this need. \" +\n \"No official source that we found gives a daily amount. A user gives the heat as input data.\",\n },\n },\n];\n\n/**\n * These are the codes of the gate of the daily needs. Each code is an error. The gate of the sources of `@mark1russell7/guidebook` gives its own codes.\n *\n * - `daily-need-id`: a need has an empty code, or a different need has its code.\n * - `daily-need-unit`: the unit of a need is not a unit of `@mark1russell7/quantity`.\n * - `daily-need-rate`: a read has no source. Or its amount is not a finite number of 0 or more in the unit of the need for each day.\n * Or a no read has no reason.\n */\nexport const DAILY_NEED_CODES: readonly [\"daily-need-id\", \"daily-need-unit\", \"daily-need-rate\"] = [\"daily-need-id\", \"daily-need-unit\", \"daily-need-rate\"];\n\n/** A code of the gate of the daily needs. */\nexport type DailyNeedCode = (typeof DAILY_NEED_CODES)[number];\n\n/** A finding of the gate of the daily needs: a finding of the gate of the sources, or a finding of a need. */\nexport type DailyNeedFinding = Finding<DailyNeedCode | FindingCode, \"source\" | \"unit\" | \"need\">;\n\n/** This function tells if a text is a unit that `@mark1russell7/quantity` reads. */\nfunction isUnit(unit: string): boolean {\n try {\n return Number.isFinite(valueIn({ value: 0, unit }, unit));\n } catch {\n return false;\n }\n}\n\n/** This function gives the amount of a rate in the unit of its need for each day, or `undefined` when the units do not convert. */\nfunction amountOf(perDay: Quantity, unit: string): number | undefined {\n try {\n return valueIn(perDay, `${unit}/d`);\n } catch {\n return undefined;\n }\n}\n\n/**\n * This function gives each finding of a list of daily needs. `resultOf` of `@mark1russell7/guidebook` tells if the gate passes.\n *\n * Each source must have a publisher (`by`) and a page of its terms, with HTTPS addresses. The findings are in the order of the list. The function is pure.\n *\n * @param needs - The daily needs, for example `DAILY_NEEDS`\n * @param options - The options of the gate of the sources, for example the date of the gate\n */\nexport function checkDailyNeeds(needs: readonly DailyNeed[], options?: GateOptions): DailyNeedFinding[] {\n const sources = new Map<string, Source>();\n for (const need of needs) if (need.rate.read) for (const source of need.rate.sources) sources.set(source.id, source);\n const fields = [...new Set([...(options?.require ?? []), \"by\" as const, \"terms\" as const])];\n const findings: DailyNeedFinding[] = [...checkSources([...sources.values()], { ...options, require: fields, https: true })];\n const add = (code: DailyNeedCode, id: string, message: string): void => {\n findings.push({ level: \"error\", code, record: \"need\", id, message });\n };\n\n const seen = new Set<string>();\n needs.forEach((need, index) => {\n const id = need.code.trim() === \"\" ? `needs[${String(index)}]` : need.code;\n if (need.code.trim() === \"\") add(\"daily-need-id\", id, `The need \"${id}\" has no code.`);\n else if (seen.has(need.code)) add(\"daily-need-id\", id, `Two needs have the code \"${id}\".`);\n seen.add(need.code);\n if (!isUnit(need.unit)) add(\"daily-need-unit\", id, `The unit \"${need.unit}\" of the need \"${id}\" is not a unit of quantity.`);\n if (need.rate.read) {\n const amount = amountOf(need.rate.perDay, need.unit);\n if (amount === undefined || !Number.isFinite(amount) || amount < 0) add(\"daily-need-rate\", id, `The rate of the need \"${id}\" is not a finite number of 0 or more in ${need.unit}/d.`);\n if (need.rate.sources.length === 0) add(\"daily-need-rate\", id, `The rate of the need \"${id}\" has no source.`);\n } else if (need.rate.why.trim() === \"\") add(\"daily-need-rate\", id, `The no read of the need \"${id}\" has no reason.`);\n });\n return findings;\n}\n\n"],"mappings":";;;;;AAQA,MAAa,kB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,IAAI,4BAA4B,GAAG,GAAG;EACzF,KAAK,IAAI,KAAK,IAAI;EAClB,IAAI,CAAC,OAAO,KAAK,IAAI,GAAG,IAAI,mBAAmB,IAAI,aAAa,KAAK,KAAK,iBAAiB,GAAG,6BAA6B;EAC3H,IAAI,KAAK,KAAK,MAAM;GAClB,MAAM,SAAS,SAAS,KAAK,KAAK,QAAQ,KAAK,IAAI;GACnD,IAAI,WAAW,KAAA,KAAa,CAAC,OAAO,SAAS,MAAM,KAAK,SAAS,GAAG,IAAI,mBAAmB,IAAI,yBAAyB,GAAG,2CAA2C,KAAK,KAAK,IAAI;GACpL,IAAI,KAAK,KAAK,QAAQ,WAAW,GAAG,IAAI,mBAAmB,IAAI,yBAAyB,GAAG,iBAAiB;EAC9G,OAAO,IAAI,KAAK,KAAK,IAAI,KAAK,MAAM,IAAI,IAAI,mBAAmB,IAAI,4BAA4B,GAAG,iBAAiB;CACrH,CAAC;CACD,OAAO;AACT"}
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.9.2",
4
+ "version": "0.9.3",
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": {