@recipe-book/core 0.0.3 → 0.1.1
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 +116 -0
- package/LICENSE +21 -0
- package/README.md +50 -7
- package/dist/chunk-D5CV3UF7.cjs +2754 -0
- package/dist/chunk-D5CV3UF7.cjs.map +1 -0
- package/dist/errors.js +76 -0
- package/dist/errors.js.map +1 -0
- package/dist/format/duration.js +36 -0
- package/dist/format/duration.js.map +1 -0
- package/dist/format/ingredient.js +49 -0
- package/dist/format/ingredient.js.map +1 -0
- package/dist/format/number.js +120 -0
- package/dist/format/number.js.map +1 -0
- package/dist/format/options.js +31 -0
- package/dist/format/options.js.map +1 -0
- package/dist/format/quantity.js +144 -0
- package/dist/format/quantity.js.map +1 -0
- package/dist/format/servings.js +68 -0
- package/dist/format/servings.js.map +1 -0
- package/dist/format/temperature.js +35 -0
- package/dist/format/temperature.js.map +1 -0
- package/dist/index.cjs +476 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +994 -0
- package/dist/index.d.ts +994 -5
- package/dist/index.js +48 -1
- package/dist/index.js.map +1 -0
- package/dist/ingredient/parse.js +412 -0
- package/dist/ingredient/parse.js.map +1 -0
- package/dist/issues.js +26 -0
- package/dist/issues.js.map +1 -0
- package/dist/quantity/amount.js +78 -0
- package/dist/quantity/amount.js.map +1 -0
- package/dist/quantity/parse.js +255 -0
- package/dist/quantity/parse.js.map +1 -0
- package/dist/quantity/scale.js +23 -0
- package/dist/quantity/scale.js.map +1 -0
- package/dist/recipe/duration.js +28 -0
- package/dist/recipe/duration.js.map +1 -0
- package/dist/recipe/ids.js +68 -0
- package/dist/recipe/ids.js.map +1 -0
- package/dist/recipe/infer.js +24 -0
- package/dist/recipe/infer.js.map +1 -0
- package/dist/recipe/nutrient-units.js +18 -0
- package/dist/recipe/nutrient-units.js.map +1 -0
- package/dist/recipe/nutrition.js +26 -0
- package/dist/recipe/nutrition.js.map +1 -0
- package/dist/recipe/parse.js +854 -0
- package/dist/recipe/parse.js.map +1 -0
- package/dist/recipe/schema.js +32 -0
- package/dist/recipe/schema.js.map +1 -0
- package/dist/recipe/url.js +9 -0
- package/dist/recipe/url.js.map +1 -0
- package/dist/resolve.js +120 -0
- package/dist/resolve.js.map +1 -0
- package/dist/schema-org/find.js +158 -0
- package/dist/schema-org/find.js.map +1 -0
- package/dist/schema-org/from-json-ld.js +647 -0
- package/dist/schema-org/from-json-ld.js.map +1 -0
- package/dist/schema-org/nutrients.js +19 -0
- package/dist/schema-org/nutrients.js.map +1 -0
- package/dist/schema-org/text.js +125 -0
- package/dist/schema-org/text.js.map +1 -0
- package/dist/schema-org/to-json-ld.js +151 -0
- package/dist/schema-org/to-json-ld.js.map +1 -0
- package/dist/schema-org.cjs +1062 -0
- package/dist/schema-org.cjs.map +1 -0
- package/dist/schema-org.d.cts +223 -0
- package/dist/schema-org.d.ts +223 -0
- package/dist/schema-org.js +10 -0
- package/dist/schema-org.js.map +1 -0
- package/dist/steps/segment.js +45 -0
- package/dist/steps/segment.js.map +1 -0
- package/dist/steps/temperature.js +174 -0
- package/dist/steps/temperature.js.map +1 -0
- package/dist/suggest.js +50 -0
- package/dist/suggest.js.map +1 -0
- package/dist/types-BknM8KOd.d.cts +628 -0
- package/dist/types-BknM8KOd.d.ts +628 -0
- package/dist/units/convert.js +79 -0
- package/dist/units/convert.js.map +1 -0
- package/dist/units/lookup.js +86 -0
- package/dist/units/lookup.js.map +1 -0
- package/dist/units/registry.js +183 -0
- package/dist/units/registry.js.map +1 -0
- package/dist/units/system.js +91 -0
- package/dist/units/system.js.map +1 -0
- package/dist/units/temperature.js +40 -0
- package/dist/units/temperature.js.map +1 -0
- package/dist/validation.js +90 -0
- package/dist/validation.js.map +1 -0
- package/package.json +53 -8
- package/schema-org/package.json +5 -0
- package/dist/chunk-22RBQQWH.mjs +0 -1
- package/dist/chunk-3CSP4UZG.mjs +0 -1
- package/dist/chunk-3FFMHRB7.mjs +0 -26
- package/dist/chunk-4EB3HG6B.mjs +0 -50
- package/dist/chunk-4EHNJLGI.mjs +0 -50
- package/dist/chunk-4IA5EEKI.mjs +0 -81
- package/dist/chunk-4TATADPT.mjs +0 -51
- package/dist/chunk-6GI5KLI4.mjs +0 -22
- package/dist/chunk-6QJZOZ6W.mjs +0 -49
- package/dist/chunk-6YYQ4RYZ.mjs +0 -26
- package/dist/chunk-7BBUDI2L.mjs +0 -0
- package/dist/chunk-7KEMNCV7.mjs +0 -26
- package/dist/chunk-7MMJZZ7Z.mjs +0 -75
- package/dist/chunk-BES4V7DM.mjs +0 -26
- package/dist/chunk-BRDXRIAH.mjs +0 -50
- package/dist/chunk-C45UD45A.mjs +0 -1
- package/dist/chunk-CBLJXA6P.mjs +0 -1
- package/dist/chunk-CFR2ZBPB.mjs +0 -77
- package/dist/chunk-DYMNVFL2.mjs +0 -78
- package/dist/chunk-F6AQKXJU.mjs +0 -51
- package/dist/chunk-FW4M2R43.mjs +0 -51
- package/dist/chunk-GCCEDUST.mjs +0 -75
- package/dist/chunk-GE7KBYZR.mjs +0 -26
- package/dist/chunk-GN7ZDGYC.mjs +0 -51
- package/dist/chunk-GOO2SCQX.mjs +0 -75
- package/dist/chunk-HAVKBQLH.mjs +0 -51
- package/dist/chunk-HCBIPANU.mjs +0 -50
- package/dist/chunk-IEBAGBS7.mjs +0 -51
- package/dist/chunk-IQ6WN2V4.mjs +0 -75
- package/dist/chunk-JB4Z2FR7.mjs +0 -77
- package/dist/chunk-JMTQOTBM.mjs +0 -75
- package/dist/chunk-JRO6JUES.mjs +0 -51
- package/dist/chunk-KH3SRXET.mjs +0 -52
- package/dist/chunk-KNZMCAQZ.mjs +0 -51
- package/dist/chunk-KXFUCO3R.mjs +0 -1
- package/dist/chunk-LEBGCVCJ.mjs +0 -75
- package/dist/chunk-MAHWFCIL.mjs +0 -51
- package/dist/chunk-MPH76SLC.mjs +0 -51
- package/dist/chunk-MQGMFBJQ.mjs +0 -26
- package/dist/chunk-NMIVG7T4.mjs +0 -6
- package/dist/chunk-Q3TT3AZ4.mjs +0 -26
- package/dist/chunk-QY5HJQIL.mjs +0 -51
- package/dist/chunk-RCPLSNKM.mjs +0 -1
- package/dist/chunk-SR2KFBT3.mjs +0 -1
- package/dist/chunk-ULDLBAEG.mjs +0 -1
- package/dist/chunk-UQ3EUYFR.mjs +0 -1
- package/dist/chunk-V26OCCTL.mjs +0 -82
- package/dist/chunk-WBQAMGXK.mjs +0 -0
- package/dist/chunk-WSW6FMUL.mjs +0 -51
- package/dist/chunk-WU55SBIV.mjs +0 -75
- package/dist/chunk-XINK45P3.mjs +0 -51
- package/dist/chunk-XNOHIWI3.mjs +0 -1
- package/dist/chunk-XV4QN4LA.mjs +0 -6
- package/dist/chunk-YHBXEVUX.mjs +0 -51
- package/dist/chunk-YSZSCEI7.mjs +0 -75
- package/dist/chunk-YY3SUQ7P.mjs +0 -16
- package/dist/chunk-YZB3IG47.mjs +0 -80
- package/dist/chunk-ZPZT4LMQ.mjs +0 -25
- package/dist/const/conversion.d.mts +0 -7
- package/dist/const/conversion.d.ts +0 -7
- package/dist/const/conversion.js +0 -1
- package/dist/const/conversion.mjs +0 -1
- package/dist/const/unit.d.mts +0 -119
- package/dist/const/unit.d.ts +0 -119
- package/dist/const/unit.js +0 -1
- package/dist/const/unit.mjs +0 -1
- package/dist/index.d.mts +0 -5
- package/dist/index.mjs +0 -1
- package/dist/lib/assert.d.mts +0 -18
- package/dist/lib/assert.d.ts +0 -18
- package/dist/lib/assert.js +0 -1
- package/dist/lib/assert.mjs +0 -1
- package/dist/lib/ingredient.d.mts +0 -9
- package/dist/lib/ingredient.d.ts +0 -9
- package/dist/lib/ingredient.js +0 -1
- package/dist/lib/ingredient.mjs +0 -1
- package/dist/lib/recipe.d.mts +0 -12
- package/dist/lib/recipe.d.ts +0 -12
- package/dist/lib/recipe.js +0 -1
- package/dist/lib/recipe.mjs +0 -1
- package/dist/lib/runtime.d.mts +0 -3
- package/dist/lib/runtime.d.ts +0 -3
- package/dist/lib/runtime.js +0 -1
- package/dist/lib/runtime.mjs +0 -1
- package/dist/lib/unit.d.mts +0 -19
- package/dist/lib/unit.d.ts +0 -19
- package/dist/lib/unit.js +0 -1
- package/dist/lib/unit.mjs +0 -1
- package/dist/types.d.mts +0 -36
- package/dist/types.d.ts +0 -36
- package/dist/types.js +0 -1
- package/dist/types.mjs +0 -1
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// src/format/temperature.ts
|
|
2
|
+
import { describeValue, RecipeBookError } from "../errors.js";
|
|
3
|
+
import { NBSP, pluralForm, round } from "./number.js";
|
|
4
|
+
import { option, readSettings } from "./options.js";
|
|
5
|
+
var OVEN_STEPS = { C: 10, F: 25 };
|
|
6
|
+
function formatTemperature(temperature, options) {
|
|
7
|
+
const fn = "formatTemperature";
|
|
8
|
+
const { value, unit } = temperature ?? {};
|
|
9
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
10
|
+
throw new RecipeBookError(
|
|
11
|
+
"invalid_argument",
|
|
12
|
+
`${fn}: value must be a finite number, received ${describeValue(value)}.`
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
if (unit !== "C" && unit !== "F") {
|
|
16
|
+
throw new RecipeBookError(
|
|
17
|
+
"invalid_argument",
|
|
18
|
+
`${fn}: temperature unit must be "C" or "F", received ${describeValue(unit)}.`
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
const { number, unitDisplay } = readSettings(fn, options);
|
|
22
|
+
const rounding = option(fn, "rounding", options?.rounding, [
|
|
23
|
+
"kitchen",
|
|
24
|
+
"oven",
|
|
25
|
+
"none"
|
|
26
|
+
]);
|
|
27
|
+
const digits = rounding === "none" ? 3 : 0;
|
|
28
|
+
const shown = rounding === "oven" ? round(value / OVEN_STEPS[unit], 0) * OVEN_STEPS[unit] : round(value, digits);
|
|
29
|
+
const label = unitDisplay === "short" ? `\xB0${unit}` : `${pluralForm(shown) === "one" ? "degree" : "degrees"} ${unit === "C" ? "Celsius" : "Fahrenheit"}`;
|
|
30
|
+
return `${number(shown, digits)}${NBSP}${label}`;
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
formatTemperature
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=temperature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/format/temperature.ts"],"sourcesContent":["import { describeValue, RecipeBookError } from '../errors'\nimport type { Temperature } from '../units/temperature'\nimport { NBSP, pluralForm, round } from './number'\nimport { type FormatOptions, option, readSettings } from './options'\n\nconst OVEN_STEPS = { C: 10, F: 25 } as const\n\n/** Options for {@link formatTemperature}. */\nexport type FormatTemperatureOptions = FormatOptions & {\n /**\n * `'kitchen'` (default) writes whole degrees. `'oven'` rounds to the nearest\n * 10 °C or 25 °F. `'none'` writes up to three decimals.\n */\n rounding?: 'kitchen' | 'oven' | 'none' | undefined\n}\n\n/**\n * Formats a temperature, such as \"180 °C\" or \"350 degrees Fahrenheit\". The\n * number and unit are joined by a no-break space (U+00A0).\n *\n * Rounding is `'kitchen'` by default: whole degrees. `'oven'` rounds to the\n * steps oven dials and recipes use, the nearest 10 °C or 25 °F, so a converted\n * 176.67 °C reads \"180 °C\" and 356 °F reads \"350 °F\". `'none'` writes up to\n * three decimals.\n *\n * @throws {RecipeBookError} `invalid_argument` for an invalid temperature or option.\n *\n * @example\n * formatTemperature({ value: 176.66, unit: 'C' }, { rounding: 'oven' }) // \"180 °C\"\n * formatTemperature(convertTemperature({ value: 180, unit: 'C' }, 'F'), { rounding: 'oven' }) // \"350 °F\"\n * formatTemperature({ value: 350, unit: 'F' }, { unitDisplay: 'long' }) // \"350 degrees Fahrenheit\"\n */\nexport function formatTemperature(\n temperature: Temperature,\n options?: FormatTemperatureOptions,\n): string {\n const fn = 'formatTemperature'\n const { value, unit } = temperature ?? {}\n\n if (typeof value !== 'number' || !Number.isFinite(value)) {\n throw new RecipeBookError(\n 'invalid_argument',\n `${fn}: value must be a finite number, received ${describeValue(value)}.`,\n )\n }\n if (unit !== 'C' && unit !== 'F') {\n throw new RecipeBookError(\n 'invalid_argument',\n `${fn}: temperature unit must be \"C\" or \"F\", received ${describeValue(unit)}.`,\n )\n }\n\n const { number, unitDisplay } = readSettings(fn, options)\n const rounding = option(fn, 'rounding', options?.rounding, [\n 'kitchen',\n 'oven',\n 'none',\n ])\n\n const digits = rounding === 'none' ? 3 : 0\n const shown =\n rounding === 'oven'\n ? round(value / OVEN_STEPS[unit], 0) * OVEN_STEPS[unit]\n : round(value, digits)\n const label =\n unitDisplay === 'short'\n ? `°${unit}`\n : `${pluralForm(shown) === 'one' ? 'degree' : 'degrees'} ${unit === 'C' ? 'Celsius' : 'Fahrenheit'}`\n\n return `${number(shown, digits)}${NBSP}${label}`\n}\n"],"mappings":";AAAA,SAAS,eAAe,uBAAuB;AAE/C,SAAS,MAAM,YAAY,aAAa;AACxC,SAA6B,QAAQ,oBAAoB;AAEzD,IAAM,aAAa,EAAE,GAAG,IAAI,GAAG,GAAG;AA2B3B,SAAS,kBACd,aACA,SACQ;AACR,QAAM,KAAK;AACX,QAAM,EAAE,OAAO,KAAK,IAAI,eAAe,CAAC;AAExC,MAAI,OAAO,UAAU,YAAY,CAAC,OAAO,SAAS,KAAK,GAAG;AACxD,UAAM,IAAI;AAAA,MACR;AAAA,MACA,GAAG,EAAE,6CAA6C,cAAc,KAAK,CAAC;AAAA,IACxE;AAAA,EACF;AACA,MAAI,SAAS,OAAO,SAAS,KAAK;AAChC,UAAM,IAAI;AAAA,MACR;AAAA,MACA,GAAG,EAAE,mDAAmD,cAAc,IAAI,CAAC;AAAA,IAC7E;AAAA,EACF;AAEA,QAAM,EAAE,QAAQ,YAAY,IAAI,aAAa,IAAI,OAAO;AACxD,QAAM,WAAW,OAAO,IAAI,YAAY,SAAS,UAAU;AAAA,IACzD;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAED,QAAM,SAAS,aAAa,SAAS,IAAI;AACzC,QAAM,QACJ,aAAa,SACT,MAAM,QAAQ,WAAW,IAAI,GAAG,CAAC,IAAI,WAAW,IAAI,IACpD,MAAM,OAAO,MAAM;AACzB,QAAM,QACJ,gBAAgB,UACZ,OAAI,IAAI,KACR,GAAG,WAAW,KAAK,MAAM,QAAQ,WAAW,SAAS,IAAI,SAAS,MAAM,YAAY,YAAY;AAEtG,SAAO,GAAG,OAAO,OAAO,MAAM,CAAC,GAAG,IAAI,GAAG,KAAK;AAChD;","names":[]}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,476 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkD5CV3UF7_cjs = require('./chunk-D5CV3UF7.cjs');
|
|
4
|
+
|
|
5
|
+
// src/recipe/schema.ts
|
|
6
|
+
var recipeSchema = /* @__PURE__ */ standardSchema();
|
|
7
|
+
function createRecipeSchema(options) {
|
|
8
|
+
return standardSchema(chunkD5CV3UF7_cjs.readLineOption("createRecipeSchema", options));
|
|
9
|
+
}
|
|
10
|
+
function standardSchema(readLine) {
|
|
11
|
+
const lines = readLine ?? "use createRecipeSchema({ parseIngredientLine })";
|
|
12
|
+
return {
|
|
13
|
+
"~standard": {
|
|
14
|
+
version: 1,
|
|
15
|
+
vendor: "recipe-book",
|
|
16
|
+
validate: (value) => {
|
|
17
|
+
const result = chunkD5CV3UF7_cjs.parseRecipeWith(value, lines);
|
|
18
|
+
if (result.success) {
|
|
19
|
+
return { value: result.data };
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
issues: result.error.issues.filter((issue) => issue.severity === "error").map(({ message, path }) => ({ message, path }))
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// src/units/convert.ts
|
|
30
|
+
function convert(quantity, to) {
|
|
31
|
+
const amount = chunkD5CV3UF7_cjs.checkQuantity("convert", quantity);
|
|
32
|
+
const target = chunkD5CV3UF7_cjs.getUnit(to);
|
|
33
|
+
const source = quantity.unit === void 0 ? void 0 : chunkD5CV3UF7_cjs.getUnit(quantity.unit);
|
|
34
|
+
if (source?.id === target.id) {
|
|
35
|
+
return { amount, unit: to };
|
|
36
|
+
}
|
|
37
|
+
if (source?.toBase === void 0 || target.toBase === void 0 || source.dimension !== target.dimension) {
|
|
38
|
+
throw incompatibleUnits(source, target);
|
|
39
|
+
}
|
|
40
|
+
const fromBase = source.toBase;
|
|
41
|
+
const toBase = target.toBase;
|
|
42
|
+
return {
|
|
43
|
+
amount: chunkD5CV3UF7_cjs.checkResult(
|
|
44
|
+
"convert",
|
|
45
|
+
chunkD5CV3UF7_cjs.mapAmount(amount, (value) => value * fromBase / toBase)
|
|
46
|
+
),
|
|
47
|
+
unit: to
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function canConvert(from, to) {
|
|
51
|
+
const source = chunkD5CV3UF7_cjs.lookupUnit(from);
|
|
52
|
+
const target = chunkD5CV3UF7_cjs.lookupUnit(to);
|
|
53
|
+
if (!source || !target) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
return source.id === target.id || source.toBase !== void 0 && source.dimension === target.dimension;
|
|
57
|
+
}
|
|
58
|
+
function toSystem(quantity, system) {
|
|
59
|
+
const amount = chunkD5CV3UF7_cjs.checkQuantity("toSystem", quantity);
|
|
60
|
+
chunkD5CV3UF7_cjs.checkSystem("toSystem", system);
|
|
61
|
+
const { unit } = quantity;
|
|
62
|
+
if (unit !== void 0 && !chunkD5CV3UF7_cjs.lookupUnit(unit)) {
|
|
63
|
+
throw chunkD5CV3UF7_cjs.unknownUnitError(unit);
|
|
64
|
+
}
|
|
65
|
+
const checked = { amount, unit };
|
|
66
|
+
const result = chunkD5CV3UF7_cjs.inSystem(checked, system);
|
|
67
|
+
chunkD5CV3UF7_cjs.checkResult("toSystem", result.amount);
|
|
68
|
+
return result === checked ? quantity : result;
|
|
69
|
+
}
|
|
70
|
+
function incompatibleUnits(source, target) {
|
|
71
|
+
const example = target.dimension === "mass" ? "120 g" : target.dimension === "volume" ? "250 ml" : `1 ${target.id}`;
|
|
72
|
+
const fix = `Add an equivalent to the ingredient, e.g. equivalents: ["${example}"].`;
|
|
73
|
+
if (!source) {
|
|
74
|
+
return new chunkD5CV3UF7_cjs.RecipeBookError(
|
|
75
|
+
"incompatible_units",
|
|
76
|
+
`Cannot convert a quantity without a unit to ${target.id}; a bare count such as "2 eggs" has no fixed size. ${fix}`
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
const countUnit = [source, target].find((unit) => unit.toBase === void 0);
|
|
80
|
+
if (countUnit) {
|
|
81
|
+
return new chunkD5CV3UF7_cjs.RecipeBookError(
|
|
82
|
+
"incompatible_units",
|
|
83
|
+
`Cannot convert ${source.id} to ${target.id}; ${countUnit.id} is a count unit with no fixed size. ${fix}`
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
return new chunkD5CV3UF7_cjs.RecipeBookError(
|
|
87
|
+
"incompatible_units",
|
|
88
|
+
`Cannot convert ${source.id} (${source.dimension}) to ${target.id} (${target.dimension}). ${fix}`
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// src/units/temperature.ts
|
|
93
|
+
function convertTemperature(temperature, to) {
|
|
94
|
+
const { value, unit } = temperature ?? {};
|
|
95
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
96
|
+
throw invalidArgument(
|
|
97
|
+
`value must be a finite number, received ${chunkD5CV3UF7_cjs.describeValue(value)}`
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
if (unit !== "C" && unit !== "F") {
|
|
101
|
+
throw invalidArgument(
|
|
102
|
+
`temperature unit must be "C" or "F", received ${chunkD5CV3UF7_cjs.describeValue(unit)}`
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
if (to !== "C" && to !== "F") {
|
|
106
|
+
throw invalidArgument(
|
|
107
|
+
`target unit must be "C" or "F", received ${chunkD5CV3UF7_cjs.describeValue(to)}`
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
if (unit === to) {
|
|
111
|
+
return { value, unit };
|
|
112
|
+
}
|
|
113
|
+
const result = to === "C" ? (value - 32) * 5 / 9 : value * 9 / 5 + 32;
|
|
114
|
+
if (!Number.isFinite(result)) {
|
|
115
|
+
throw invalidArgument(
|
|
116
|
+
`the result must be a finite number, but it is ${result}`
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
return { value: result, unit: to };
|
|
120
|
+
}
|
|
121
|
+
function invalidArgument(detail) {
|
|
122
|
+
return new chunkD5CV3UF7_cjs.RecipeBookError(
|
|
123
|
+
"invalid_argument",
|
|
124
|
+
`convertTemperature: ${detail}.`
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// src/format/temperature.ts
|
|
129
|
+
var OVEN_STEPS = { C: 10, F: 25 };
|
|
130
|
+
function formatTemperature(temperature, options) {
|
|
131
|
+
const fn = "formatTemperature";
|
|
132
|
+
const { value, unit } = temperature ?? {};
|
|
133
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
134
|
+
throw new chunkD5CV3UF7_cjs.RecipeBookError(
|
|
135
|
+
"invalid_argument",
|
|
136
|
+
`${fn}: value must be a finite number, received ${chunkD5CV3UF7_cjs.describeValue(value)}.`
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
if (unit !== "C" && unit !== "F") {
|
|
140
|
+
throw new chunkD5CV3UF7_cjs.RecipeBookError(
|
|
141
|
+
"invalid_argument",
|
|
142
|
+
`${fn}: temperature unit must be "C" or "F", received ${chunkD5CV3UF7_cjs.describeValue(unit)}.`
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
const { number, unitDisplay } = chunkD5CV3UF7_cjs.readSettings(fn, options);
|
|
146
|
+
const rounding = chunkD5CV3UF7_cjs.option(fn, "rounding", options?.rounding, [
|
|
147
|
+
"kitchen",
|
|
148
|
+
"oven",
|
|
149
|
+
"none"
|
|
150
|
+
]);
|
|
151
|
+
const digits = rounding === "none" ? 3 : 0;
|
|
152
|
+
const shown = rounding === "oven" ? chunkD5CV3UF7_cjs.round(value / OVEN_STEPS[unit], 0) * OVEN_STEPS[unit] : chunkD5CV3UF7_cjs.round(value, digits);
|
|
153
|
+
const label = unitDisplay === "short" ? `\xB0${unit}` : `${chunkD5CV3UF7_cjs.pluralForm(shown) === "one" ? "degree" : "degrees"} ${unit === "C" ? "Celsius" : "Fahrenheit"}`;
|
|
154
|
+
return `${number(shown, digits)}${chunkD5CV3UF7_cjs.NBSP}${label}`;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// src/format/duration.ts
|
|
158
|
+
var SHORT_LABELS = {
|
|
159
|
+
hour: "hr",
|
|
160
|
+
minute: "min",
|
|
161
|
+
second: "sec"
|
|
162
|
+
};
|
|
163
|
+
function formatDuration(minutes, options) {
|
|
164
|
+
const fn = "formatDuration";
|
|
165
|
+
if (!Number.isFinite(minutes) || minutes < 0) {
|
|
166
|
+
throw new chunkD5CV3UF7_cjs.RecipeBookError(
|
|
167
|
+
"invalid_argument",
|
|
168
|
+
`${fn}: minutes must be a finite number, 0 or more, received ${chunkD5CV3UF7_cjs.describeValue(minutes)}.`
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
const { number, unitDisplay } = chunkD5CV3UF7_cjs.readSettings(fn, options);
|
|
172
|
+
const partDay = minutes % 1440;
|
|
173
|
+
const seconds = Math.round(partDay * 60);
|
|
174
|
+
const days = Math.round((minutes - partDay) / 1440) + (seconds === 86400 ? 1 : 0);
|
|
175
|
+
const counts = [
|
|
176
|
+
["day", days],
|
|
177
|
+
["hour", Math.floor(seconds / 3600) % 24],
|
|
178
|
+
["minute", Math.floor(seconds / 60) % 60],
|
|
179
|
+
["second", seconds % 60]
|
|
180
|
+
];
|
|
181
|
+
const parts = counts.filter(([, count]) => count > 0);
|
|
182
|
+
return (parts.length > 0 ? parts : [["minute", 0]]).map(
|
|
183
|
+
([unit, count]) => `${number(count, 0)}${chunkD5CV3UF7_cjs.NBSP}${unitDisplay === "short" && SHORT_LABELS[unit] || (chunkD5CV3UF7_cjs.pluralForm(count) === "one" ? unit : `${unit}s`)}`
|
|
184
|
+
).join(" ");
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// src/steps/temperature.ts
|
|
188
|
+
var LOOKBACK = 24;
|
|
189
|
+
var MAX_ITEMS = 6;
|
|
190
|
+
var NUMBER = /(\d{1,4})(\.\d{1,2})?(?![.,]?\d)/y;
|
|
191
|
+
var DEGREES = /(?:-|\s{0,3})(?:([℃℉])|(?:[°º˚]|degrees?(?!(?!ι)[\p{sc=Latin}\p{sc=Cyrillic}\p{M}\d_]))(?:\s{0,3}(?:(cel[cs]ius|centigrade|fahrenheit|[cfс])(?!(?![ºªι])[\p{sc=Latin}\p{sc=Cyrillic}\p{M}\d_])|\(([cf])\)))?)/iuy;
|
|
192
|
+
var SCALE = /(\s{0,3})(cel[cs]ius|centigrade|fahrenheit|[cf])(?!(?![ºªι])[\p{sc=Latin}\p{sc=Cyrillic}\p{M}\d_])(?:°|\s{1,3}degrees?(?!(?!ι)[\p{sc=Latin}\p{sc=Cyrillic}\p{M}\d_]))?/iuy;
|
|
193
|
+
var FAN_AFTER = /(?:\s{1,3}|-)(?:(?:fan|convection)(?:[- ](?:forced|assisted|oven))?|umluft|hei(?:ß|ss)luft)(?!(?!ι)[\p{sc=Latin}\p{sc=Cyrillic}\p{M}\d_])/iuy;
|
|
194
|
+
var FAN_GROUP = /\s{0,3}\(\s{0,2}(?:(?:fan|convection)(?:[- ](?:forced|assisted|oven))?|umluft|hei(?:ß|ss)luft)\s{0,2}\)/iy;
|
|
195
|
+
var FAN_BEFORE = /(?:(?:fan|convection)(?:[- ](?:forced|assisted|oven))?|umluft|hei(?:ß|ss)luft)\s{1,3}/iy;
|
|
196
|
+
var FAN_PREFIX = /(?:^|ι|[^\p{sc=Latin}\p{sc=Cyrillic}\p{M}\d_])((?:(?:fan|convection)(?:[- ](?:forced|assisted|oven))?|umluft|hei(?:ß|ss)luft)\s{1,3})$/iu;
|
|
197
|
+
var GAS = /(?:gas(?:\s{1,3}mark)?|mark)\s{0,3}(?:\d{1,2}(?:[-/\u2013]\d{1,2})?|[¼½¾])(?!(?!ι)[\p{sc=Latin}\p{sc=Cyrillic}\p{M}\d_])/iuy;
|
|
198
|
+
var SEPARATOR = /\s{0,3}(?:(?:,?\s{0,3}or(?=\s)|[-/,\u2013\u2014])\s{0,3})?/iy;
|
|
199
|
+
var OPEN = /\s{0,3}\(\s{0,2}(?:(?:about|around|roughly|approx(?:imately|\.)?|ca\.|i\.e\.,?|or)\s{1,3}|[~≈]\s{0,2})?/iy;
|
|
200
|
+
var CLOSE = /\s{0,2}\)/y;
|
|
201
|
+
var OVEN_STEP = 10;
|
|
202
|
+
var SHARED = /\d\s{0,3}(?:(?:[°º˚]|degrees?)\s{0,3}\(|(?:[°º˚]|degrees?)?\s{0,3}(?:[-\u2010-\u2015~/&]|to|and|or))\s{0,3}$/i;
|
|
203
|
+
var GAS_ALTERNATIVE = /(?:gas|mark)\s{0,3}\d{1,2}\s{0,3}(?:\/|or)\s{0,3}$/i;
|
|
204
|
+
var RANGE_AFTER = /\s{0,3}(?:[-\u2010-\u2015~/&]|to|and|or)\s{0,3}-?\d/iy;
|
|
205
|
+
var NOT_A_READING = /\d[.,:]$|(?:^|ι|[^\p{sc=Latin}\p{sc=Cyrillic}\p{M}\d_])by\s{1,3}(?:(?:about|around|roughly|approximately|another|an?|further|additional|extra)\s{1,3}){0,3}$/iu;
|
|
206
|
+
var SETTING = /(?:^|ι|[^\p{sc=Latin}\p{sc=Cyrillic}\p{M}\d_])(?:at|to|of|be|is|until|oven|bake|roast|reads?|reach(?:es)?|registers?|hits?)\s{1,3}(?:(?:about|around|roughly|approximately)\s{1,3})?$/iu;
|
|
207
|
+
var OVEN_AFTER = /\s{1,3}oven(?!(?!ι)[\p{sc=Latin}\p{sc=Cyrillic}\p{M}\d_])/iuy;
|
|
208
|
+
var SIGN = /[-\u2212]/;
|
|
209
|
+
var SIGN_BEFORE = /[\s(]/;
|
|
210
|
+
var LETTER = /[a-z]/i;
|
|
211
|
+
function matchTemperature(text, digit, floor, assumed) {
|
|
212
|
+
const negative = digit > floor && SIGN.test(text[digit - 1] ?? "") && SIGN_BEFORE.test(text.charAt(digit - 2) || " ");
|
|
213
|
+
const start = negative ? digit - 1 : digit;
|
|
214
|
+
const before = text.slice(Math.max(floor, start - LOOKBACK), start);
|
|
215
|
+
if (LETTER.test(text.charAt(start - 1)) || NOT_A_READING.test(before) || SHARED.test(before) && !GAS_ALTERNATIVE.test(before)) {
|
|
216
|
+
return void 0;
|
|
217
|
+
}
|
|
218
|
+
const first = readingAt(text, digit);
|
|
219
|
+
if (!first) {
|
|
220
|
+
return void 0;
|
|
221
|
+
}
|
|
222
|
+
const prefix = FAN_PREFIX.exec(before)?.[1];
|
|
223
|
+
const unit = first.unit ?? assumed;
|
|
224
|
+
if (!unit || !first.unit && exec(RANGE_AFTER, text, first.end)) {
|
|
225
|
+
return void 0;
|
|
226
|
+
}
|
|
227
|
+
const reading = {
|
|
228
|
+
temperature: {
|
|
229
|
+
value: negative && first.value ? -first.value : first.value,
|
|
230
|
+
unit
|
|
231
|
+
},
|
|
232
|
+
fan: Boolean(prefix) || first.fan
|
|
233
|
+
};
|
|
234
|
+
const run = { readings: [reading], gas: false };
|
|
235
|
+
let end = extend(text, first.end, run);
|
|
236
|
+
if (first.cued && run.readings.length < 2 && !(prefix || SETTING.test(before) || exec(OVEN_AFTER, text, first.end))) {
|
|
237
|
+
return void 0;
|
|
238
|
+
}
|
|
239
|
+
const fanEnd = text[end - 1] === ")" && !run.readings.some(({ fan }) => fan) ? at(FAN_AFTER, text, end) : void 0;
|
|
240
|
+
if (fanEnd !== void 0) {
|
|
241
|
+
end = fanEnd;
|
|
242
|
+
for (const item of run.readings) {
|
|
243
|
+
item.fan = true;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return {
|
|
247
|
+
start: prefix ? start - prefix.length : start,
|
|
248
|
+
end,
|
|
249
|
+
reading,
|
|
250
|
+
alternatives: run.readings.slice(1)
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
function extend(text, end, run, grouped) {
|
|
254
|
+
let owner;
|
|
255
|
+
for (let count = 1; count < MAX_ITEMS; count++) {
|
|
256
|
+
run.clash = false;
|
|
257
|
+
let group;
|
|
258
|
+
if (!grouped) {
|
|
259
|
+
const { readings, gas } = run;
|
|
260
|
+
const { length } = readings;
|
|
261
|
+
const first = itemAt(text, at(OPEN, text, end), run);
|
|
262
|
+
group = first === void 0 ? void 0 : at(CLOSE, text, extend(text, first, run, true));
|
|
263
|
+
if (group !== void 0) {
|
|
264
|
+
const fanOwner = readings[length - 1];
|
|
265
|
+
for (const item of readings.slice(length)) {
|
|
266
|
+
const { unit } = item.temperature;
|
|
267
|
+
if (fanOwner?.fan && near(item.temperature, fanOwner.temperature) && !readings.some(
|
|
268
|
+
(other) => other.fan && other.temperature.unit === unit
|
|
269
|
+
)) {
|
|
270
|
+
item.fan = true;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
} else {
|
|
274
|
+
readings.length = length;
|
|
275
|
+
run.gas = gas;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
if (run.clash && owner) {
|
|
279
|
+
run.readings.length = owner[1];
|
|
280
|
+
return owner[0];
|
|
281
|
+
}
|
|
282
|
+
const size = run.readings.length;
|
|
283
|
+
const next = group ?? itemAt(text, at(SEPARATOR, text, end), run);
|
|
284
|
+
if (next === void 0) {
|
|
285
|
+
break;
|
|
286
|
+
}
|
|
287
|
+
owner = run.readings.length > size ? [end, size] : void 0;
|
|
288
|
+
end = next;
|
|
289
|
+
}
|
|
290
|
+
return end;
|
|
291
|
+
}
|
|
292
|
+
function itemAt(text, index, run) {
|
|
293
|
+
if (index === void 0) {
|
|
294
|
+
return void 0;
|
|
295
|
+
}
|
|
296
|
+
const reading = readingAt(text, index);
|
|
297
|
+
if (reading?.unit) {
|
|
298
|
+
const { value, unit, fan } = reading;
|
|
299
|
+
const temperature = { value, unit };
|
|
300
|
+
if (run.readings.some(
|
|
301
|
+
(item) => item.fan === fan && (item.temperature.unit === unit || !near(item.temperature, temperature))
|
|
302
|
+
)) {
|
|
303
|
+
run.clash = true;
|
|
304
|
+
return void 0;
|
|
305
|
+
}
|
|
306
|
+
run.readings.push({ temperature, fan });
|
|
307
|
+
return reading.end;
|
|
308
|
+
}
|
|
309
|
+
const end = run.gas ? void 0 : at(GAS, text, index);
|
|
310
|
+
if (end !== void 0) {
|
|
311
|
+
run.gas = true;
|
|
312
|
+
}
|
|
313
|
+
return end;
|
|
314
|
+
}
|
|
315
|
+
function readingAt(text, index) {
|
|
316
|
+
const marked = at(FAN_BEFORE, text, index);
|
|
317
|
+
const number = exec(NUMBER, text, marked ?? index);
|
|
318
|
+
if (!number) {
|
|
319
|
+
return void 0;
|
|
320
|
+
}
|
|
321
|
+
const [digits, integer = "", fraction] = number;
|
|
322
|
+
const after = number.index + digits.length;
|
|
323
|
+
let scale = exec(DEGREES, text, after);
|
|
324
|
+
let name = scale && (scale[1] ?? scale[2] ?? scale[3]);
|
|
325
|
+
let cups = false;
|
|
326
|
+
if (!scale) {
|
|
327
|
+
scale = exec(SCALE, text, after);
|
|
328
|
+
name = scale?.[2];
|
|
329
|
+
cups = name === "c" || name === "C" && Boolean(scale?.[1]);
|
|
330
|
+
if (!scale || name?.length === 1 && (fraction || integer.length < (cups || name === "f" ? 3 : 2))) {
|
|
331
|
+
return void 0;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
const end = scale.index + scale[0].length;
|
|
335
|
+
const fanEnd = at(FAN_AFTER, text, end) ?? at(FAN_GROUP, text, end);
|
|
336
|
+
return {
|
|
337
|
+
value: Number(digits),
|
|
338
|
+
unit: name ? /^[cс℃]/i.test(name) ? "C" : "F" : void 0,
|
|
339
|
+
fan: marked !== void 0 || fanEnd !== void 0,
|
|
340
|
+
cued: !name || cups,
|
|
341
|
+
end: fanEnd ?? end
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
function near(a, b) {
|
|
345
|
+
return Math.abs(celsius(a) - celsius(b)) <= OVEN_STEP;
|
|
346
|
+
}
|
|
347
|
+
function celsius({ value, unit }) {
|
|
348
|
+
return unit === "C" ? value : (value - 32) / 1.8;
|
|
349
|
+
}
|
|
350
|
+
function exec(pattern, text, index) {
|
|
351
|
+
pattern.lastIndex = index;
|
|
352
|
+
return pattern.exec(text);
|
|
353
|
+
}
|
|
354
|
+
function at(pattern, text, index) {
|
|
355
|
+
return exec(pattern, text, index) ? pattern.lastIndex : void 0;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// src/steps/segment.ts
|
|
359
|
+
function segmentStepText(text, options) {
|
|
360
|
+
if (typeof text !== "string") {
|
|
361
|
+
throw new chunkD5CV3UF7_cjs.RecipeBookError(
|
|
362
|
+
"invalid_argument",
|
|
363
|
+
`segmentStepText: text must be a string, received ${chunkD5CV3UF7_cjs.describeValue(text)}.`
|
|
364
|
+
);
|
|
365
|
+
}
|
|
366
|
+
const assumed = options?.assumeTemperatureUnit;
|
|
367
|
+
if (assumed !== void 0 && assumed !== "C" && assumed !== "F") {
|
|
368
|
+
throw new chunkD5CV3UF7_cjs.RecipeBookError(
|
|
369
|
+
"invalid_argument",
|
|
370
|
+
`segmentStepText: assumeTemperatureUnit must be "C" or "F", received ${chunkD5CV3UF7_cjs.describeValue(assumed)}.`
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
const segments = [];
|
|
374
|
+
const digits = /\d+/g;
|
|
375
|
+
let done = 0;
|
|
376
|
+
for (let found = digits.exec(text); found; found = digits.exec(text)) {
|
|
377
|
+
const match = matchTemperature(text, found.index, done, assumed);
|
|
378
|
+
if (!match) {
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
if (match.start > done) {
|
|
382
|
+
segments.push({ type: "text", text: text.slice(done, match.start) });
|
|
383
|
+
}
|
|
384
|
+
segments.push({
|
|
385
|
+
type: "temperature",
|
|
386
|
+
text: text.slice(match.start, match.end),
|
|
387
|
+
...match.reading,
|
|
388
|
+
alternatives: match.alternatives
|
|
389
|
+
});
|
|
390
|
+
done = digits.lastIndex = match.end;
|
|
391
|
+
}
|
|
392
|
+
if (done < text.length) {
|
|
393
|
+
segments.push({ type: "text", text: text.slice(done) });
|
|
394
|
+
}
|
|
395
|
+
return segments;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
Object.defineProperty(exports, "RecipeBookError", {
|
|
399
|
+
enumerable: true,
|
|
400
|
+
get: function () { return chunkD5CV3UF7_cjs.RecipeBookError; }
|
|
401
|
+
});
|
|
402
|
+
Object.defineProperty(exports, "RecipeValidationError", {
|
|
403
|
+
enumerable: true,
|
|
404
|
+
get: function () { return chunkD5CV3UF7_cjs.RecipeValidationError; }
|
|
405
|
+
});
|
|
406
|
+
Object.defineProperty(exports, "findUnit", {
|
|
407
|
+
enumerable: true,
|
|
408
|
+
get: function () { return chunkD5CV3UF7_cjs.findUnit; }
|
|
409
|
+
});
|
|
410
|
+
Object.defineProperty(exports, "formatIngredient", {
|
|
411
|
+
enumerable: true,
|
|
412
|
+
get: function () { return chunkD5CV3UF7_cjs.formatIngredient; }
|
|
413
|
+
});
|
|
414
|
+
Object.defineProperty(exports, "formatQuantity", {
|
|
415
|
+
enumerable: true,
|
|
416
|
+
get: function () { return chunkD5CV3UF7_cjs.formatQuantity; }
|
|
417
|
+
});
|
|
418
|
+
Object.defineProperty(exports, "formatQuantityToParts", {
|
|
419
|
+
enumerable: true,
|
|
420
|
+
get: function () { return chunkD5CV3UF7_cjs.formatQuantityToParts; }
|
|
421
|
+
});
|
|
422
|
+
Object.defineProperty(exports, "formatServings", {
|
|
423
|
+
enumerable: true,
|
|
424
|
+
get: function () { return chunkD5CV3UF7_cjs.formatServings; }
|
|
425
|
+
});
|
|
426
|
+
Object.defineProperty(exports, "formatYield", {
|
|
427
|
+
enumerable: true,
|
|
428
|
+
get: function () { return chunkD5CV3UF7_cjs.formatYield; }
|
|
429
|
+
});
|
|
430
|
+
Object.defineProperty(exports, "getUnit", {
|
|
431
|
+
enumerable: true,
|
|
432
|
+
get: function () { return chunkD5CV3UF7_cjs.getUnit; }
|
|
433
|
+
});
|
|
434
|
+
Object.defineProperty(exports, "isRecipeBookError", {
|
|
435
|
+
enumerable: true,
|
|
436
|
+
get: function () { return chunkD5CV3UF7_cjs.isRecipeBookError; }
|
|
437
|
+
});
|
|
438
|
+
Object.defineProperty(exports, "parseIngredientLine", {
|
|
439
|
+
enumerable: true,
|
|
440
|
+
get: function () { return chunkD5CV3UF7_cjs.parseIngredientLine; }
|
|
441
|
+
});
|
|
442
|
+
Object.defineProperty(exports, "parseQuantity", {
|
|
443
|
+
enumerable: true,
|
|
444
|
+
get: function () { return chunkD5CV3UF7_cjs.parseQuantity; }
|
|
445
|
+
});
|
|
446
|
+
Object.defineProperty(exports, "parseRecipe", {
|
|
447
|
+
enumerable: true,
|
|
448
|
+
get: function () { return chunkD5CV3UF7_cjs.parseRecipe; }
|
|
449
|
+
});
|
|
450
|
+
Object.defineProperty(exports, "resolveIngredient", {
|
|
451
|
+
enumerable: true,
|
|
452
|
+
get: function () { return chunkD5CV3UF7_cjs.resolveIngredient; }
|
|
453
|
+
});
|
|
454
|
+
Object.defineProperty(exports, "resolveRecipe", {
|
|
455
|
+
enumerable: true,
|
|
456
|
+
get: function () { return chunkD5CV3UF7_cjs.resolveRecipe; }
|
|
457
|
+
});
|
|
458
|
+
Object.defineProperty(exports, "scaleQuantity", {
|
|
459
|
+
enumerable: true,
|
|
460
|
+
get: function () { return chunkD5CV3UF7_cjs.scaleQuantity; }
|
|
461
|
+
});
|
|
462
|
+
Object.defineProperty(exports, "units", {
|
|
463
|
+
enumerable: true,
|
|
464
|
+
get: function () { return chunkD5CV3UF7_cjs.units; }
|
|
465
|
+
});
|
|
466
|
+
exports.canConvert = canConvert;
|
|
467
|
+
exports.convert = convert;
|
|
468
|
+
exports.convertTemperature = convertTemperature;
|
|
469
|
+
exports.createRecipeSchema = createRecipeSchema;
|
|
470
|
+
exports.formatDuration = formatDuration;
|
|
471
|
+
exports.formatTemperature = formatTemperature;
|
|
472
|
+
exports.recipeSchema = recipeSchema;
|
|
473
|
+
exports.segmentStepText = segmentStepText;
|
|
474
|
+
exports.toSystem = toSystem;
|
|
475
|
+
//# sourceMappingURL=index.cjs.map
|
|
476
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/recipe/schema.ts","../src/units/convert.ts","../src/units/temperature.ts","../src/format/temperature.ts","../src/format/duration.ts","../src/steps/temperature.ts","../src/steps/segment.ts"],"names":["readLineOption","parseRecipeWith","checkQuantity","getUnit","checkResult","mapAmount","lookupUnit","checkSystem","unknownUnitError","inSystem","RecipeBookError","describeValue","readSettings","option","round","pluralForm","NBSP"],"mappings":";;;;;AA+CO,IAAM,+BAA6C,cAAA;AAmBnD,SAAS,mBACd,OAAA,EACsB;AACtB,EAAA,OAAO,cAAA,CAAeA,gCAAA,CAAe,oBAAA,EAAsB,OAAO,CAAC,CAAA;AACrE;AAEA,SAAS,eAAe,QAAA,EAAqC;AAC3D,EAAA,MAAM,QAAQ,QAAA,IAAY,iDAAA;AAE1B,EAAA,OAAO;AAAA,IACL,WAAA,EAAa;AAAA,MACX,OAAA,EAAS,CAAA;AAAA,MACT,MAAA,EAAQ,aAAA;AAAA,MACR,QAAA,EAAU,CAAC,KAAA,KAAU;AACnB,QAAA,MAAM,MAAA,GAASC,iCAAA,CAAgB,KAAA,EAAO,KAAK,CAAA;AAE3C,QAAA,IAAI,OAAO,OAAA,EAAS;AAClB,UAAA,OAAO,EAAE,KAAA,EAAO,MAAA,CAAO,IAAA,EAAK;AAAA,QAC9B;AAEA,QAAA,OAAO;AAAA,UACL,MAAA,EAAQ,OAAO,KAAA,CAAM,MAAA,CAClB,OAAO,CAAC,KAAA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AAI,IAAA,GAAO,KAAK,MAAA,EAAQ;AACtB,IAAA,QAAA,CAAS,IAAA,CAAK,EAAE,IAAA,EAAM,MAAA,EAAQ,MAAM,IAAA,CAAK,KAAA,CAAM,IAAI,CAAA,EAAG,CAAA;AAAA,EACxD;AAEA,EAAA,OAAO,QAAA;AACT","file":"index.cjs","sourcesContent":["import type { StandardSchemaV1 } from '../standard-schema'\nimport type { RecipeInput } from './input'\nimport {\n type LineReader,\n parseRecipeWith,\n type ParseRecipeOptions,\n readLineOption,\n} from './parse'\nimport type { Recipe } from './types'\n\n/**\n * The type of {@link recipeSchema}: a Standard Schema v1 whose `validate`\n * returns its result directly, never a promise. `RecipeSchema<string>`, from\n * {@link createRecipeSchema}, also takes ingredient lines.\n */\nexport interface RecipeSchema<\n Line extends string = never,\n> extends StandardSchemaV1<RecipeInput<Line>, Recipe> {\n readonly '~standard': {\n readonly version: 1\n readonly vendor: string\n readonly validate: (\n value: unknown,\n options?: StandardSchemaV1.Options,\n ) => StandardSchemaV1.Result<Recipe>\n readonly types?:\n StandardSchemaV1.Types<RecipeInput<Line>, Recipe> | undefined\n }\n}\n\n/**\n * `parseRecipe` as a [Standard Schema](https://standardschema.dev) v1, for\n * libraries that accept one: tRPC, TanStack Form, react-hook-form, Hono, and\n * others. Validation is synchronous, so `validate` returns its result\n * directly. Only errors are reported as issues; warnings don't fail\n * validation. It reads ingredient objects only; use\n * {@link createRecipeSchema} for ingredient lines.\n *\n * @example\n * import { recipeSchema } from '@recipe-book/core'\n * import { initTRPC } from '@trpc/server'\n *\n * const t = initTRPC.create()\n * export const appRouter = t.router({\n * saveRecipe: t.procedure.input(recipeSchema).mutation(({ input }) => input.id), // input: Recipe\n * })\n */\nexport const recipeSchema: RecipeSchema = /* @__PURE__ */ standardSchema()\n\n/**\n * Makes a schema like {@link recipeSchema} that parses with `options`. Pass\n * `{ parseIngredientLine }` to accept ingredients written as text.\n *\n * @throws {RecipeBookError} `invalid_argument` when\n * `options.parseIngredientLine` is present but isn't a function.\n *\n * @example\n * import { createRecipeSchema, parseIngredientLine } from '@recipe-book/core'\n * import { initTRPC } from '@trpc/server'\n *\n * const t = initTRPC.create()\n * const recipeInput = createRecipeSchema({ parseIngredientLine })\n * export const appRouter = t.router({\n * saveRecipe: t.procedure.input(recipeInput).mutation(({ input }) => input.id), // input: Recipe\n * })\n */\nexport function createRecipeSchema(\n options: ParseRecipeOptions,\n): RecipeSchema<string> {\n return standardSchema(readLineOption('createRecipeSchema', options))\n}\n\nfunction standardSchema(readLine?: LineReader): RecipeSchema {\n const lines = readLine ?? 'use createRecipeSchema({ parseIngredientLine })'\n\n return {\n '~standard': {\n version: 1,\n vendor: 'recipe-book',\n validate: (value) => {\n const result = parseRecipeWith(value, lines)\n\n if (result.success) {\n return { value: result.data }\n }\n\n return {\n issues: result.error.issues\n .filter((issue) => issue.severity === 'error')\n .map(({ message, path }) => ({ message, path })),\n }\n },\n },\n }\n}\n","import { RecipeBookError } from '../errors'\nimport {\n checkQuantity,\n checkResult,\n mapAmount,\n type SameAmount,\n} from '../quantity/amount'\nimport type { Amount, Quantity } from '../quantity/types'\nimport { getUnit, unknownUnitError } from './lookup'\nimport {\n lookupUnit,\n type System,\n type UnitDefinition,\n type UnitId,\n} from './registry'\nimport { checkSystem, inSystem } from './system'\n\n/**\n * Converts a quantity to another unit of the same dimension. Both ends of a\n * range convert. Nothing is rounded, so the amount can be off in its last\n * digit: 5 tbsp is 14.999999999999998 tsp.\n *\n * @throws {RecipeBookError} `incompatible_units` across dimensions (cup to g),\n * between a count unit and a different unit, or for a bare count. Check with\n * {@link canConvert} first when the units come from data.\n * @throws {RecipeBookError} `unknown_unit` when either unit is not a unit id.\n * @throws {RecipeBookError} `invalid_argument` when `quantity` isn't a quantity object, the amount is not a finite number greater than 0 or a range of them, a range's `min` isn't less than its `max`, the quantity has `max` set, as a `Servings` or `Yield` has, or the result overflows to `Infinity` or underflows to 0, which only an amount above about 1e300 or below about 1e-300 can do.\n *\n * @example\n * convert({ amount: 1, unit: 'cup' }, 'ml') // { amount: 236.5882365, unit: 'ml' }\n * convert({ amount: { min: 2, max: 3 }, unit: 'tbsp' }, 'tsp') // { amount: { min: 6, max: 9 }, unit: 'tsp' }\n */\nexport function convert<A extends Amount, To extends UnitId>(\n quantity: Quantity & { amount: A },\n to: To,\n): { amount: SameAmount<A>; unit: To } {\n const amount = checkQuantity('convert', quantity)\n const target = getUnit(to)\n const source =\n quantity.unit === undefined ? undefined : getUnit(quantity.unit)\n\n if (source?.id === target.id) {\n return { amount: amount as SameAmount<A>, unit: to }\n }\n if (\n source?.toBase === undefined ||\n target.toBase === undefined ||\n source.dimension !== target.dimension\n ) {\n throw incompatibleUnits(source, target)\n }\n\n const fromBase = source.toBase\n const toBase = target.toBase\n return {\n amount: checkResult(\n 'convert',\n mapAmount(amount, (value) => (value * fromBase) / toBase),\n ) as SameAmount<A>,\n unit: to,\n }\n}\n\n/**\n * True when {@link convert} can convert between the two units: same unit, or\n * mass to mass, or volume to volume. Never throws, so it is safe on untrusted data.\n *\n * @example\n * canConvert('cup', 'ml') // true\n * canConvert('cup', 'g') // false\n * canConvert(undefined, 'g') // false: a bare count has no size\n */\nexport function canConvert(from: UnitId | undefined, to: UnitId): boolean {\n const source = lookupUnit(from)\n const target = lookupUnit(to)\n\n if (!source || !target) {\n return false\n }\n\n // Only count units lack `toBase`, so a target with the source's dimension has one.\n return (\n source.id === target.id ||\n (source.toBase !== undefined && source.dimension === target.dimension)\n )\n}\n\n/**\n * Expresses a quantity in a measurement system, choosing the display unit\n * from that system's ladder: g and kg, ml and l, oz and lb, or tsp, tbsp, and\n * cup. Nothing is rounded, so the amount can be off in its last digit, as with\n * {@link convert}.\n *\n * Returns the quantity unchanged when its unit is already native to `system`\n * (tsp and tbsp are native to both), when it is a count unit, or when it has\n * no unit.\n *\n * @throws {RecipeBookError} `invalid_argument` for an unknown system, an invalid amount, a quantity with `max` set, as a `Servings` or `Yield` has, or a result that overflows to `Infinity` or underflows to 0, which only an amount above about 1e300 or below about 1e-300 can do.\n * @throws {RecipeBookError} `unknown_unit` when the unit is not a unit id.\n *\n * @example\n * toSystem({ amount: 250, unit: 'g' }, 'us') // { amount: 8.818…, unit: 'oz' }\n * toSystem({ amount: 0.5, unit: 'cup' }, 'metric') // { amount: 118.29…, unit: 'ml' }\n * toSystem({ amount: 3, unit: 'tsp' }, 'metric') // unchanged\n */\nexport function toSystem<A extends Amount>(\n quantity: Quantity & { amount: A },\n system: System,\n): { amount: SameAmount<A>; unit?: UnitId | undefined } {\n const amount = checkQuantity('toSystem', quantity)\n checkSystem('toSystem', system)\n const { unit } = quantity\n\n if (unit !== undefined && !lookupUnit(unit)) {\n throw unknownUnitError(unit)\n }\n\n const checked = { amount, unit }\n const result = inSystem(checked, system)\n checkResult('toSystem', result.amount)\n return (result === checked ? quantity : result) as {\n amount: SameAmount<A>\n unit?: UnitId | undefined\n }\n}\n\nfunction incompatibleUnits(\n source: UnitDefinition | undefined,\n target: UnitDefinition,\n): RecipeBookError {\n const example =\n target.dimension === 'mass'\n ? '120 g'\n : target.dimension === 'volume'\n ? '250 ml'\n : `1 ${target.id}`\n const fix = `Add an equivalent to the ingredient, e.g. equivalents: [\"${example}\"].`\n\n if (!source) {\n return new RecipeBookError(\n 'incompatible_units',\n `Cannot convert a quantity without a unit to ${target.id}; a bare count such as \"2 eggs\" has no fixed size. ${fix}`,\n )\n }\n\n const countUnit = [source, target].find((unit) => unit.toBase === undefined)\n if (countUnit) {\n return new RecipeBookError(\n 'incompatible_units',\n `Cannot convert ${source.id} to ${target.id}; ${countUnit.id} is a count unit with no fixed size. ${fix}`,\n )\n }\n\n return new RecipeBookError(\n 'incompatible_units',\n `Cannot convert ${source.id} (${source.dimension}) to ${target.id} (${target.dimension}). ${fix}`,\n )\n}\n","import { describeValue, RecipeBookError } from '../errors'\n\n/** Degrees Celsius or Fahrenheit. */\nexport type TemperatureUnit = 'C' | 'F'\n\n/**\n * An oven or food temperature. Temperatures are not quantities: converting\n * them is affine, and scaling a recipe never changes them.\n */\nexport type Temperature = { value: number; unit: TemperatureUnit }\n\n/**\n * Converts a temperature between Celsius and Fahrenheit. Nothing is rounded,\n * so the value can be off in its last digits: −18 °C is\n * −0.3999999999999986 °F.\n *\n * @throws {RecipeBookError} `invalid_argument` for a non-finite value, an unknown unit, or a result that overflows to `Infinity` or `-Infinity`, which only a value beyond about ±2e307 can do.\n *\n * @example\n * convertTemperature({ value: 350, unit: 'F' }, 'C') // { value: 176.66…, unit: 'C' }\n * convertTemperature({ value: 180, unit: 'C' }, 'F') // { value: 356, unit: 'F' }\n */\nexport function convertTemperature(\n temperature: Temperature,\n to: TemperatureUnit,\n): Temperature {\n const { value, unit } = temperature ?? {}\n\n if (typeof value !== 'number' || !Number.isFinite(value)) {\n throw invalidArgument(\n `value must be a finite number, received ${describeValue(value)}`,\n )\n }\n if (unit !== 'C' && unit !== 'F') {\n throw invalidArgument(\n `temperature unit must be \"C\" or \"F\", received ${describeValue(unit)}`,\n )\n }\n if (to !== 'C' && to !== 'F') {\n throw invalidArgument(\n `target unit must be \"C\" or \"F\", received ${describeValue(to)}`,\n )\n }\n\n if (unit === to) {\n return { value, unit }\n }\n\n const result = to === 'C' ? ((value - 32) * 5) / 9 : (value * 9) / 5 + 32\n if (!Number.isFinite(result)) {\n throw invalidArgument(\n `the result must be a finite number, but it is ${result}`,\n )\n }\n return { value: result, unit: to }\n}\n\nfunction invalidArgument(detail: string): RecipeBookError {\n return new RecipeBookError(\n 'invalid_argument',\n `convertTemperature: ${detail}.`,\n )\n}\n","import { describeValue, RecipeBookError } from '../errors'\nimport type { Temperature } from '../units/temperature'\nimport { NBSP, pluralForm, round } from './number'\nimport { type FormatOptions, option, readSettings } from './options'\n\nconst OVEN_STEPS = { C: 10, F: 25 } as const\n\n/** Options for {@link formatTemperature}. */\nexport type FormatTemperatureOptions = FormatOptions & {\n /**\n * `'kitchen'` (default) writes whole degrees. `'oven'` rounds to the nearest\n * 10 °C or 25 °F. `'none'` writes up to three decimals.\n */\n rounding?: 'kitchen' | 'oven' | 'none' | undefined\n}\n\n/**\n * Formats a temperature, such as \"180 °C\" or \"350 degrees Fahrenheit\". The\n * number and unit are joined by a no-break space (U+00A0).\n *\n * Rounding is `'kitchen'` by default: whole degrees. `'oven'` rounds to the\n * steps oven dials and recipes use, the nearest 10 °C or 25 °F, so a converted\n * 176.67 °C reads \"180 °C\" and 356 °F reads \"350 °F\". `'none'` writes up to\n * three decimals.\n *\n * @throws {RecipeBookError} `invalid_argument` for an invalid temperature or option.\n *\n * @example\n * formatTemperature({ value: 176.66, unit: 'C' }, { rounding: 'oven' }) // \"180 °C\"\n * formatTemperature(convertTemperature({ value: 180, unit: 'C' }, 'F'), { rounding: 'oven' }) // \"350 °F\"\n * formatTemperature({ value: 350, unit: 'F' }, { unitDisplay: 'long' }) // \"350 degrees Fahrenheit\"\n */\nexport function formatTemperature(\n temperature: Temperature,\n options?: FormatTemperatureOptions,\n): string {\n const fn = 'formatTemperature'\n const { value, unit } = temperature ?? {}\n\n if (typeof value !== 'number' || !Number.isFinite(value)) {\n throw new RecipeBookError(\n 'invalid_argument',\n `${fn}: value must be a finite number, received ${describeValue(value)}.`,\n )\n }\n if (unit !== 'C' && unit !== 'F') {\n throw new RecipeBookError(\n 'invalid_argument',\n `${fn}: temperature unit must be \"C\" or \"F\", received ${describeValue(unit)}.`,\n )\n }\n\n const { number, unitDisplay } = readSettings(fn, options)\n const rounding = option(fn, 'rounding', options?.rounding, [\n 'kitchen',\n 'oven',\n 'none',\n ])\n\n const digits = rounding === 'none' ? 3 : 0\n const shown =\n rounding === 'oven'\n ? round(value / OVEN_STEPS[unit], 0) * OVEN_STEPS[unit]\n : round(value, digits)\n const label =\n unitDisplay === 'short'\n ? `°${unit}`\n : `${pluralForm(shown) === 'one' ? 'degree' : 'degrees'} ${unit === 'C' ? 'Celsius' : 'Fahrenheit'}`\n\n return `${number(shown, digits)}${NBSP}${label}`\n}\n","import { describeValue, RecipeBookError } from '../errors'\nimport { NBSP, pluralForm } from './number'\nimport { type FormatOptions, readSettings } from './options'\n\ntype Unit = 'day' | 'hour' | 'minute' | 'second'\n\nconst SHORT_LABELS: Partial<Record<Unit, string>> = {\n hour: 'hr',\n minute: 'min',\n second: 'sec',\n}\n\n/**\n * Formats a duration in minutes, such as a recipe's `times.cook`: \"45 min\",\n * \"1 hr 15 min\", or with `unitDisplay: 'long'`, \"1 hour 15 minutes\".\n *\n * The duration is rounded to the second and written in days, hours, minutes,\n * and seconds, leaving out zero parts. Each number and unit is joined by a\n * no-break space (U+00A0).\n *\n * @throws {RecipeBookError} `invalid_argument` when `minutes` is not a finite number, 0 or more, or for an invalid option.\n *\n * @example\n * formatDuration(75) // \"1 hr 15 min\"\n * formatDuration(1.5) // \"1 min 30 sec\"\n * formatDuration(2880, { unitDisplay: 'long' }) // \"2 days\"\n * formatDuration(0) // \"0 min\"\n */\nexport function formatDuration(\n minutes: number,\n options?: FormatOptions,\n): string {\n const fn = 'formatDuration'\n\n if (!Number.isFinite(minutes) || minutes < 0) {\n throw new RecipeBookError(\n 'invalid_argument',\n `${fn}: minutes must be a finite number, 0 or more, received ${describeValue(minutes)}.`,\n )\n }\n\n const { number, unitDisplay } = readSettings(fn, options)\n const partDay = minutes % 1440\n const seconds = Math.round(partDay * 60)\n const days =\n Math.round((minutes - partDay) / 1440) + (seconds === 86400 ? 1 : 0)\n const counts: Array<readonly [Unit, number]> = [\n ['day', days],\n ['hour', Math.floor(seconds / 3600) % 24],\n ['minute', Math.floor(seconds / 60) % 60],\n ['second', seconds % 60],\n ]\n\n const parts = counts.filter(([, count]) => count > 0)\n\n return (parts.length > 0 ? parts : ([['minute', 0]] as const))\n .map(\n ([unit, count]) =>\n `${number(count, 0)}${NBSP}${\n (unitDisplay === 'short' && SHORT_LABELS[unit]) ||\n (pluralForm(count) === 'one' ? unit : `${unit}s`)\n }`,\n )\n .join(' ')\n}\n","import type { Temperature, TemperatureUnit } from '../units/temperature'\nimport type { TemperatureReading } from './segment'\n\ntype TemperatureMatch = {\n start: number\n end: number\n reading: TemperatureReading\n alternatives: TemperatureReading[]\n}\n\ntype Reading = {\n value: number\n unit: TemperatureUnit | undefined\n fan: boolean\n /** True when it counts only after a word such as \"at\", as \"350°\" and \"180 C\" do. */\n cued: boolean\n end: number\n}\n\n/**\n * The readings in a run, first included, and whether a gas mark was among\n * them. Readings for the same kind of oven are one setting written in both\n * units, so \"350°F or 375°F\" and \"350°F or 200°C\" are separate settings.\n * `clash` is set when a reading was turned away for that reason.\n */\ntype Run = { readings: TemperatureReading[]; gas: boolean; clash?: boolean }\n\n// Every quantifier is bounded, lookbehind reads at most LOOKBACK characters,\n// and a run holds at most MAX_ITEMS items, so each call does constant work and\n// a scan stays linear in the text length.\nconst LOOKBACK = 24\nconst MAX_ITEMS = 6\n\n// The lookahead never changes a reading, since no scale starts with a digit,\n// \".\" or \",\". It's there for speed: it turns a longer number away before\n// DEGREES and SCALE are tried.\nconst NUMBER = /(\\d{1,4})(\\.\\d{1,2})?(?![.,]?\\d)/y\n// Every word boundary in this file except LETTER, below, treats a Latin or\n// Cyrillic letter, a combining mark, a digit, or \"_\" as continuing a word,\n// since those scripts write the units and separate words with spaces:\n// \"200 fèves\" isn't 200 °F. Chinese, Japanese, and Korean attach words and\n// particles straight to a number or unit, as in \"45°C/113°F的温水\" and\n// \"180°C에서\", so their letters end a word. So do Greek letters, since Greek\n// writes the unit in its own letters: \"180°Cγια\" is missing a space. So does\n// U+0345, a combining mark that only sits on a Greek vowel. Under \"/iu\" the\n// Greek iotas fold onto it and match \"\\p{M}\", so each of these boundaries\n// lets \"ι\" end a word explicitly. \"º\" and \"ª\" end a unit letter too, as in\n// \"180Cº\". The unit may be a Cyrillic \"С\", as in \"180 °С\".\nconst DEGREES =\n /(?:-|\\s{0,3})(?:([℃℉])|(?:[°º˚]|degrees?(?!(?!ι)[\\p{sc=Latin}\\p{sc=Cyrillic}\\p{M}\\d_]))(?:\\s{0,3}(?:(cel[cs]ius|centigrade|fahrenheit|[cfс])(?!(?![ºªι])[\\p{sc=Latin}\\p{sc=Cyrillic}\\p{M}\\d_])|\\(([cf])\\)))?)/iuy\nconst SCALE =\n /(\\s{0,3})(cel[cs]ius|centigrade|fahrenheit|[cf])(?!(?![ºªι])[\\p{sc=Latin}\\p{sc=Cyrillic}\\p{M}\\d_])(?:°|\\s{1,3}degrees?(?!(?!ι)[\\p{sc=Latin}\\p{sc=Cyrillic}\\p{M}\\d_]))?/iuy\nconst FAN_AFTER =\n /(?:\\s{1,3}|-)(?:(?:fan|convection)(?:[- ](?:forced|assisted|oven))?|umluft|hei(?:ß|ss)luft)(?!(?!ι)[\\p{sc=Latin}\\p{sc=Cyrillic}\\p{M}\\d_])/iuy\nconst FAN_GROUP =\n /\\s{0,3}\\(\\s{0,2}(?:(?:fan|convection)(?:[- ](?:forced|assisted|oven))?|umluft|hei(?:ß|ss)luft)\\s{0,2}\\)/iy\nconst FAN_BEFORE =\n /(?:(?:fan|convection)(?:[- ](?:forced|assisted|oven))?|umluft|hei(?:ß|ss)luft)\\s{1,3}/iy\nconst FAN_PREFIX =\n /(?:^|ι|[^\\p{sc=Latin}\\p{sc=Cyrillic}\\p{M}\\d_])((?:(?:fan|convection)(?:[- ](?:forced|assisted|oven))?|umluft|hei(?:ß|ss)luft)\\s{1,3})$/iu\nconst GAS =\n /(?:gas(?:\\s{1,3}mark)?|mark)\\s{0,3}(?:\\d{1,2}(?:[-/\\u2013]\\d{1,2})?|[¼½¾])(?!(?!ι)[\\p{sc=Latin}\\p{sc=Cyrillic}\\p{M}\\d_])/iuy\nconst SEPARATOR = /\\s{0,3}(?:(?:,?\\s{0,3}or(?=\\s)|[-/,\\u2013\\u2014])\\s{0,3})?/iy\n// A parenthesis may hedge what it restates, as in \"350°F (about 180°C)\".\nconst OPEN =\n /\\s{0,3}\\(\\s{0,2}(?:(?:about|around|roughly|approx(?:imately|\\.)?|ca\\.|i\\.e\\.,?|or)\\s{1,3}|[~≈]\\s{0,2})?/iy\nconst CLOSE = /\\s{0,2}\\)/y\n// Readings this close are one setting written in both units: 170°C is 338°F,\n// and recipes round it to 325°F or 350°F.\nconst OVEN_STEP = 10\n\n// A number that takes its scale from a later one, as 350 does in \"350–375°F\",\n// \"350 to 375 degrees F\", and \"350° (175°C)\". The later one stays text too,\n// so a converter never rewrites one end of a range.\nconst SHARED =\n /\\d\\s{0,3}(?:(?:[°º˚]|degrees?)\\s{0,3}\\(|(?:[°º˚]|degrees?)?\\s{0,3}(?:[-\\u2010-\\u2015~/&]|to|and|or))\\s{0,3}$/i\n// A gas mark before \"/\" or \"or\" has its own scale, so the 200C in\n// \"gas 6/200C\" and \"gas mark 6 or 200C\" is read. Other joiners can start a\n// range, as in \"gas 4–5\" and \"gas mark 4 to 5\", so SHARED still applies.\nconst GAS_ALTERNATIVE = /(?:gas|mark)\\s{0,3}\\d{1,2}\\s{0,3}(?:\\/|or)\\s{0,3}$/i\nconst RANGE_AFTER = /\\s{0,3}(?:[-\\u2010-\\u2015~/&]|to|and|or)\\s{0,3}-?\\d/iy\n// A number that continues another, as in \"1.5\" and \"10:30\", isn't a reading,\n// and \"Reduce the heat by 20°F\" is a difference; converting it is wrong.\nconst NOT_A_READING =\n /\\d[.,:]$|(?:^|ι|[^\\p{sc=Latin}\\p{sc=Cyrillic}\\p{M}\\d_])by\\s{1,3}(?:(?:about|around|roughly|approximately|another|an?|further|additional|extra)\\s{1,3}){0,3}$/iu\n// Words that make a bare \"350°\" or \"350 degrees\" an oven setting rather than\n// an angle, as in \"rotate the pan 180 degrees\", and \"180 C\" a temperature\n// rather than cups, as in \"add 100 c sugar\".\nconst SETTING =\n /(?:^|ι|[^\\p{sc=Latin}\\p{sc=Cyrillic}\\p{M}\\d_])(?:at|to|of|be|is|until|oven|bake|roast|reads?|reach(?:es)?|registers?|hits?)\\s{1,3}(?:(?:about|around|roughly|approximately)\\s{1,3})?$/iu\nconst OVEN_AFTER =\n /\\s{1,3}oven(?!(?!ι)[\\p{sc=Latin}\\p{sc=Cyrillic}\\p{M}\\d_])/iuy\n\nconst SIGN = /[-\\u2212]/\nconst SIGN_BEFORE = /[\\s(]/\n// ASCII only: Chinese puts numbers right after words, as in \"预热至200°C\".\nconst LETTER = /[a-z]/i\n\n/**\n * Matches a temperature, or a run of readings that state one setting several\n * ways, whose first number starts at `digit`. Text before `floor` belongs to\n * an earlier segment and is never included.\n */\nexport function matchTemperature(\n text: string,\n digit: number,\n floor: number,\n assumed: TemperatureUnit | undefined,\n): TemperatureMatch | undefined {\n // Past the start of the text, `charAt` gives '' where an index would read a\n // key set on `Object.prototype`.\n const negative =\n digit > floor &&\n SIGN.test(text[digit - 1] ?? '') &&\n SIGN_BEFORE.test(text.charAt(digit - 2) || ' ')\n const start = negative ? digit - 1 : digit\n const before = text.slice(Math.max(floor, start - LOOKBACK), start)\n if (\n LETTER.test(text.charAt(start - 1)) ||\n NOT_A_READING.test(before) ||\n (SHARED.test(before) && !GAS_ALTERNATIVE.test(before))\n ) {\n return undefined\n }\n\n const first = readingAt(text, digit)\n if (!first) {\n return undefined\n }\n\n const prefix = FAN_PREFIX.exec(before)?.[1]\n const unit = first.unit ?? assumed\n if (!unit || (!first.unit && exec(RANGE_AFTER, text, first.end))) {\n return undefined\n }\n\n const reading: TemperatureReading = {\n temperature: {\n value: negative && first.value ? -first.value : first.value,\n unit,\n },\n fan: Boolean(prefix) || first.fan,\n }\n const run: Run = { readings: [reading], gas: false }\n let end = extend(text, first.end, run)\n // A reading that needs a cue word is a temperature without one when the\n // author restated it, as in \"Oven: 180 C (350 F).\"\n if (\n first.cued &&\n run.readings.length < 2 &&\n !(prefix || SETTING.test(before) || exec(OVEN_AFTER, text, first.end))\n ) {\n return undefined\n }\n // A marker after a pair, as in \"170°C (340°F) Fan\", is for the whole pair.\n const fanEnd =\n text[end - 1] === ')' && !run.readings.some(({ fan }) => fan)\n ? at(FAN_AFTER, text, end)\n : undefined\n if (fanEnd !== undefined) {\n end = fanEnd\n for (const item of run.readings) {\n item.fan = true\n }\n }\n\n return {\n start: prefix ? start - prefix.length : start,\n end,\n reading,\n alternatives: run.readings.slice(1),\n }\n}\n\n/**\n * Adds the items that follow `end` to `run`, such as \"/170C fan\" or\n * \"(200 degrees C)\", and returns where they stop. Groups don't nest.\n */\nfunction extend(text: string, end: number, run: Run, grouped?: true): number {\n // Where the last reading after a joiner starts, and the run's size before it.\n let owner: [number, number] | undefined\n for (let count = 1; count < MAX_ITEMS; count++) {\n run.clash = false\n let group: number | undefined\n if (!grouped) {\n const { readings, gas } = run\n const { length } = readings\n const first = itemAt(text, at(OPEN, text, end), run)\n group =\n first === undefined\n ? undefined\n : at(CLOSE, text, extend(text, first, run, true))\n if (group !== undefined) {\n // An unmarked reading that restates a fan reading, as 340°F does in\n // \"170°C fan (340°F)\", is for a fan oven too.\n const fanOwner = readings[length - 1]\n for (const item of readings.slice(length)) {\n const { unit } = item.temperature\n if (\n fanOwner?.fan &&\n near(item.temperature, fanOwner.temperature) &&\n !readings.some(\n (other) => other.fan && other.temperature.unit === unit,\n )\n ) {\n item.fan = true\n }\n }\n } else {\n readings.length = length\n run.gas = gas\n }\n }\n // A parenthesis that clashes with the run restates the reading before it,\n // which is a setting of its own, as in \"190°C (375°F) or 170°C fan\n // (340°F)\", so the run ends before that reading.\n if (run.clash && owner) {\n run.readings.length = owner[1]\n return owner[0]\n }\n const size = run.readings.length\n const next = group ?? itemAt(text, at(SEPARATOR, text, end), run)\n if (next === undefined) {\n break\n }\n owner = run.readings.length > size ? [end, size] : undefined\n end = next\n }\n return end\n}\n\n/**\n * A reading with its scale that restates the run's reading for the same kind\n * of oven in the other unit, or is the first for its kind, or a gas mark when\n * the run has none yet.\n */\nfunction itemAt(\n text: string,\n index: number | undefined,\n run: Run,\n): number | undefined {\n if (index === undefined) {\n return undefined\n }\n\n const reading = readingAt(text, index)\n if (reading?.unit) {\n const { value, unit, fan } = reading\n const temperature = { value, unit }\n if (\n run.readings.some(\n (item) =>\n item.fan === fan &&\n (item.temperature.unit === unit ||\n !near(item.temperature, temperature)),\n )\n ) {\n run.clash = true\n return undefined\n }\n run.readings.push({ temperature, fan })\n return reading.end\n }\n\n const end = run.gas ? undefined : at(GAS, text, index)\n if (end !== undefined) {\n run.gas = true\n }\n return end\n}\n\n/**\n * Reads one temperature: an optional fan marker, a number, then a scale, a\n * degree sign, or the word \"degree\" or \"degrees\". `unit` is undefined when\n * only a degree sign or word says it is a temperature.\n */\nfunction readingAt(text: string, index: number): Reading | undefined {\n const marked = at(FAN_BEFORE, text, index)\n const number = exec(NUMBER, text, marked ?? index)\n if (!number) {\n return undefined\n }\n\n const [digits, integer = '', fraction] = number\n const after = number.index + digits.length\n let scale = exec(DEGREES, text, after)\n let name = scale && (scale[1] ?? scale[2] ?? scale[3])\n let cups = false\n if (!scale) {\n scale = exec(SCALE, text, after)\n name = scale?.[2]\n // A lone letter needs two digits, as in \"180C\" and \"350 F\". A C that could\n // be cups needs three digits and, to start a run, a word such as \"to\"\n // before it, so \"2C\", \"12 C bowl\", and \"add 100 c sugar\" stay text.\n cups = name === 'c' || (name === 'C' && Boolean(scale?.[1]))\n if (\n !scale ||\n (name?.length === 1 &&\n (fraction || integer.length < (cups || name === 'f' ? 3 : 2)))\n ) {\n return undefined\n }\n }\n\n const end = scale.index + scale[0].length\n const fanEnd = at(FAN_AFTER, text, end) ?? at(FAN_GROUP, text, end)\n\n return {\n value: Number(digits),\n unit: name ? (/^[cс℃]/i.test(name) ? 'C' : 'F') : undefined,\n fan: marked !== undefined || fanEnd !== undefined,\n cued: !name || cups,\n end: fanEnd ?? end,\n }\n}\n\nfunction near(a: Temperature, b: Temperature): boolean {\n return Math.abs(celsius(a) - celsius(b)) <= OVEN_STEP\n}\n\nfunction celsius({ value, unit }: Temperature): number {\n return unit === 'C' ? value : (value - 32) / 1.8\n}\n\nfunction exec(\n pattern: RegExp,\n text: string,\n index: number,\n): RegExpExecArray | null {\n pattern.lastIndex = index\n return pattern.exec(text)\n}\n\n/** Where sticky `pattern` ends when it matches at `index`. */\nfunction at(pattern: RegExp, text: string, index: number): number | undefined {\n return exec(pattern, text, index) ? pattern.lastIndex : undefined\n}\n","import { describeValue, RecipeBookError } from '../errors'\nimport type { Temperature, TemperatureUnit } from '../units/temperature'\nimport { matchTemperature } from './temperature'\n\n/** A temperature read from step text, and whether it is for a fan oven. */\nexport type TemperatureReading = {\n temperature: Temperature\n /**\n * True when the text marks it for a fan or convection oven, as in \"170C\n * fan\". A marker after a segment's closing parenthesis, as in \"170°C (about\n * 340°F) fan\", marks every reading in the segment. An unmarked reading in\n * parentheses that restates a marked one, in the other unit and within 10 °C,\n * is marked too, as in \"170°C fan (about 340°F)\". In \"160°C fan (350°F)\",\n * 350 °F is 177 °C, so it isn't. Otherwise, a marker with other words between\n * it and the reading, as in \"325°F for convection\", isn't read.\n */\n fan: boolean\n}\n\n/** Step text with nothing recognized in it. */\nexport type TextSegment = { type: 'text'; text: string }\n\n/**\n * A temperature in step text. When the author already wrote the setting more\n * than one way, as in \"400 degrees F (200 degrees C)\" or \"190C/170C fan/gas 5\",\n * the whole run is one segment: the first reading is `temperature`, the others\n * are `alternatives`, and `text` keeps any gas mark uninterpreted. Readings\n * with the same `fan` value are one setting in both units, within 10 °C of\n * each other, so no two share a unit and a `fan` value.\n */\nexport type TemperatureSegment = TemperatureReading & {\n type: 'temperature'\n /** The text exactly as authored, such as `'350°F'` or `'200C/180C fan forced'`. */\n text: string\n /** The other readings in this segment, in authored order. Often empty. */\n alternatives: TemperatureReading[]\n}\n\n/**\n * A piece of step text. Recognizes temperatures in 0.1; durations and other\n * kinds may be added in minor releases, so handle unknown `type`s as text.\n */\nexport type StepSegment = TextSegment | TemperatureSegment\n\n/** Options for {@link segmentStepText}. */\nexport type SegmentStepTextOptions = {\n /**\n * Scale for a temperature written with a degree sign or the word \"degree\" or\n * \"degrees\" but no scale, such as \"Bake at 350 degrees\", \"Bake in a\n * 350-degree oven.\" or \"Preheat oven to 350°.\" Default: none, so those stay\n * text. A number with no degree sign or word, as in \"Preheat oven to 350.\",\n * stays text even with a scale. With one, such a temperature counts only\n * after a word such as \"at\" or \"to\", before \"oven\", or when a reading in the\n * other unit restates it, as in \"350° (175°C)\", so \"rotate the pan 180\n * degrees\" stays text.\n */\n assumeTemperatureUnit?: TemperatureUnit | undefined\n}\n\n/**\n * Splits step text into plain text and the temperatures in it. Joining every\n * segment's `text` gives back the input exactly.\n *\n * @throws {RecipeBookError} `invalid_argument` for text that isn't a string or an unknown `assumeTemperatureUnit`.\n *\n * @example\n * segmentStepText('Bake at 350°F for 20 minutes.')\n * // [\n * // { type: 'text', text: 'Bake at ' },\n * // { type: 'temperature', text: '350°F', temperature: { value: 350, unit: 'F' }, fan: false, alternatives: [] },\n * // { type: 'text', text: ' for 20 minutes.' },\n * // ]\n */\nexport function segmentStepText(\n text: string,\n options?: SegmentStepTextOptions,\n): StepSegment[] {\n if (typeof text !== 'string') {\n throw new RecipeBookError(\n 'invalid_argument',\n `segmentStepText: text must be a string, received ${describeValue(text)}.`,\n )\n }\n\n const assumed = options?.assumeTemperatureUnit\n if (assumed !== undefined && assumed !== 'C' && assumed !== 'F') {\n throw new RecipeBookError(\n 'invalid_argument',\n `segmentStepText: assumeTemperatureUnit must be \"C\" or \"F\", received ${describeValue(assumed)}.`,\n )\n }\n\n const segments: StepSegment[] = []\n const digits = /\\d+/g\n let done = 0\n for (let found = digits.exec(text); found; found = digits.exec(text)) {\n const match = matchTemperature(text, found.index, done, assumed)\n if (!match) {\n continue\n }\n\n if (match.start > done) {\n segments.push({ type: 'text', text: text.slice(done, match.start) })\n }\n\n segments.push({\n type: 'temperature',\n text: text.slice(match.start, match.end),\n ...match.reading,\n alternatives: match.alternatives,\n })\n done = digits.lastIndex = match.end\n }\n\n if (done < text.length) {\n segments.push({ type: 'text', text: text.slice(done) })\n }\n\n return segments\n}\n"]}
|