@recipe-book/core 0.1.1 → 0.1.2
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/CHANGELOG.md +35 -0
- package/dist/{chunk-D5CV3UF7.cjs → chunk-ISRDJR2O.cjs} +42 -9
- package/dist/chunk-ISRDJR2O.cjs.map +1 -0
- package/dist/errors.js +29 -1
- package/dist/errors.js.map +1 -1
- package/dist/format/duration.js.map +1 -1
- package/dist/format/ingredient.js.map +1 -1
- package/dist/format/quantity.js.map +1 -1
- package/dist/format/servings.js.map +1 -1
- package/dist/format/temperature.js.map +1 -1
- package/dist/index.cjs +62 -58
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +38 -11
- package/dist/index.d.ts +38 -11
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/quantity/parse.js.map +1 -1
- package/dist/quantity/scale.js.map +1 -1
- package/dist/recipe/ids.js.map +1 -1
- package/dist/recipe/parse.js +11 -6
- package/dist/recipe/parse.js.map +1 -1
- package/dist/resolve.js.map +1 -1
- package/dist/schema-org/from-json-ld.js +16 -23
- package/dist/schema-org/from-json-ld.js.map +1 -1
- package/dist/schema-org/to-json-ld.js.map +1 -1
- package/dist/schema-org.cjs +75 -82
- package/dist/schema-org.cjs.map +1 -1
- package/dist/schema-org.d.cts +3 -2
- package/dist/schema-org.d.ts +3 -2
- package/dist/steps/segment.js.map +1 -1
- package/dist/steps/temperature.js +1 -1
- package/dist/steps/temperature.js.map +1 -1
- package/dist/{types-BknM8KOd.d.cts → types-CKIoWsz8.d.cts} +21 -4
- package/dist/{types-BknM8KOd.d.ts → types-CKIoWsz8.d.ts} +21 -4
- package/dist/units/convert.js.map +1 -1
- package/dist/units/temperature.js.map +1 -1
- package/dist/validation.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-D5CV3UF7.cjs.map +0 -1
package/dist/schema-org.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkISRDJR2O_cjs = require('./chunk-ISRDJR2O.cjs');
|
|
4
4
|
|
|
5
5
|
// src/schema-org/find.ts
|
|
6
6
|
var MAX_DEPTH = 32;
|
|
@@ -22,7 +22,7 @@ function scan(documents, lists) {
|
|
|
22
22
|
}
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
25
|
-
const fields =
|
|
25
|
+
const fields = chunkISRDJR2O_cjs.asRecord(value);
|
|
26
26
|
if (!fields) {
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
@@ -84,7 +84,7 @@ function entriesOf(value, path) {
|
|
|
84
84
|
}
|
|
85
85
|
const entries = [];
|
|
86
86
|
for (let i = 0; i < value.length; i++) {
|
|
87
|
-
if (
|
|
87
|
+
if (chunkISRDJR2O_cjs.hasOwn(value, i)) {
|
|
88
88
|
entries.push([value[i], [...path, i]]);
|
|
89
89
|
}
|
|
90
90
|
}
|
|
@@ -92,9 +92,9 @@ function entriesOf(value, path) {
|
|
|
92
92
|
}
|
|
93
93
|
function findRecipeJsonLd(html) {
|
|
94
94
|
if (typeof html !== "string") {
|
|
95
|
-
throw new
|
|
95
|
+
throw new chunkISRDJR2O_cjs.RecipeBookError(
|
|
96
96
|
"invalid_argument",
|
|
97
|
-
`findRecipeJsonLd: html must be a string, such as await response.text(), received ${
|
|
97
|
+
`findRecipeJsonLd: html must be a string, such as await response.text(), received ${chunkISRDJR2O_cjs.describeValue(html)}.`
|
|
98
98
|
);
|
|
99
99
|
}
|
|
100
100
|
const documents = [];
|
|
@@ -117,7 +117,7 @@ function findRecipeJsonLd(html) {
|
|
|
117
117
|
}
|
|
118
118
|
function withImages(node, ids) {
|
|
119
119
|
const follow = (value) => {
|
|
120
|
-
const id =
|
|
120
|
+
const id = chunkISRDJR2O_cjs.isRecord(value) && Object.keys(value).join() === "@id" && value["@id"];
|
|
121
121
|
const target = typeof id === "string" && ids.get(id)?.node;
|
|
122
122
|
return target && target !== node ? target : value;
|
|
123
123
|
};
|
|
@@ -129,7 +129,7 @@ function withImages(node, ids) {
|
|
|
129
129
|
if (Array.isArray(value)) {
|
|
130
130
|
return value.map((entry) => copy(entry, depth + 1, keys));
|
|
131
131
|
}
|
|
132
|
-
const fields =
|
|
132
|
+
const fields = chunkISRDJR2O_cjs.asRecord(value);
|
|
133
133
|
if (!fields) {
|
|
134
134
|
return value;
|
|
135
135
|
}
|
|
@@ -263,11 +263,11 @@ function cleanLines(text2) {
|
|
|
263
263
|
const code = decimal === void 0 ? parseInt(hex, 16) : +decimal;
|
|
264
264
|
return code > 0 && code <= 1114111 && (code < 55296 || code > 57343) ? String.fromCodePoint(code) : entity;
|
|
265
265
|
}
|
|
266
|
-
if (
|
|
266
|
+
if (chunkISRDJR2O_cjs.hasOwn(NAMED_ENTITIES, name)) {
|
|
267
267
|
return NAMED_ENTITIES[name];
|
|
268
268
|
}
|
|
269
269
|
const accent = /^([aceinouyACEINOUY])([a-z]+)$/.exec(name);
|
|
270
|
-
return accent &&
|
|
270
|
+
return accent && chunkISRDJR2O_cjs.hasOwn(MARKS, accent[2]) ? `${accent[1]}${MARKS[accent[2]]}`.normalize("NFC") : entity;
|
|
271
271
|
}
|
|
272
272
|
).split(/[\n\r\u2028\u2029]/).map((line) => line.replace(/\s+/g, " ").trim()).filter(Boolean);
|
|
273
273
|
}
|
|
@@ -303,11 +303,6 @@ var READ_FIELDS = [
|
|
|
303
303
|
"tool",
|
|
304
304
|
"nutrition"
|
|
305
305
|
];
|
|
306
|
-
var TIMES = [
|
|
307
|
-
["prep", "prepTime"],
|
|
308
|
-
["cook", "cookTime"],
|
|
309
|
-
["total", "totalTime"]
|
|
310
|
-
];
|
|
311
306
|
var MAX_URL_LENGTH = 4096;
|
|
312
307
|
var SERVINGS_WORD = /^(?:servings?|portions?|(?:serving|portion)\(s\)|people|persons?)\.?$/i;
|
|
313
308
|
function fromJsonLd(input) {
|
|
@@ -315,18 +310,18 @@ function fromJsonLd(input) {
|
|
|
315
310
|
const [found] = recipes;
|
|
316
311
|
if (!found) {
|
|
317
312
|
return {
|
|
318
|
-
...
|
|
319
|
-
|
|
313
|
+
...chunkISRDJR2O_cjs.toResult("invalid_recipe", void 0, [
|
|
314
|
+
chunkISRDJR2O_cjs.issue(
|
|
320
315
|
"error",
|
|
321
316
|
"invalid_type",
|
|
322
317
|
[],
|
|
323
|
-
`Expected a schema.org Recipe, or an array, @graph, mainEntity, or ItemList that holds one, received ${
|
|
318
|
+
`Expected a schema.org Recipe, or an array, @graph, mainEntity, or ItemList that holds one, received ${chunkISRDJR2O_cjs.describeValue(input)}.`
|
|
324
319
|
)
|
|
325
320
|
]),
|
|
326
321
|
extra: {}
|
|
327
322
|
};
|
|
328
323
|
}
|
|
329
|
-
const node =
|
|
324
|
+
const node = chunkISRDJR2O_cjs.asRecord(found.node);
|
|
330
325
|
const reader = {
|
|
331
326
|
recipe: found.node,
|
|
332
327
|
ids,
|
|
@@ -339,15 +334,15 @@ function fromJsonLd(input) {
|
|
|
339
334
|
};
|
|
340
335
|
const name = text(node.name);
|
|
341
336
|
if (recipes.length > 1) {
|
|
342
|
-
|
|
337
|
+
chunkISRDJR2O_cjs.warning(
|
|
343
338
|
reader.warnings,
|
|
344
339
|
"ignored_value",
|
|
345
340
|
[],
|
|
346
|
-
`Found ${recipes.length} recipes. Only the first${typeof name === "string" ? `, ${
|
|
341
|
+
`Found ${recipes.length} recipes. Only the first${typeof name === "string" ? `, ${chunkISRDJR2O_cjs.quote(name)},` : ""} is read.`
|
|
347
342
|
);
|
|
348
343
|
}
|
|
349
344
|
const model = readRecipe(reader, node, found.path);
|
|
350
|
-
const parse = () =>
|
|
345
|
+
const parse = () => chunkISRDJR2O_cjs.parseRecipeWith(model, chunkISRDJR2O_cjs.parseIngredientLine);
|
|
351
346
|
let result = parse();
|
|
352
347
|
const dropped = [];
|
|
353
348
|
if (!result.success) {
|
|
@@ -388,11 +383,11 @@ function fromJsonLd(input) {
|
|
|
388
383
|
}
|
|
389
384
|
const path = [...found.path, key];
|
|
390
385
|
if (tooDeep(value, path.length, checked)) {
|
|
391
|
-
|
|
386
|
+
chunkISRDJR2O_cjs.warning(
|
|
392
387
|
issues,
|
|
393
388
|
"invalid_type",
|
|
394
389
|
path,
|
|
395
|
-
`Expected a value to keep in extra, received ${
|
|
390
|
+
`Expected a value to keep in extra, received ${chunkISRDJR2O_cjs.describeValue(value)} nested more than ${MAX_DEPTH} levels deep. It is ignored.`
|
|
396
391
|
);
|
|
397
392
|
return false;
|
|
398
393
|
}
|
|
@@ -400,11 +395,11 @@ function fromJsonLd(input) {
|
|
|
400
395
|
})
|
|
401
396
|
);
|
|
402
397
|
return {
|
|
403
|
-
...
|
|
398
|
+
...chunkISRDJR2O_cjs.toResult(
|
|
404
399
|
"invalid_recipe",
|
|
405
400
|
result.success ? result.data : void 0,
|
|
406
401
|
issues,
|
|
407
|
-
typeof name === "string" ?
|
|
402
|
+
typeof name === "string" ? chunkISRDJR2O_cjs.quote(name) : void 0
|
|
408
403
|
),
|
|
409
404
|
extra
|
|
410
405
|
};
|
|
@@ -440,7 +435,8 @@ function readRecipe(reader, node, base) {
|
|
|
440
435
|
}
|
|
441
436
|
readYield(reader, model, node.recipeYield, at("recipeYield"));
|
|
442
437
|
const times = {};
|
|
443
|
-
for (const [
|
|
438
|
+
for (const key of ["prep", "cook", "total"]) {
|
|
439
|
+
const field = `${key}Time`;
|
|
444
440
|
const minutes = readTime(reader, node[field], at(field));
|
|
445
441
|
if (minutes !== void 0) {
|
|
446
442
|
times[key] = minutes;
|
|
@@ -478,7 +474,7 @@ function readImage(reader, value, source) {
|
|
|
478
474
|
reader,
|
|
479
475
|
"invalid_type",
|
|
480
476
|
source,
|
|
481
|
-
`Expected an image URL, an ImageObject with a url, or a list of them, received ${
|
|
477
|
+
`Expected an image URL, an ImageObject with a url, or a list of them, received ${chunkISRDJR2O_cjs.describeValue(value)}.`
|
|
482
478
|
);
|
|
483
479
|
}
|
|
484
480
|
return image;
|
|
@@ -491,20 +487,20 @@ function findImage(reader, value, source, referenced = false) {
|
|
|
491
487
|
reader,
|
|
492
488
|
"invalid_type",
|
|
493
489
|
source,
|
|
494
|
-
`Expected an image URL, an ImageObject with a url, or a list of them, received ${
|
|
490
|
+
`Expected an image URL, an ImageObject with a url, or a list of them, received ${chunkISRDJR2O_cjs.describeValue(value)} nested more than ${MAX_DEPTH} levels deep.`
|
|
495
491
|
);
|
|
496
492
|
}
|
|
497
493
|
return void 0;
|
|
498
494
|
}
|
|
499
495
|
if (typeof value === "string") {
|
|
500
496
|
const url = cleanText(value);
|
|
501
|
-
const scheme =
|
|
497
|
+
const scheme = chunkISRDJR2O_cjs.disallowedScheme(url);
|
|
502
498
|
if (scheme) {
|
|
503
499
|
ignore(
|
|
504
500
|
reader,
|
|
505
501
|
"invalid_url",
|
|
506
502
|
source,
|
|
507
|
-
`Expected an http or https URL, or a relative one, received ${
|
|
503
|
+
`Expected an http or https URL, or a relative one, received ${chunkISRDJR2O_cjs.quote(`${scheme}\u2026`)}.`
|
|
508
504
|
);
|
|
509
505
|
return void 0;
|
|
510
506
|
}
|
|
@@ -538,7 +534,7 @@ function findImage(reader, value, source, referenced = false) {
|
|
|
538
534
|
reader.deepest = Math.max(reader.deepest, source.length + read[2]);
|
|
539
535
|
return read[0];
|
|
540
536
|
}
|
|
541
|
-
const record =
|
|
537
|
+
const record = chunkISRDJR2O_cjs.asRecord(value);
|
|
542
538
|
if (!record) {
|
|
543
539
|
return void 0;
|
|
544
540
|
}
|
|
@@ -549,15 +545,17 @@ function findImage(reader, value, source, referenced = false) {
|
|
|
549
545
|
const id = record["@id"];
|
|
550
546
|
const target = typeof id === "string" && !referenced ? reader.ids.get(id) : void 0;
|
|
551
547
|
let image = findImage(reader, record.url, [...source, "url"], referenced) ?? findImage(reader, record.contentUrl, [...source, "contentUrl"], referenced);
|
|
552
|
-
if (!image && target
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
548
|
+
if (!image && target) {
|
|
549
|
+
if (target.node === reader.recipe) {
|
|
550
|
+
ignore(
|
|
551
|
+
reader,
|
|
552
|
+
"invalid_type",
|
|
553
|
+
source,
|
|
554
|
+
"Expected an image URL, an ImageObject with a url, or a list of them, received a reference to the recipe itself."
|
|
555
|
+
);
|
|
556
|
+
} else {
|
|
557
|
+
image = findImage(reader, target.node, target.path, true);
|
|
558
|
+
}
|
|
561
559
|
}
|
|
562
560
|
reads.push([
|
|
563
561
|
image,
|
|
@@ -580,21 +578,21 @@ function readYield(reader, model, value, source) {
|
|
|
580
578
|
const keptServings = servings.find((batch) => batch.worded) ?? servings.find((batch) => batch.amount !== kept?.amount);
|
|
581
579
|
for (const batch of servings) {
|
|
582
580
|
if (keptServings && batch.amount !== keptServings.amount && (batch.worded || batch.amount !== kept?.amount)) {
|
|
583
|
-
|
|
581
|
+
chunkISRDJR2O_cjs.warning(
|
|
584
582
|
reader.warnings,
|
|
585
583
|
"ignored_value",
|
|
586
584
|
batch.source,
|
|
587
|
-
`Only one number of servings is read, ${
|
|
585
|
+
`Only one number of servings is read, ${chunkISRDJR2O_cjs.quote(keptServings.label)}, so this one is ignored.`
|
|
588
586
|
);
|
|
589
587
|
}
|
|
590
588
|
}
|
|
591
589
|
for (const batch of yields) {
|
|
592
590
|
if (batch !== kept) {
|
|
593
|
-
|
|
591
|
+
chunkISRDJR2O_cjs.warning(
|
|
594
592
|
reader.warnings,
|
|
595
593
|
"ignored_value",
|
|
596
594
|
batch.source,
|
|
597
|
-
`Only one yield is read, ${
|
|
595
|
+
`Only one yield is read, ${chunkISRDJR2O_cjs.quote(kept.label)}, so this one is ignored.`
|
|
598
596
|
);
|
|
599
597
|
}
|
|
600
598
|
}
|
|
@@ -620,13 +618,13 @@ function readBatch(reader, value, source) {
|
|
|
620
618
|
/^(?:(?:serves|servings?|yields?|makes)\s*:?\s*)?(?:about\s+)?/i,
|
|
621
619
|
""
|
|
622
620
|
);
|
|
623
|
-
const match =
|
|
621
|
+
const match = chunkISRDJR2O_cjs.matchAmount(text2);
|
|
624
622
|
if (!match || "code" in match) {
|
|
625
623
|
ignore(
|
|
626
624
|
reader,
|
|
627
625
|
match?.code ?? "invalid_quantity",
|
|
628
626
|
source,
|
|
629
|
-
match?.message ?? `Expected a batch such as "24 cookies" or "3\u20134 loaves", received ${
|
|
627
|
+
match?.message ?? `Expected a batch such as "24 cookies" or "3\u20134 loaves", received ${chunkISRDJR2O_cjs.describeValue(label)}.`
|
|
630
628
|
);
|
|
631
629
|
return void 0;
|
|
632
630
|
}
|
|
@@ -634,7 +632,7 @@ function readBatch(reader, value, source) {
|
|
|
634
632
|
const rest = match.rest.trim();
|
|
635
633
|
return !rest || SERVINGS_WORD.test(rest) ? { source, label, amount: amount2, servings: match.amountText, worded: !!rest } : { source, label, amount: amount2, yield: text2, article: /^an?\s/i.test(text2) };
|
|
636
634
|
}
|
|
637
|
-
const record =
|
|
635
|
+
const record = chunkISRDJR2O_cjs.asRecord(value);
|
|
638
636
|
const amount = toNumber(record?.value ?? record?.minValue);
|
|
639
637
|
if (record && amount !== void 0) {
|
|
640
638
|
const max = toNumber(record.maxValue);
|
|
@@ -651,7 +649,7 @@ function readBatch(reader, value, source) {
|
|
|
651
649
|
reader,
|
|
652
650
|
"invalid_type",
|
|
653
651
|
source,
|
|
654
|
-
`Expected a yield such as "4 servings" or "24 cookies", received ${
|
|
652
|
+
`Expected a yield such as "4 servings" or "24 cookies", received ${chunkISRDJR2O_cjs.describeValue(value)}.`
|
|
655
653
|
);
|
|
656
654
|
}
|
|
657
655
|
return void 0;
|
|
@@ -660,13 +658,13 @@ function readTime(reader, value, source) {
|
|
|
660
658
|
if (isAbsent(value)) {
|
|
661
659
|
return void 0;
|
|
662
660
|
}
|
|
663
|
-
const minutes = typeof value === "string" ?
|
|
661
|
+
const minutes = typeof value === "string" ? chunkISRDJR2O_cjs.parseIsoDuration(cleanText(value)) : void 0;
|
|
664
662
|
if (minutes === void 0 || minutes > Number.MAX_SAFE_INTEGER) {
|
|
665
663
|
ignore(
|
|
666
664
|
reader,
|
|
667
665
|
"invalid_duration",
|
|
668
666
|
source,
|
|
669
|
-
`Expected an ISO 8601 duration such as "PT30M", received ${
|
|
667
|
+
`Expected an ISO 8601 duration such as "PT30M", received ${chunkISRDJR2O_cjs.describeValue(value)}${minutes === void 0 ? "" : ", which is too long"}.`
|
|
670
668
|
);
|
|
671
669
|
return void 0;
|
|
672
670
|
}
|
|
@@ -684,14 +682,14 @@ function readList(reader, key, value, source, readItem, expected) {
|
|
|
684
682
|
reader,
|
|
685
683
|
"invalid_type",
|
|
686
684
|
entrySource,
|
|
687
|
-
`Expected ${expected}, received ${
|
|
685
|
+
`Expected ${expected}, received ${chunkISRDJR2O_cjs.describeValue(entry)} nested more than ${MAX_DEPTH} levels deep.`
|
|
688
686
|
);
|
|
689
687
|
return;
|
|
690
688
|
}
|
|
691
689
|
if (Array.isArray(entry)) {
|
|
692
690
|
const elements2 = entriesOf(entry, entrySource);
|
|
693
691
|
const positions = elements2.map(
|
|
694
|
-
([element]) => toNumber(
|
|
692
|
+
([element]) => toNumber(chunkISRDJR2O_cjs.asRecord(element)?.position)
|
|
695
693
|
);
|
|
696
694
|
const order = [...elements2.keys()];
|
|
697
695
|
if (!positions.includes(void 0)) {
|
|
@@ -703,7 +701,7 @@ function readList(reader, key, value, source, readItem, expected) {
|
|
|
703
701
|
}
|
|
704
702
|
return;
|
|
705
703
|
}
|
|
706
|
-
const record =
|
|
704
|
+
const record = chunkISRDJR2O_cjs.asRecord(entry);
|
|
707
705
|
const elements = [...entrySource, "itemListElement"];
|
|
708
706
|
if (record?.itemListElement !== void 0 && record.text === void 0) {
|
|
709
707
|
const title = typeof record.name === "string" ? cleanText(record.name) : "";
|
|
@@ -735,7 +733,7 @@ function readList(reader, key, value, source, readItem, expected) {
|
|
|
735
733
|
reader,
|
|
736
734
|
"invalid_type",
|
|
737
735
|
entrySource,
|
|
738
|
-
`Expected ${expected}, received ${
|
|
736
|
+
`Expected ${expected}, received ${chunkISRDJR2O_cjs.describeValue(entry)}.`
|
|
739
737
|
);
|
|
740
738
|
return;
|
|
741
739
|
}
|
|
@@ -752,15 +750,10 @@ function readList(reader, key, value, source, readItem, expected) {
|
|
|
752
750
|
return list;
|
|
753
751
|
}
|
|
754
752
|
function readLine(reader, value, source) {
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
fields: []
|
|
760
|
-
}));
|
|
761
|
-
}
|
|
762
|
-
const record = chunkD5CV3UF7_cjs.asRecord(value);
|
|
763
|
-
const parts = [record?.value, record?.unitText, record?.name ?? record?.text].filter((part) => typeof part === "string" || typeof part === "number").join(" ");
|
|
753
|
+
const record = chunkISRDJR2O_cjs.asRecord(value);
|
|
754
|
+
const parts = typeof value === "string" ? value : [record?.value, record?.unitText, record?.name ?? record?.text].filter(
|
|
755
|
+
(part) => typeof part === "string" || typeof part === "number"
|
|
756
|
+
).join(" ");
|
|
764
757
|
return parts ? cleanLines(parts).map((line) => ({ value: line, source, fields: [] })) : void 0;
|
|
765
758
|
}
|
|
766
759
|
function readStep(reader, value, source) {
|
|
@@ -771,7 +764,7 @@ function readStep(reader, value, source) {
|
|
|
771
764
|
fields: []
|
|
772
765
|
}));
|
|
773
766
|
}
|
|
774
|
-
const record =
|
|
767
|
+
const record = chunkISRDJR2O_cjs.asRecord(value);
|
|
775
768
|
if (!record) {
|
|
776
769
|
return void 0;
|
|
777
770
|
}
|
|
@@ -802,12 +795,12 @@ function readTools(reader, value, source) {
|
|
|
802
795
|
const equipment = [];
|
|
803
796
|
link(reader, ["equipment"], source);
|
|
804
797
|
for (const [entry, entrySource] of entriesOf(value, source)) {
|
|
805
|
-
const record =
|
|
798
|
+
const record = chunkISRDJR2O_cjs.asRecord(entry);
|
|
806
799
|
const item = record ? {
|
|
807
800
|
name: text(record.name),
|
|
808
801
|
...record.requiredQuantity !== void 0 && {
|
|
809
802
|
quantity: toNumber(
|
|
810
|
-
|
|
803
|
+
chunkISRDJR2O_cjs.asRecord(record.requiredQuantity)?.value ?? record.requiredQuantity
|
|
811
804
|
) ?? record.requiredQuantity
|
|
812
805
|
},
|
|
813
806
|
...record.url !== void 0 && { url: text(record.url) }
|
|
@@ -834,13 +827,13 @@ function readNutrition(reader, value, source) {
|
|
|
834
827
|
if (isAbsent(value)) {
|
|
835
828
|
return void 0;
|
|
836
829
|
}
|
|
837
|
-
const record =
|
|
830
|
+
const record = chunkISRDJR2O_cjs.asRecord(value);
|
|
838
831
|
if (!record) {
|
|
839
832
|
ignore(
|
|
840
833
|
reader,
|
|
841
834
|
"invalid_type",
|
|
842
835
|
source,
|
|
843
|
-
`Expected NutritionInformation, such as { "calories": "250 kcal" }, received ${
|
|
836
|
+
`Expected NutritionInformation, such as { "calories": "250 kcal" }, received ${chunkISRDJR2O_cjs.describeValue(value)}.`
|
|
844
837
|
);
|
|
845
838
|
return void 0;
|
|
846
839
|
}
|
|
@@ -868,7 +861,7 @@ function isAbsent(value) {
|
|
|
868
861
|
return value === void 0 || value === null || typeof value === "string" && !value.trim();
|
|
869
862
|
}
|
|
870
863
|
function ignore(reader, code, path, message) {
|
|
871
|
-
|
|
864
|
+
chunkISRDJR2O_cjs.warning(reader.warnings, code, path, `${message} It is ignored.`);
|
|
872
865
|
}
|
|
873
866
|
function link(reader, path, source, droppable = false) {
|
|
874
867
|
const key = JSON.stringify(path);
|
|
@@ -920,11 +913,11 @@ function remove(model, path) {
|
|
|
920
913
|
// src/schema-org/to-json-ld.ts
|
|
921
914
|
function toJsonLd(recipe, options) {
|
|
922
915
|
const { servings, system, url, extra } = options ?? {};
|
|
923
|
-
const resolved =
|
|
916
|
+
const resolved = chunkISRDJR2O_cjs.resolveRecipe(recipe, { servings, system });
|
|
924
917
|
const page = typeof url === "string" ? url.replace(/#.*/s, "") : void 0;
|
|
925
918
|
const yields = [
|
|
926
919
|
...resolved.servings ? servingsText(resolved.servings) : [],
|
|
927
|
-
...resolved.yield ? [
|
|
920
|
+
...resolved.yield ? [chunkISRDJR2O_cjs.formatYield(resolved.yield, { fractions: false })] : []
|
|
928
921
|
];
|
|
929
922
|
const ingredients = resolved.ingredients.flatMap(
|
|
930
923
|
({ items }) => items.map((item) => ingredientLine(item, resolved.scale, resolved.system))
|
|
@@ -973,13 +966,13 @@ function toJsonLd(recipe, options) {
|
|
|
973
966
|
const data = {
|
|
974
967
|
...written,
|
|
975
968
|
...Object.fromEntries(
|
|
976
|
-
Object.entries(
|
|
977
|
-
([field, value]) => value !== void 0 && !
|
|
969
|
+
Object.entries(chunkISRDJR2O_cjs.isRecord(extra) ? extra : {}).filter(
|
|
970
|
+
([field, value]) => value !== void 0 && !chunkISRDJR2O_cjs.hasOwn(written, field)
|
|
978
971
|
)
|
|
979
972
|
)
|
|
980
973
|
};
|
|
981
974
|
if (data.image === void 0) {
|
|
982
|
-
|
|
975
|
+
chunkISRDJR2O_cjs.warning(
|
|
983
976
|
warnings,
|
|
984
977
|
"missing_field",
|
|
985
978
|
["image"],
|
|
@@ -987,7 +980,7 @@ function toJsonLd(recipe, options) {
|
|
|
987
980
|
);
|
|
988
981
|
}
|
|
989
982
|
if (data.nutrition !== void 0 && data.recipeYield === void 0) {
|
|
990
|
-
|
|
983
|
+
chunkISRDJR2O_cjs.warning(
|
|
991
984
|
warnings,
|
|
992
985
|
"missing_field",
|
|
993
986
|
["recipeYield"],
|
|
@@ -997,16 +990,16 @@ function toJsonLd(recipe, options) {
|
|
|
997
990
|
return { data, warnings };
|
|
998
991
|
}
|
|
999
992
|
function servingsText(servings) {
|
|
1000
|
-
const amount =
|
|
993
|
+
const amount = chunkISRDJR2O_cjs.formatServings(servings, { fractions: false });
|
|
1001
994
|
const word = servings.amount === 1 && servings.max === void 0 ? "serving" : "servings";
|
|
1002
995
|
return [amount, `${amount} ${word}`];
|
|
1003
996
|
}
|
|
1004
997
|
function ingredientLine(item, scale, system) {
|
|
1005
998
|
const { ingredient, origin } = item;
|
|
1006
|
-
const { quantity, name, note } =
|
|
999
|
+
const { quantity, name, note } = chunkISRDJR2O_cjs.formatIngredient(item);
|
|
1007
1000
|
const authored = ingredient.quantity ? [ingredient.quantity, ...ingredient.equivalents] : [];
|
|
1008
|
-
const shown = origin === "authored" ? 0 : origin === "equivalent" ? 1 + ingredient.equivalents.findIndex((q) =>
|
|
1009
|
-
const alternatives = authored.filter((_, i) => i !== shown).map((q) =>
|
|
1001
|
+
const shown = origin === "authored" ? 0 : origin === "equivalent" ? 1 + ingredient.equivalents.findIndex((q) => chunkISRDJR2O_cjs.isNative(q, system)) : -1;
|
|
1002
|
+
const alternatives = authored.filter((_, i) => i !== shown).map((q) => chunkISRDJR2O_cjs.formatQuantity(scale === 1 ? q : chunkISRDJR2O_cjs.multiply(q, scale))).join("; ");
|
|
1010
1003
|
const inParentheses = alternatives && ` (${alternatives})`;
|
|
1011
1004
|
const head = quantity === void 0 ? name : item.quantity?.unit === void 0 ? `${quantity} ${name}${inParentheses}` : `${quantity}${inParentheses} ${name}`;
|
|
1012
1005
|
return plainSpaces(
|
|
@@ -1018,11 +1011,11 @@ function duration(warnings, key, minutes) {
|
|
|
1018
1011
|
return {};
|
|
1019
1012
|
}
|
|
1020
1013
|
if (Number.isNaN(minutes) || minutes > Number.MAX_SAFE_INTEGER) {
|
|
1021
|
-
|
|
1014
|
+
chunkISRDJR2O_cjs.warning(
|
|
1022
1015
|
warnings,
|
|
1023
1016
|
"invalid_duration",
|
|
1024
1017
|
["times", key],
|
|
1025
|
-
`Expected minutes such as 30, received ${
|
|
1018
|
+
`Expected minutes such as 30, received ${chunkISRDJR2O_cjs.describeValue(minutes)}${Number.isNaN(minutes) ? "" : ", which is too long"}. It is ignored.`
|
|
1026
1019
|
);
|
|
1027
1020
|
return {};
|
|
1028
1021
|
}
|
|
@@ -1046,7 +1039,7 @@ function nutritionInformation(nutrition) {
|
|
|
1046
1039
|
for (const key of Object.keys(NUTRIENTS)) {
|
|
1047
1040
|
const value = nutrition[key];
|
|
1048
1041
|
if (value !== void 0) {
|
|
1049
|
-
information[NUTRIENTS[key]] = typeof value === "string" ? value : `${
|
|
1042
|
+
information[NUTRIENTS[key]] = typeof value === "string" ? value : `${chunkISRDJR2O_cjs.round(value, 3)} ${chunkISRDJR2O_cjs.NUTRIENT_UNITS[key]}`;
|
|
1050
1043
|
}
|
|
1051
1044
|
}
|
|
1052
1045
|
return information;
|