@mark1russell7/market 0.1.8 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -1
- package/build/average-B29bynFb.js +106 -0
- package/build/average-B29bynFb.js.map +1 -0
- package/build/average-Bj0GkSLo.d.ts +40 -0
- package/build/average-Bj0GkSLo.d.ts.map +1 -0
- package/build/index.d.ts +2 -37
- package/build/index.d.ts.map +1 -1
- package/build/index.js +3 -76
- package/build/index.js.map +1 -1
- package/build/{offers-B_8DqLSA.js → offers-h_HvMkH_.js} +3 -186
- package/build/offers-h_HvMkH_.js.map +1 -0
- package/build/plan.js +2 -1
- package/build/plan.js.map +1 -1
- package/build/records-W6sPyhTQ.js +187 -0
- package/build/records-W6sPyhTQ.js.map +1 -0
- package/build/supplies-entry.d.ts +139 -5
- package/build/supplies-entry.d.ts.map +1 -1
- package/build/supplies-entry.js +410 -18
- package/build/supplies-entry.js.map +1 -1
- package/package.json +1 -1
- package/build/offers-B_8DqLSA.js.map +0 -1
package/build/supplies-entry.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as moneyOf, i as moneyAbove, o as monthSchema, r as latestAverages } from "./average-B29bynFb.js";
|
|
2
|
+
import { convertible, quantity, valueIn, whyNotConvertible } from "@mark1russell7/quantity";
|
|
2
3
|
import { checkSources, checkUnits } from "@mark1russell7/guidebook";
|
|
3
4
|
// src/supplies.ts
|
|
4
5
|
/** The format of a catalog of supplies. */
|
|
@@ -20,6 +21,7 @@ const SUPPLY_CODES = [
|
|
|
20
21
|
"supplies-kind",
|
|
21
22
|
"supplies-resource",
|
|
22
23
|
"supplies-fact",
|
|
24
|
+
"supplies-basis",
|
|
23
25
|
"supplies-amount",
|
|
24
26
|
"supplies-unit",
|
|
25
27
|
"supplies-shelf",
|
|
@@ -45,10 +47,13 @@ const SHELF_UNIT = "d";
|
|
|
45
47
|
* `@mark1russell7/guidebook`), and the findings of the products:
|
|
46
48
|
*
|
|
47
49
|
* - An error for a product or a resource two times, a kind that is not a supply kind, and a gift of an unknown resource.
|
|
48
|
-
* - An error for a
|
|
50
|
+
* - An error for a product that gives no resource and has no basis.
|
|
51
|
+
* - An error for a fact that is not a fact of the catalog, and for an amount that is not more than 0. The basis of a
|
|
52
|
+
* product is also a fact.
|
|
49
53
|
* - An error for an amount with no reason, with two reasons, or with a blank definition. A catalog from JSON can have them.
|
|
50
54
|
* - An error for a unit that is not a unit of `@mark1russell7/quantity`.
|
|
51
55
|
* - An error for a unit that does not convert to the unit of its resource.
|
|
56
|
+
* - The amount of the item of an average price has the same checks as each other amount.
|
|
52
57
|
* - A warning for each value with no read, and for a no read with a blank reason.
|
|
53
58
|
* - A warning for each fact and each source that no product uses.
|
|
54
59
|
*
|
|
@@ -119,7 +124,14 @@ function checkSupplies(catalog, options = {}) {
|
|
|
119
124
|
if (resource === void 0) error("supplies-resource", "product", product.id, `The product ${product.id} gives the resource ${gift.resource}, and the catalog has no such resource.`);
|
|
120
125
|
else amount(product.id, `gift of ${gift.resource}`, gift.amount, resource.unit);
|
|
121
126
|
}
|
|
127
|
+
if (product.gives.length === 0 && product.basis === void 0) error("supplies-basis", "product", product.id, `The product ${product.id} gives no resource and has no basis. A product that gives no resource cites a fact in its basis.`);
|
|
128
|
+
if (product.basis !== void 0) {
|
|
129
|
+
const fact = facts.get(product.basis);
|
|
130
|
+
if (fact === void 0 || fact.use !== "fact") error("supplies-fact", "product", product.id, `The basis of the product ${product.id} cites ${String(product.basis)}, and the catalog has no fact with that id.`);
|
|
131
|
+
used.add(product.basis);
|
|
132
|
+
}
|
|
122
133
|
if (product.energy !== void 0) amount(product.id, "food energy", product.energy, ENERGY_UNIT);
|
|
134
|
+
if (product.average !== void 0) amount(product.id, "average price", product.average.read ? product.average.per : product.average, product.average.read ? product.average.per.unit : "");
|
|
123
135
|
if ("foodKeeper" in product.shelf) {
|
|
124
136
|
if (!(Number.isSafeInteger(product.shelf.foodKeeper) && product.shelf.foodKeeper > 0)) error("supplies-shelf", "product", product.id, `The FoodKeeper id of the product ${product.id} is ${String(product.shelf.foodKeeper)}. It must be a whole number more than 0.`);
|
|
125
137
|
} else amount(product.id, "shelf life", product.shelf, SHELF_UNIT);
|
|
@@ -174,26 +186,84 @@ function giftsOf(catalog, id, units) {
|
|
|
174
186
|
};
|
|
175
187
|
});
|
|
176
188
|
}
|
|
189
|
+
/**
|
|
190
|
+
* This function gives the price of one unit of each product with a join to a series, in the order of the catalog.
|
|
191
|
+
* It takes the last month of each series (`latestAverages`). The price is in the money of the average price.
|
|
192
|
+
*
|
|
193
|
+
* - A product with no join is not in the result.
|
|
194
|
+
* - A join with no read, a series with no price, and a unit that does not fit give no read. A no read is not 0.
|
|
195
|
+
* - The unit of the series must convert to the unit of the product, for example USD/lb to 1 kg.
|
|
196
|
+
* - With the option `since`, a last price before that month gives no read. A series that stops then gives no old price.
|
|
197
|
+
*
|
|
198
|
+
* @param catalog - The catalog
|
|
199
|
+
* @param prices - The average prices, from one or more reads
|
|
200
|
+
* @param options - The option `since`: the first month of a price that the result can use, in the form `YYYY-MM`
|
|
201
|
+
* @returns The price of one unit of each product with a join, or no read with the reason
|
|
202
|
+
* @throws RangeError when `since` is not a month in the form `YYYY-MM`
|
|
203
|
+
*/
|
|
204
|
+
function averageSupplyPrices(catalog, prices, options = {}) {
|
|
205
|
+
const { since } = options;
|
|
206
|
+
if (since !== void 0 && !monthSchema.safeParse(since).success) throw new RangeError(`The month ${String(since)} is not in the form YYYY-MM.`);
|
|
207
|
+
const last = new Map(latestAverages(prices).map((price) => [`${price.source}:${price.series}`, price]));
|
|
208
|
+
return catalog.products.flatMap((product) => {
|
|
209
|
+
const join = product.average;
|
|
210
|
+
if (join === void 0) return [];
|
|
211
|
+
const none = (why) => [{
|
|
212
|
+
product: product.id,
|
|
213
|
+
read: false,
|
|
214
|
+
why
|
|
215
|
+
}];
|
|
216
|
+
if (!join.read) return none(join.why);
|
|
217
|
+
const average = last.get(`${join.source}:${join.series}`);
|
|
218
|
+
if (average === void 0) return none(`The prices have no average price of the series ${join.series} of ${join.source}.`);
|
|
219
|
+
if (since !== void 0 && average.period < since) return none(`The last average price of the series ${join.series} of ${join.source} is for ${average.period}, before ${since}.`);
|
|
220
|
+
const money = moneyOf(average.price.unit);
|
|
221
|
+
if (money === void 0) return none(`The unit ${average.price.unit} of ${average.id} is not a price for each unit of an amount.`);
|
|
222
|
+
if (!known(join.per.unit)) return none(`The unit ${String(join.per.unit)} of the product ${product.id} is not a known unit.`);
|
|
223
|
+
const unit = `${money}/${join.per.unit}`;
|
|
224
|
+
const why = whyNotConvertible(average.price.unit, unit);
|
|
225
|
+
if (why !== void 0) return none(`The average price ${average.id} is in ${average.price.unit}, and it does not convert to ${unit}: ${why}.`);
|
|
226
|
+
const price = quantity(valueIn(average.price, unit) * join.per.amount, money);
|
|
227
|
+
return [{
|
|
228
|
+
product: product.id,
|
|
229
|
+
read: true,
|
|
230
|
+
price,
|
|
231
|
+
average: average.id,
|
|
232
|
+
period: average.period
|
|
233
|
+
}];
|
|
234
|
+
});
|
|
235
|
+
}
|
|
177
236
|
// src/supplies-data.ts
|
|
178
237
|
const CHECKED = "2026-11-22";
|
|
179
238
|
/** The reference catalog of supplies. A household adds its own products to a copy of it. */
|
|
180
239
|
const SUPPLY_CATALOG = {
|
|
181
240
|
format: SUPPLY_FORMAT,
|
|
182
|
-
sources: [
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
241
|
+
sources: [
|
|
242
|
+
{
|
|
243
|
+
id: "ready.water",
|
|
244
|
+
title: "Water",
|
|
245
|
+
url: "https://www.ready.gov/water",
|
|
246
|
+
license: "us-public-domain",
|
|
247
|
+
checked: CHECKED,
|
|
248
|
+
by: "FEMA (Ready.gov)"
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
id: "ready.kit",
|
|
252
|
+
title: "Build A Kit",
|
|
253
|
+
url: "https://www.ready.gov/kit",
|
|
254
|
+
license: "us-public-domain",
|
|
255
|
+
checked: CHECKED,
|
|
256
|
+
by: "FEMA (Ready.gov)"
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
id: "fdc.sr-legacy",
|
|
260
|
+
title: "FoodData Central, SR Legacy",
|
|
261
|
+
url: "https://fdc.nal.usda.gov/",
|
|
262
|
+
license: "cc0",
|
|
263
|
+
checked: CHECKED,
|
|
264
|
+
by: "USDA Agricultural Research Service"
|
|
265
|
+
}
|
|
266
|
+
],
|
|
197
267
|
facts: [
|
|
198
268
|
{
|
|
199
269
|
id: "ready.water-replace",
|
|
@@ -215,6 +285,48 @@ const SUPPLY_CATALOG = {
|
|
|
215
285
|
text: "The item 173904 (oats, regular and quick, not fortified, dry) gives 379 kcal in 100 g. Thus 1 kg gives 3790 kcal.",
|
|
216
286
|
source: "fdc.sr-legacy",
|
|
217
287
|
locator: "FDC ID 173904"
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
id: "fdc.beans-black",
|
|
291
|
+
use: "fact",
|
|
292
|
+
text: "The item 173734 (black beans, mature seeds, raw) gives 341 kcal in 100 g. Thus 1 kg gives 3410 kcal.",
|
|
293
|
+
source: "fdc.sr-legacy",
|
|
294
|
+
locator: "FDC ID 173734"
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
id: "fdc.peanut-butter",
|
|
298
|
+
use: "fact",
|
|
299
|
+
text: "The item 174266 (peanut butter, smooth style, with salt) gives 598 kcal in 100 g. Thus 1 kg gives 5980 kcal.",
|
|
300
|
+
source: "fdc.sr-legacy",
|
|
301
|
+
locator: "FDC ID 174266"
|
|
302
|
+
},
|
|
303
|
+
{
|
|
304
|
+
id: "ready.kit-flashlight",
|
|
305
|
+
use: "fact",
|
|
306
|
+
text: "The basic kit of the page has a flashlight and extra batteries.",
|
|
307
|
+
source: "ready.kit",
|
|
308
|
+
locator: "Basic Disaster Supplies Kit"
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
id: "ready.kit-first-aid",
|
|
312
|
+
use: "fact",
|
|
313
|
+
text: "The basic kit of the page has a first aid kit.",
|
|
314
|
+
source: "ready.kit",
|
|
315
|
+
locator: "Basic Disaster Supplies Kit"
|
|
316
|
+
},
|
|
317
|
+
{
|
|
318
|
+
id: "ready.kit-radio",
|
|
319
|
+
use: "fact",
|
|
320
|
+
text: "The basic kit of the page has a radio on batteries or a hand crank, and a NOAA Weather Radio with tone alert.",
|
|
321
|
+
source: "ready.kit",
|
|
322
|
+
locator: "Basic Disaster Supplies Kit"
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
id: "ready.kit-sleeping-bag",
|
|
326
|
+
use: "fact",
|
|
327
|
+
text: "The page tells to add a sleeping bag or a warm blanket for each person.",
|
|
328
|
+
source: "ready.kit",
|
|
329
|
+
locator: "Additional Emergency Supplies"
|
|
218
330
|
}
|
|
219
331
|
],
|
|
220
332
|
resources: [
|
|
@@ -228,6 +340,16 @@ const SUPPLY_CATALOG = {
|
|
|
228
340
|
unit: "kg",
|
|
229
341
|
title: "Dry grain, to cook with water and fuel"
|
|
230
342
|
},
|
|
343
|
+
{
|
|
344
|
+
code: "food.legume-dry",
|
|
345
|
+
unit: "kg",
|
|
346
|
+
title: "Dry beans, to cook with water and fuel"
|
|
347
|
+
},
|
|
348
|
+
{
|
|
349
|
+
code: "food.no-cook",
|
|
350
|
+
unit: "kcal",
|
|
351
|
+
title: "Food energy to eat with no water and no fuel"
|
|
352
|
+
},
|
|
231
353
|
{
|
|
232
354
|
code: "energy.battery",
|
|
233
355
|
unit: "Wh",
|
|
@@ -295,6 +417,17 @@ const SUPPLY_CATALOG = {
|
|
|
295
417
|
shelf: {
|
|
296
418
|
read: true,
|
|
297
419
|
foodKeeper: 338
|
|
420
|
+
},
|
|
421
|
+
average: {
|
|
422
|
+
read: true,
|
|
423
|
+
source: "bls-ap",
|
|
424
|
+
series: "APU0000701312",
|
|
425
|
+
per: {
|
|
426
|
+
read: true,
|
|
427
|
+
amount: 1,
|
|
428
|
+
unit: "kg",
|
|
429
|
+
definition: "The product is 1 kg of dry white long-grain rice, the item of the series."
|
|
430
|
+
}
|
|
298
431
|
}
|
|
299
432
|
},
|
|
300
433
|
{
|
|
@@ -319,6 +452,117 @@ const SUPPLY_CATALOG = {
|
|
|
319
452
|
shelf: {
|
|
320
453
|
read: true,
|
|
321
454
|
foodKeeper: 375
|
|
455
|
+
},
|
|
456
|
+
average: {
|
|
457
|
+
read: false,
|
|
458
|
+
why: "The known series of average prices have no series of oats yet."
|
|
459
|
+
}
|
|
460
|
+
},
|
|
461
|
+
{
|
|
462
|
+
id: "food.beans-dry-1kg",
|
|
463
|
+
title: "Dry beans, 1 kg",
|
|
464
|
+
kind: "food",
|
|
465
|
+
gives: [{
|
|
466
|
+
resource: "food.legume-dry",
|
|
467
|
+
amount: {
|
|
468
|
+
read: true,
|
|
469
|
+
amount: 1,
|
|
470
|
+
unit: "kg",
|
|
471
|
+
definition: "The product is 1 kg of dry beans."
|
|
472
|
+
}
|
|
473
|
+
}],
|
|
474
|
+
energy: {
|
|
475
|
+
read: true,
|
|
476
|
+
amount: 3410,
|
|
477
|
+
unit: "kcal",
|
|
478
|
+
fact: "fdc.beans-black"
|
|
479
|
+
},
|
|
480
|
+
shelf: {
|
|
481
|
+
read: true,
|
|
482
|
+
foodKeeper: 333
|
|
483
|
+
},
|
|
484
|
+
average: {
|
|
485
|
+
read: true,
|
|
486
|
+
source: "bls-ap",
|
|
487
|
+
series: "APU0000714233",
|
|
488
|
+
per: {
|
|
489
|
+
read: true,
|
|
490
|
+
amount: 1,
|
|
491
|
+
unit: "kg",
|
|
492
|
+
definition: "The product is 1 kg of dry beans of any type, the item of the series."
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
},
|
|
496
|
+
{
|
|
497
|
+
id: "food.peanut-butter-1kg",
|
|
498
|
+
title: "Peanut butter, smooth, 1 kg",
|
|
499
|
+
kind: "food",
|
|
500
|
+
gives: [{
|
|
501
|
+
resource: "food.no-cook",
|
|
502
|
+
amount: {
|
|
503
|
+
read: true,
|
|
504
|
+
amount: 5980,
|
|
505
|
+
unit: "kcal",
|
|
506
|
+
fact: "fdc.peanut-butter"
|
|
507
|
+
}
|
|
508
|
+
}],
|
|
509
|
+
energy: {
|
|
510
|
+
read: true,
|
|
511
|
+
amount: 5980,
|
|
512
|
+
unit: "kcal",
|
|
513
|
+
fact: "fdc.peanut-butter"
|
|
514
|
+
},
|
|
515
|
+
shelf: {
|
|
516
|
+
read: true,
|
|
517
|
+
foodKeeper: 387
|
|
518
|
+
},
|
|
519
|
+
average: {
|
|
520
|
+
read: false,
|
|
521
|
+
why: "The known series of average prices have no series of peanut butter yet."
|
|
522
|
+
}
|
|
523
|
+
},
|
|
524
|
+
{
|
|
525
|
+
id: "light.flashlight",
|
|
526
|
+
title: "A flashlight on batteries",
|
|
527
|
+
kind: "light",
|
|
528
|
+
basis: "ready.kit-flashlight",
|
|
529
|
+
gives: [],
|
|
530
|
+
shelf: {
|
|
531
|
+
read: false,
|
|
532
|
+
why: "The source gives no shelf life. The batteries have the date on their label."
|
|
533
|
+
}
|
|
534
|
+
},
|
|
535
|
+
{
|
|
536
|
+
id: "heat.sleeping-bag",
|
|
537
|
+
title: "A sleeping bag for each person",
|
|
538
|
+
kind: "heat",
|
|
539
|
+
basis: "ready.kit-sleeping-bag",
|
|
540
|
+
gives: [],
|
|
541
|
+
shelf: {
|
|
542
|
+
read: false,
|
|
543
|
+
why: "The source gives no shelf life."
|
|
544
|
+
}
|
|
545
|
+
},
|
|
546
|
+
{
|
|
547
|
+
id: "first-aid.kit",
|
|
548
|
+
title: "A first aid kit",
|
|
549
|
+
kind: "first-aid",
|
|
550
|
+
basis: "ready.kit-first-aid",
|
|
551
|
+
gives: [],
|
|
552
|
+
shelf: {
|
|
553
|
+
read: false,
|
|
554
|
+
why: "The source gives no shelf life. Each item of the kit has the date on its label."
|
|
555
|
+
}
|
|
556
|
+
},
|
|
557
|
+
{
|
|
558
|
+
id: "communication.noaa-radio",
|
|
559
|
+
title: "A NOAA Weather Radio with tone alert, on batteries or a hand crank",
|
|
560
|
+
kind: "communication",
|
|
561
|
+
basis: "ready.kit-radio",
|
|
562
|
+
gives: [],
|
|
563
|
+
shelf: {
|
|
564
|
+
read: false,
|
|
565
|
+
why: "The source gives no shelf life."
|
|
322
566
|
}
|
|
323
567
|
},
|
|
324
568
|
{
|
|
@@ -343,6 +587,154 @@ const SUPPLY_CATALOG = {
|
|
|
343
587
|
}
|
|
344
588
|
]
|
|
345
589
|
};
|
|
346
|
-
|
|
590
|
+
// src/food-plan.ts
|
|
591
|
+
/** This function gives the money of a cost for each unit of time, for example `USD` for `USD/wk`. */
|
|
592
|
+
function moneyOfRate(unit) {
|
|
593
|
+
const money = moneyAbove(unit);
|
|
594
|
+
return money !== void 0 && convertible(unit, `${money}/d`) ? money : void 0;
|
|
595
|
+
}
|
|
596
|
+
/** The age and sex groups of a food plan of USDA. */
|
|
597
|
+
const FOOD_PLAN_GROUPS = [
|
|
598
|
+
"child-1",
|
|
599
|
+
"child-2-3",
|
|
600
|
+
"child-4-5",
|
|
601
|
+
"child-6-8",
|
|
602
|
+
"child-9-11",
|
|
603
|
+
"female-12-13",
|
|
604
|
+
"female-14-19",
|
|
605
|
+
"female-20-50",
|
|
606
|
+
"female-51-70",
|
|
607
|
+
"female-71-up",
|
|
608
|
+
"male-12-13",
|
|
609
|
+
"male-14-19",
|
|
610
|
+
"male-20-50",
|
|
611
|
+
"male-51-70",
|
|
612
|
+
"male-71-up"
|
|
613
|
+
];
|
|
614
|
+
/**
|
|
615
|
+
* This function gives the cost of a food plan for the members of a household and a count of days. It adds the cost of
|
|
616
|
+
* each person, and then it applies the change for the size of the household.
|
|
617
|
+
*
|
|
618
|
+
* @param plan - The food plan
|
|
619
|
+
* @param members - The groups of the members of the household, each with its count of persons
|
|
620
|
+
* @param days - The count of days, a finite number of 0 or more
|
|
621
|
+
* @throws RangeError when a count of persons is not a whole number of 0 or more, or when the household has no person
|
|
622
|
+
* @throws RangeError when a group is not in the plan, or when the plan has no change for the size of the household
|
|
623
|
+
* @throws RangeError when the count of days is not a finite number of 0 or more
|
|
624
|
+
*/
|
|
625
|
+
function foodPlanCost(plan, members, days) {
|
|
626
|
+
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.`);
|
|
627
|
+
let persons = 0;
|
|
628
|
+
let money;
|
|
629
|
+
let total = 0;
|
|
630
|
+
for (const member of members) {
|
|
631
|
+
if (!(Number.isSafeInteger(member.count) && member.count >= 0)) throw new RangeError(`The count of the group ${member.group} is ${String(member.count)}. It must be a whole number of 0 or more.`);
|
|
632
|
+
const weekly = plan.weekly[member.group];
|
|
633
|
+
const symbol = weekly === void 0 ? void 0 : moneyOfRate(weekly.unit);
|
|
634
|
+
if (weekly === void 0 || symbol === void 0) throw new RangeError(`The plan ${plan.id} has no cost for each unit of time of the group ${String(member.group)}.`);
|
|
635
|
+
if (money !== void 0 && symbol !== money) throw new RangeError(`The plan ${plan.id} has costs in ${money} and in ${symbol}.`);
|
|
636
|
+
money = symbol;
|
|
637
|
+
persons += member.count;
|
|
638
|
+
total += member.count * valueIn(weekly, `${symbol}/d`) * days;
|
|
639
|
+
}
|
|
640
|
+
if (persons === 0 || money === void 0) throw new RangeError("The household has no person.");
|
|
641
|
+
const size = plan.sizes.find((each) => persons >= each.from && (each.to === void 0 || persons <= each.to));
|
|
642
|
+
if (size === void 0) throw new RangeError(`The plan ${plan.id} has no change for a household of ${String(persons)} persons.`);
|
|
643
|
+
return quantity(total * (1 + size.change), money);
|
|
644
|
+
}
|
|
645
|
+
/**
|
|
646
|
+
* This function compares the cost of the food of a buy list with the cost of a food plan for the same members and
|
|
647
|
+
* days. A list of dry staples costs less than the plan, because the plan is a full diet. A ratio above 1 tells that
|
|
648
|
+
* a price or an amount of the list is possibly wrong. A low ratio is normal, because a list can be any part of a diet.
|
|
649
|
+
* The check of the amount of food is a check of its energy, not of its cost.
|
|
650
|
+
*
|
|
651
|
+
* @param cost - The cost of the food, in a money that converts to the money of the plan
|
|
652
|
+
* @param plan - The food plan
|
|
653
|
+
* @param members - The groups of the members of the household, each with its count of persons
|
|
654
|
+
* @param days - The count of days of the food
|
|
655
|
+
* @throws RangeError for the errors of `foodPlanCost`
|
|
656
|
+
* @throws The error of `valueIn` of `@mark1russell7/quantity` when the money of the cost does not convert to the money of the plan
|
|
657
|
+
*/
|
|
658
|
+
function foodPlanCheck(cost, plan, members, days) {
|
|
659
|
+
const planned = foodPlanCost(plan, members, days);
|
|
660
|
+
const value = valueIn(cost, planned.unit);
|
|
661
|
+
const ratio = planned.value === 0 ? value === 0 ? 0 : Number.POSITIVE_INFINITY : value / planned.value;
|
|
662
|
+
return {
|
|
663
|
+
plan: planned,
|
|
664
|
+
cost: quantity(value, planned.unit),
|
|
665
|
+
ratio,
|
|
666
|
+
above: ratio > 1
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
// src/food-plan-data.ts
|
|
670
|
+
const week = (value) => ({
|
|
671
|
+
value,
|
|
672
|
+
unit: "USD/wk"
|
|
673
|
+
});
|
|
674
|
+
/** The costs of the food plans of USDA, one record for each plan and month. */
|
|
675
|
+
const FOOD_PLANS = [{
|
|
676
|
+
id: "usda.thrifty:2026-10",
|
|
677
|
+
title: "Official USDA Thrifty Food Plan: U.S. Average, October 2026",
|
|
678
|
+
area: "U.S. average",
|
|
679
|
+
period: "2026-10",
|
|
680
|
+
source: {
|
|
681
|
+
id: "usda.food-plans",
|
|
682
|
+
title: "USDA Food Plans: Monthly Cost of Food Reports",
|
|
683
|
+
url: "https://www.fna.usda.gov/research/cnpp/usda-food-plans/cost-food-monthly-reports",
|
|
684
|
+
license: "us-public-domain",
|
|
685
|
+
checked: "2026-11-22",
|
|
686
|
+
by: "USDA Food and Nutrition Administration"
|
|
687
|
+
},
|
|
688
|
+
locator: "CostofFoodOct2026Thrifty.pdf, the column Weekly Cost of the table of age-sex groups",
|
|
689
|
+
weekly: {
|
|
690
|
+
"child-1": week(26.4),
|
|
691
|
+
"child-2-3": week(39.8),
|
|
692
|
+
"child-4-5": week(43.5),
|
|
693
|
+
"child-6-8": week(48.3),
|
|
694
|
+
"child-9-11": week(55.8),
|
|
695
|
+
"female-12-13": week(51.7),
|
|
696
|
+
"female-14-19": week(60.1),
|
|
697
|
+
"female-20-50": week(58.7),
|
|
698
|
+
"female-51-70": week(54.6),
|
|
699
|
+
"female-71-up": week(60.3),
|
|
700
|
+
"male-12-13": week(59.7),
|
|
701
|
+
"male-14-19": week(75.3),
|
|
702
|
+
"male-20-50": week(73.7),
|
|
703
|
+
"male-51-70": week(65),
|
|
704
|
+
"male-71-up": week(62)
|
|
705
|
+
},
|
|
706
|
+
sizes: [
|
|
707
|
+
{
|
|
708
|
+
from: 1,
|
|
709
|
+
to: 1,
|
|
710
|
+
change: .2
|
|
711
|
+
},
|
|
712
|
+
{
|
|
713
|
+
from: 2,
|
|
714
|
+
to: 2,
|
|
715
|
+
change: .1
|
|
716
|
+
},
|
|
717
|
+
{
|
|
718
|
+
from: 3,
|
|
719
|
+
to: 3,
|
|
720
|
+
change: .05
|
|
721
|
+
},
|
|
722
|
+
{
|
|
723
|
+
from: 4,
|
|
724
|
+
to: 4,
|
|
725
|
+
change: 0
|
|
726
|
+
},
|
|
727
|
+
{
|
|
728
|
+
from: 5,
|
|
729
|
+
to: 6,
|
|
730
|
+
change: -.05
|
|
731
|
+
},
|
|
732
|
+
{
|
|
733
|
+
from: 7,
|
|
734
|
+
change: -.1
|
|
735
|
+
}
|
|
736
|
+
]
|
|
737
|
+
}];
|
|
738
|
+
export { FOOD_PLANS, FOOD_PLAN_GROUPS, SUPPLY_CATALOG, SUPPLY_CODES, SUPPLY_FORMAT, SUPPLY_KINDS, averageSupplyPrices, checkSupplies, foodPlanCheck, foodPlanCost, giftsOf, supplyWants };
|
|
347
739
|
|
|
348
740
|
//# sourceMappingURL=supplies-entry.js.map
|