@recipe-book/core 0.1.0 → 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 +103 -0
- package/README.md +1 -1
- package/dist/{chunk-VWVIBCTG.cjs → chunk-D5CV3UF7.cjs} +188 -173
- package/dist/chunk-D5CV3UF7.cjs.map +1 -0
- package/dist/errors.js.map +1 -1
- package/dist/format/number.js +1 -1
- package/dist/format/number.js.map +1 -1
- package/dist/format/options.js.map +1 -1
- package/dist/index.cjs +83 -74
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +35 -19
- package/dist/index.d.ts +35 -19
- package/dist/ingredient/parse.js +27 -22
- package/dist/ingredient/parse.js.map +1 -1
- package/dist/issues.js.map +1 -1
- package/dist/quantity/amount.js +11 -0
- package/dist/quantity/amount.js.map +1 -1
- package/dist/quantity/parse.js +58 -81
- package/dist/quantity/parse.js.map +1 -1
- package/dist/quantity/scale.js +5 -2
- package/dist/quantity/scale.js.map +1 -1
- package/dist/recipe/parse.js +70 -55
- package/dist/recipe/parse.js.map +1 -1
- package/dist/recipe/schema.js +8 -6
- package/dist/recipe/schema.js.map +1 -1
- package/dist/resolve.js +6 -1
- package/dist/resolve.js.map +1 -1
- package/dist/schema-org/find.js +46 -13
- package/dist/schema-org/find.js.map +1 -1
- package/dist/schema-org/from-json-ld.js +127 -57
- package/dist/schema-org/from-json-ld.js.map +1 -1
- package/dist/schema-org/text.js.map +1 -1
- package/dist/schema-org/to-json-ld.js +12 -15
- package/dist/schema-org/to-json-ld.js.map +1 -1
- package/dist/schema-org.cjs +231 -132
- package/dist/schema-org.cjs.map +1 -1
- package/dist/schema-org.d.cts +32 -19
- package/dist/schema-org.d.ts +32 -19
- package/dist/steps/temperature.js +13 -13
- package/dist/steps/temperature.js.map +1 -1
- package/dist/{types-DSMf45H5.d.cts → types-BknM8KOd.d.cts} +4 -3
- package/dist/{types-DSMf45H5.d.ts → types-BknM8KOd.d.ts} +4 -3
- package/dist/units/convert.js +16 -8
- package/dist/units/convert.js.map +1 -1
- package/dist/units/temperature.js +7 -1
- package/dist/units/temperature.js.map +1 -1
- package/dist/validation.js +1 -1
- package/dist/validation.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-VWVIBCTG.cjs.map +0 -1
package/dist/index.cjs.map
CHANGED
|
@@ -1 +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","parseRecipe","checkQuantity","getUnit","mapAmount","lookupUnit","checkSystem","unknownUnitError","inSystem","RecipeBookError","describeValue","readSettings","option","round","pluralForm","NBSP"],"mappings":";;;;;AA0CO,IAAM,+BAA6C,cAAA;AAmBnD,SAAS,mBACd,OAAA,EACsB;AACtB,EAAA,OAAO,cAAA,CAAe;AAAA,IACpB,mBAAA,EAAqBA,gCAAA,CAAe,oBAAA,EAAsB,OAAO;AAAA,GAClE,CAAA;AACH;AAEA,SAAS,eAAe,OAAA,EAA4C;AAClE,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,6BAAA,CAAY,KAAA,EAAO,OAAO,CAAA;AAEzC,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,KAAU,MAAM,QAAA,KAAa,OAAO,EAC5C,GAAA,CAAI,CAAC,EAAE,OAAA,EAAS,IAAA,QAAY,EAAE,OAAA,EAAS,MAAK,CAAE;AAAA,SACnD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G;AACpE,IAAA,MAAM,QAAQ,gBAAA,CAAiB,IAAA,EAAM,KAAA,CAAM,KAAA,EAAO,MAAM,OAAO,CAAA;AAC/D,IAAA,IAAI,CAAC,KAAA,EAAO;AACV,MAAA;AAAA,IACF;AAEA,IAAA,IAAI,KAAA,CAAM,QAAQ,IAAA,EAAM;AACtB,MAAA,QAAA,CAAS,IAAA,CAAK,EAAE,IAAA,EAAM,MAAA,EAAQ,IAAA,EAAM,IAAA,CAAK,KAAA,CAAM,IAAA,EAAM,KAAA,CAAM,KAAK,CAAA,EAAG,CAAA;AAAA,IACrE;AAEA,IAAA,QAAA,CAAS,IAAA,CAAK;AAAA,MACZ,IAAA,EAAM,aAAA;AAAA,MACN,MAAM,IAAA,CAAK,KAAA,CAAM,KAAA,CAAM,KAAA,EAAO,MAAM,GAAG,CAAA;AAAA,MACvC,GAAG,KAAA,CAAM,OAAA;AAAA,MACT,cAAc,KAAA,CAAM;AAAA,KACrB,CAAA;AACD,IAAA,IAAA,GAAO,MAAA,CAAO,YAAY,KAAA,CAAM,GAAA;AAAA,EAClC;AAEA,EAAA,IAAI,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 { parseRecipe, type ParseRecipeOptions, readLineOption } 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({\n parseIngredientLine: readLineOption('createRecipeSchema', options),\n })\n}\n\nfunction standardSchema(options?: ParseRecipeOptions): RecipeSchema {\n return {\n '~standard': {\n version: 1,\n vendor: 'recipe-book',\n validate: (value) => {\n const result = parseRecipe(value, options)\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 { checkQuantity, mapAmount, type SameAmount } 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`, or the quantity has `max` set, as a `Servings` or `Yield` has.\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: mapAmount(\n amount,\n (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, or a quantity with `max` set, as a `Servings` or `Yield` has.\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 checkQuantity('toSystem', quantity)\n checkSystem('toSystem', system)\n\n if (quantity.unit !== undefined && !lookupUnit(quantity.unit)) {\n throw unknownUnitError(quantity.unit)\n }\n\n return inSystem(quantity, system) 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 or an unknown unit.\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 return to === 'C'\n ? { value: ((value - 32) * 5) / 9, unit: 'C' }\n : { value: (value * 9) / 5 + 32, unit: 'F' }\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// Word boundaries are ASCII, so a scale can sit right before Chinese text, as\n// in \"45°C/113°F的温水\". The scale may be a Cyrillic \"С\", as in \"180 °С\".\nconst DEGREES =\n /(?:-|\\s{0,3})(?:([℃℉])|(?:[°º˚]|degrees?\\b)(?:\\s{0,3}(?:(cel[cs]ius|centigrade|fahrenheit|[cfс])(?!\\w)|\\(([cf])\\)))?)/iy\nconst SCALE =\n /(\\s{0,3})(cel[cs]ius|centigrade|fahrenheit|[cf])(?!\\w)(?:°|\\s{1,3}degrees?\\b)?/iy\nconst FAN_AFTER =\n /(?:\\s{1,3}|-)(?:(?:fan|convection)(?:[- ](?:forced|assisted|oven))?|umluft|hei(?:ß|ss)luft)\\b/iy\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 /\\b(?:(?:fan|convection)(?:[- ](?:forced|assisted|oven))?|umluft|hei(?:ß|ss)luft)\\s{1,3}$/i\nconst GAS =\n /(?:gas(?:\\s{1,3}mark)?|mark)\\s{0,3}(?:\\d{1,2}(?:[-/\\u2013]\\d{1,2})?|[¼½¾])(?!\\w)/iy\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[.,:]$|\\bby\\s{1,3}(?:(?:about|around|roughly|approximately|another|an?|further|additional|extra)\\s{1,3}){0,3}$/i\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 /\\b(?:at|to|of|be|is|until|oven|bake|roast|reads?|reach(?:es)?|registers?|hits?)\\s{1,3}(?:(?:about|around|roughly|approximately)\\s{1,3})?$/i\nconst OVEN_AFTER = /\\s{1,3}oven\\b/iy\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 const negative =\n digit > floor &&\n SIGN.test(text[digit - 1] ?? '') &&\n SIGN_BEFORE.test(text[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[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)?.[0]\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[1] &&\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 // A parenthesized run, such as \"(200 degrees C)\" or \"(160°C fan)\".\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[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"]}
|
|
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,i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AM,IAAA,CAAK,KAAA,CAAM,KAAA,CAAM,KAAA,EAAO,MAAM,GAAG,CAAA;AAAA,MACvC,GAAG,KAAA,CAAM,OAAA;AAAA,MACT,cAAc,KAAA,CAAM;AAAA,KACrB,CAAA;AACD,IAAA,IAAA,GAAO,MAAA,CAAO,YAAY,KAAA,CAAM,GAAA;AAAA,EAClC;AAEA,EAAA,IAAI,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"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Q as Quantity, P as ParseResult, R as Recipe, U as UnitAlias, S as System, I as Ingredient, a as Servings, Y as Yield, b as Step, A as Amount, c as Range, d as UnitId, e as UnitIdOf, f as UnitDefinition } from './types-
|
|
2
|
-
export { C as CustomTime, D as Dimension, E as Equipment, g as IngredientSection, N as Note, h as Nutrition, i as RecipeBookError, j as RecipeBookErrorCode, k as RecipeIssue, l as RecipeIssueCode, m as RecipeValidationError, n as StepSection, T as Times, V as ValidationErrorCode, o as isRecipeBookError, u as units } from './types-
|
|
1
|
+
import { Q as Quantity, P as ParseResult, R as Recipe, U as UnitAlias, S as System, I as Ingredient, a as Servings, Y as Yield, b as Step, A as Amount, c as Range, d as UnitId, e as UnitIdOf, f as UnitDefinition } from './types-BknM8KOd.cjs';
|
|
2
|
+
export { C as CustomTime, D as Dimension, E as Equipment, g as IngredientSection, N as Note, h as Nutrition, i as RecipeBookError, j as RecipeBookErrorCode, k as RecipeIssue, l as RecipeIssueCode, m as RecipeValidationError, n as StepSection, T as Times, V as ValidationErrorCode, o as isRecipeBookError, u as units } from './types-BknM8KOd.cjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* An ingredient read from a line of text. It has no `id`, so pass it through
|
|
@@ -22,11 +22,11 @@ type IngredientLine = {
|
|
|
22
22
|
* Reads a leading amount (`2`, `1–2`, `a`, `one`) and unit, and a second
|
|
23
23
|
* measure in parentheses that hold nothing but measures, or after a slash or
|
|
24
24
|
* semicolon, as `equivalents`. With no amount, a unit before "of" reads as 1
|
|
25
|
-
* when it starts the line, after any leading "optional" and
|
|
26
|
-
*
|
|
27
|
-
* `quantity: { amount: 1, unit: '
|
|
28
|
-
* `'
|
|
29
|
-
* none. With no
|
|
25
|
+
* when it starts the line, after any leading "optional" and any space or
|
|
26
|
+
* colon, or "(optional)" and any space, and after any size word such as
|
|
27
|
+
* "big", so `'tsp. of salt'` gets `quantity: { amount: 1, unit: 'tsp' }` and
|
|
28
|
+
* `'big pinch of salt'` gets `quantity: { amount: 1, unit: 'pinch' }` and
|
|
29
|
+
* `note: 'big'`, but `'Optional - pinch of salt'` gets none. With no
|
|
30
30
|
* leading amount or unit, the first measure in parentheses that hold nothing
|
|
31
31
|
* but measures is the `quantity` instead, so `'Butter (100g)'` gets
|
|
32
32
|
* `quantity: { amount: 100, unit: 'g' }`. Measures after a leading "optional"
|
|
@@ -37,6 +37,17 @@ type IngredientLine = {
|
|
|
37
37
|
* In parentheses, any other sum (across dimensions, in count units such as
|
|
38
38
|
* "pinch", or of three measures) makes every measure in them part of the note
|
|
39
39
|
* (`'1 cup (8 oz + 1 tbsp) milk'`).
|
|
40
|
+
* With no leading amount or unit, an amount and unit after the name and a
|
|
41
|
+
* colon are read when nothing else follows but a note after a comma, so
|
|
42
|
+
* `'nagaimo: 160 g, grated'` gets `name: 'nagaimo'`,
|
|
43
|
+
* `quantity: { amount: 160, unit: 'g' }` and `note: 'grated'`. A name with a
|
|
44
|
+
* digit, or that starts with the word "for", "to", "a", "an", "yield",
|
|
45
|
+
* "yields" or "total", isn't read that way, and neither is one that is just
|
|
46
|
+
* "makes", "serves", "serving", "servings", "serving size", "protein",
|
|
47
|
+
* "carbs", "carbohydrate", "carbohydrates", "fiber", "fibre", "sodium",
|
|
48
|
+
* "cholesterol", "saturated fat" or "fat". So `'For the sauce: 1 cup'` and
|
|
49
|
+
* `'Protein: 12 g'` keep the whole line as the name, but
|
|
50
|
+
* `'Protein powder: 30 g'` gets `name: 'Protein powder'`.
|
|
40
51
|
* It also reads a note after the first comma outside parentheses that doesn't
|
|
41
52
|
* follow "boneless" or "skinless", phrases such as "to taste", and "optional"
|
|
42
53
|
* at the start of the line or of text in parentheses (the innermost when they
|
|
@@ -445,7 +456,7 @@ type QuantityOrigin = 'authored' | 'equivalent' | 'converted';
|
|
|
445
456
|
/** An ingredient, scaled and expressed in the display system. */
|
|
446
457
|
type ResolvedIngredient = {
|
|
447
458
|
id: string;
|
|
448
|
-
/** The ingredient as authored, unscaled. */
|
|
459
|
+
/** The ingredient as authored, unscaled, not a copy; treat it as read-only. */
|
|
449
460
|
ingredient: Ingredient;
|
|
450
461
|
/**
|
|
451
462
|
* Absent for unquantified ingredients, such as "salt, to taste". May be the
|
|
@@ -457,6 +468,7 @@ type ResolvedIngredient = {
|
|
|
457
468
|
};
|
|
458
469
|
/** What {@link resolveRecipe} returns: the recipe at a scale, in one system, unrounded. */
|
|
459
470
|
type ResolvedRecipe = {
|
|
471
|
+
/** The recipe passed in, not a copy; treat it as read-only. */
|
|
460
472
|
recipe: Recipe;
|
|
461
473
|
/**
|
|
462
474
|
* The `scale` option, else `servings` divided by the scaling base. Always
|
|
@@ -500,9 +512,9 @@ type ResolvedRecipe = {
|
|
|
500
512
|
type ResolveRecipeOptions = {
|
|
501
513
|
/**
|
|
502
514
|
* Scales by `servings / base`, where the base is the recipe's servings
|
|
503
|
-
* amount, else its yield amount, else 1. Defaults to the base. A value
|
|
504
|
-
*
|
|
505
|
-
*
|
|
515
|
+
* amount, else its yield amount, else 1. Defaults to the base. A value
|
|
516
|
+
* outside a millionth to a million times the base, or that isn't a number,
|
|
517
|
+
* also uses the default.
|
|
506
518
|
*/
|
|
507
519
|
servings?: number | undefined;
|
|
508
520
|
/**
|
|
@@ -574,6 +586,8 @@ type SameAmount<A extends Amount> = A extends number ? number : Range;
|
|
|
574
586
|
* not a finite number greater than 0 or a range of them, a range's `min`
|
|
575
587
|
* isn't less than its `max`, or the quantity has `max` set, as a `Servings`
|
|
576
588
|
* or `Yield` has. `resolveRecipe` scales those. The unit isn't checked.
|
|
589
|
+
* Also thrown when an end times `factor` overflows to `Infinity` or
|
|
590
|
+
* underflows to 0: past about 1.8e308, or below about 5e-324.
|
|
577
591
|
*
|
|
578
592
|
* @example
|
|
579
593
|
* scaleQuantity({ amount: 1.5, unit: 'cup' }, 2) // { amount: 3, unit: 'cup' }
|
|
@@ -595,7 +609,7 @@ declare function scaleQuantity<A extends Amount>(quantity: Quantity & {
|
|
|
595
609
|
* between a count unit and a different unit, or for a bare count. Check with
|
|
596
610
|
* {@link canConvert} first when the units come from data.
|
|
597
611
|
* @throws {RecipeBookError} `unknown_unit` when either unit is not a unit id.
|
|
598
|
-
* @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`,
|
|
612
|
+
* @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.
|
|
599
613
|
*
|
|
600
614
|
* @example
|
|
601
615
|
* convert({ amount: 1, unit: 'cup' }, 'ml') // { amount: 236.5882365, unit: 'ml' }
|
|
@@ -627,7 +641,7 @@ declare function canConvert(from: UnitId | undefined, to: UnitId): boolean;
|
|
|
627
641
|
* (tsp and tbsp are native to both), when it is a count unit, or when it has
|
|
628
642
|
* no unit.
|
|
629
643
|
*
|
|
630
|
-
* @throws {RecipeBookError} `invalid_argument` for an unknown system, an invalid amount,
|
|
644
|
+
* @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.
|
|
631
645
|
* @throws {RecipeBookError} `unknown_unit` when the unit is not a unit id.
|
|
632
646
|
*
|
|
633
647
|
* @example
|
|
@@ -685,7 +699,7 @@ type Temperature = {
|
|
|
685
699
|
* so the value can be off in its last digits: −18 °C is
|
|
686
700
|
* −0.3999999999999986 °F.
|
|
687
701
|
*
|
|
688
|
-
* @throws {RecipeBookError} `invalid_argument` for a non-finite value
|
|
702
|
+
* @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.
|
|
689
703
|
*
|
|
690
704
|
* @example
|
|
691
705
|
* convertTemperature({ value: 350, unit: 'F' }, 'C') // { value: 176.66…, unit: 'C' }
|
|
@@ -699,11 +713,13 @@ declare function convertTemperature(temperature: Temperature, to: TemperatureUni
|
|
|
699
713
|
*/
|
|
700
714
|
type FormatOptions = {
|
|
701
715
|
/**
|
|
702
|
-
*
|
|
703
|
-
* 0.1; only numbers follow the locale, and they
|
|
704
|
-
* in other languages come from the runtime's
|
|
705
|
-
*
|
|
706
|
-
* runtime doesn't support falls back to
|
|
716
|
+
* A language tag that `Intl` accepts, such as `'en-US'`, the default. Labels
|
|
717
|
+
* and plurals are English in 0.1; only numbers follow the locale, and they
|
|
718
|
+
* are never grouped. Numbers in other languages come from the runtime's
|
|
719
|
+
* `Intl` data, so the server and client need the same locale support to
|
|
720
|
+
* render the same text. A locale the runtime doesn't support falls back to
|
|
721
|
+
* English, but a string `Intl` rejects throws. `Intl` rejects `'en_US'`, and
|
|
722
|
+
* some BCP 47 tags too, such as `'i-klingon'` and `'x-private'`.
|
|
707
723
|
*/
|
|
708
724
|
locale?: string | undefined;
|
|
709
725
|
/** `'short'` (`tbsp`) or `'long'` (`tablespoons`). Default `'short'`. */
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Q as Quantity, P as ParseResult, R as Recipe, U as UnitAlias, S as System, I as Ingredient, a as Servings, Y as Yield, b as Step, A as Amount, c as Range, d as UnitId, e as UnitIdOf, f as UnitDefinition } from './types-
|
|
2
|
-
export { C as CustomTime, D as Dimension, E as Equipment, g as IngredientSection, N as Note, h as Nutrition, i as RecipeBookError, j as RecipeBookErrorCode, k as RecipeIssue, l as RecipeIssueCode, m as RecipeValidationError, n as StepSection, T as Times, V as ValidationErrorCode, o as isRecipeBookError, u as units } from './types-
|
|
1
|
+
import { Q as Quantity, P as ParseResult, R as Recipe, U as UnitAlias, S as System, I as Ingredient, a as Servings, Y as Yield, b as Step, A as Amount, c as Range, d as UnitId, e as UnitIdOf, f as UnitDefinition } from './types-BknM8KOd.js';
|
|
2
|
+
export { C as CustomTime, D as Dimension, E as Equipment, g as IngredientSection, N as Note, h as Nutrition, i as RecipeBookError, j as RecipeBookErrorCode, k as RecipeIssue, l as RecipeIssueCode, m as RecipeValidationError, n as StepSection, T as Times, V as ValidationErrorCode, o as isRecipeBookError, u as units } from './types-BknM8KOd.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* An ingredient read from a line of text. It has no `id`, so pass it through
|
|
@@ -22,11 +22,11 @@ type IngredientLine = {
|
|
|
22
22
|
* Reads a leading amount (`2`, `1–2`, `a`, `one`) and unit, and a second
|
|
23
23
|
* measure in parentheses that hold nothing but measures, or after a slash or
|
|
24
24
|
* semicolon, as `equivalents`. With no amount, a unit before "of" reads as 1
|
|
25
|
-
* when it starts the line, after any leading "optional" and
|
|
26
|
-
*
|
|
27
|
-
* `quantity: { amount: 1, unit: '
|
|
28
|
-
* `'
|
|
29
|
-
* none. With no
|
|
25
|
+
* when it starts the line, after any leading "optional" and any space or
|
|
26
|
+
* colon, or "(optional)" and any space, and after any size word such as
|
|
27
|
+
* "big", so `'tsp. of salt'` gets `quantity: { amount: 1, unit: 'tsp' }` and
|
|
28
|
+
* `'big pinch of salt'` gets `quantity: { amount: 1, unit: 'pinch' }` and
|
|
29
|
+
* `note: 'big'`, but `'Optional - pinch of salt'` gets none. With no
|
|
30
30
|
* leading amount or unit, the first measure in parentheses that hold nothing
|
|
31
31
|
* but measures is the `quantity` instead, so `'Butter (100g)'` gets
|
|
32
32
|
* `quantity: { amount: 100, unit: 'g' }`. Measures after a leading "optional"
|
|
@@ -37,6 +37,17 @@ type IngredientLine = {
|
|
|
37
37
|
* In parentheses, any other sum (across dimensions, in count units such as
|
|
38
38
|
* "pinch", or of three measures) makes every measure in them part of the note
|
|
39
39
|
* (`'1 cup (8 oz + 1 tbsp) milk'`).
|
|
40
|
+
* With no leading amount or unit, an amount and unit after the name and a
|
|
41
|
+
* colon are read when nothing else follows but a note after a comma, so
|
|
42
|
+
* `'nagaimo: 160 g, grated'` gets `name: 'nagaimo'`,
|
|
43
|
+
* `quantity: { amount: 160, unit: 'g' }` and `note: 'grated'`. A name with a
|
|
44
|
+
* digit, or that starts with the word "for", "to", "a", "an", "yield",
|
|
45
|
+
* "yields" or "total", isn't read that way, and neither is one that is just
|
|
46
|
+
* "makes", "serves", "serving", "servings", "serving size", "protein",
|
|
47
|
+
* "carbs", "carbohydrate", "carbohydrates", "fiber", "fibre", "sodium",
|
|
48
|
+
* "cholesterol", "saturated fat" or "fat". So `'For the sauce: 1 cup'` and
|
|
49
|
+
* `'Protein: 12 g'` keep the whole line as the name, but
|
|
50
|
+
* `'Protein powder: 30 g'` gets `name: 'Protein powder'`.
|
|
40
51
|
* It also reads a note after the first comma outside parentheses that doesn't
|
|
41
52
|
* follow "boneless" or "skinless", phrases such as "to taste", and "optional"
|
|
42
53
|
* at the start of the line or of text in parentheses (the innermost when they
|
|
@@ -445,7 +456,7 @@ type QuantityOrigin = 'authored' | 'equivalent' | 'converted';
|
|
|
445
456
|
/** An ingredient, scaled and expressed in the display system. */
|
|
446
457
|
type ResolvedIngredient = {
|
|
447
458
|
id: string;
|
|
448
|
-
/** The ingredient as authored, unscaled. */
|
|
459
|
+
/** The ingredient as authored, unscaled, not a copy; treat it as read-only. */
|
|
449
460
|
ingredient: Ingredient;
|
|
450
461
|
/**
|
|
451
462
|
* Absent for unquantified ingredients, such as "salt, to taste". May be the
|
|
@@ -457,6 +468,7 @@ type ResolvedIngredient = {
|
|
|
457
468
|
};
|
|
458
469
|
/** What {@link resolveRecipe} returns: the recipe at a scale, in one system, unrounded. */
|
|
459
470
|
type ResolvedRecipe = {
|
|
471
|
+
/** The recipe passed in, not a copy; treat it as read-only. */
|
|
460
472
|
recipe: Recipe;
|
|
461
473
|
/**
|
|
462
474
|
* The `scale` option, else `servings` divided by the scaling base. Always
|
|
@@ -500,9 +512,9 @@ type ResolvedRecipe = {
|
|
|
500
512
|
type ResolveRecipeOptions = {
|
|
501
513
|
/**
|
|
502
514
|
* Scales by `servings / base`, where the base is the recipe's servings
|
|
503
|
-
* amount, else its yield amount, else 1. Defaults to the base. A value
|
|
504
|
-
*
|
|
505
|
-
*
|
|
515
|
+
* amount, else its yield amount, else 1. Defaults to the base. A value
|
|
516
|
+
* outside a millionth to a million times the base, or that isn't a number,
|
|
517
|
+
* also uses the default.
|
|
506
518
|
*/
|
|
507
519
|
servings?: number | undefined;
|
|
508
520
|
/**
|
|
@@ -574,6 +586,8 @@ type SameAmount<A extends Amount> = A extends number ? number : Range;
|
|
|
574
586
|
* not a finite number greater than 0 or a range of them, a range's `min`
|
|
575
587
|
* isn't less than its `max`, or the quantity has `max` set, as a `Servings`
|
|
576
588
|
* or `Yield` has. `resolveRecipe` scales those. The unit isn't checked.
|
|
589
|
+
* Also thrown when an end times `factor` overflows to `Infinity` or
|
|
590
|
+
* underflows to 0: past about 1.8e308, or below about 5e-324.
|
|
577
591
|
*
|
|
578
592
|
* @example
|
|
579
593
|
* scaleQuantity({ amount: 1.5, unit: 'cup' }, 2) // { amount: 3, unit: 'cup' }
|
|
@@ -595,7 +609,7 @@ declare function scaleQuantity<A extends Amount>(quantity: Quantity & {
|
|
|
595
609
|
* between a count unit and a different unit, or for a bare count. Check with
|
|
596
610
|
* {@link canConvert} first when the units come from data.
|
|
597
611
|
* @throws {RecipeBookError} `unknown_unit` when either unit is not a unit id.
|
|
598
|
-
* @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`,
|
|
612
|
+
* @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.
|
|
599
613
|
*
|
|
600
614
|
* @example
|
|
601
615
|
* convert({ amount: 1, unit: 'cup' }, 'ml') // { amount: 236.5882365, unit: 'ml' }
|
|
@@ -627,7 +641,7 @@ declare function canConvert(from: UnitId | undefined, to: UnitId): boolean;
|
|
|
627
641
|
* (tsp and tbsp are native to both), when it is a count unit, or when it has
|
|
628
642
|
* no unit.
|
|
629
643
|
*
|
|
630
|
-
* @throws {RecipeBookError} `invalid_argument` for an unknown system, an invalid amount,
|
|
644
|
+
* @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.
|
|
631
645
|
* @throws {RecipeBookError} `unknown_unit` when the unit is not a unit id.
|
|
632
646
|
*
|
|
633
647
|
* @example
|
|
@@ -685,7 +699,7 @@ type Temperature = {
|
|
|
685
699
|
* so the value can be off in its last digits: −18 °C is
|
|
686
700
|
* −0.3999999999999986 °F.
|
|
687
701
|
*
|
|
688
|
-
* @throws {RecipeBookError} `invalid_argument` for a non-finite value
|
|
702
|
+
* @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.
|
|
689
703
|
*
|
|
690
704
|
* @example
|
|
691
705
|
* convertTemperature({ value: 350, unit: 'F' }, 'C') // { value: 176.66…, unit: 'C' }
|
|
@@ -699,11 +713,13 @@ declare function convertTemperature(temperature: Temperature, to: TemperatureUni
|
|
|
699
713
|
*/
|
|
700
714
|
type FormatOptions = {
|
|
701
715
|
/**
|
|
702
|
-
*
|
|
703
|
-
* 0.1; only numbers follow the locale, and they
|
|
704
|
-
* in other languages come from the runtime's
|
|
705
|
-
*
|
|
706
|
-
* runtime doesn't support falls back to
|
|
716
|
+
* A language tag that `Intl` accepts, such as `'en-US'`, the default. Labels
|
|
717
|
+
* and plurals are English in 0.1; only numbers follow the locale, and they
|
|
718
|
+
* are never grouped. Numbers in other languages come from the runtime's
|
|
719
|
+
* `Intl` data, so the server and client need the same locale support to
|
|
720
|
+
* render the same text. A locale the runtime doesn't support falls back to
|
|
721
|
+
* English, but a string `Intl` rejects throws. `Intl` rejects `'en_US'`, and
|
|
722
|
+
* some BCP 47 tags too, such as `'i-klingon'` and `'x-private'`.
|
|
707
723
|
*/
|
|
708
724
|
locale?: string | undefined;
|
|
709
725
|
/** `'short'` (`tbsp`) or `'long'` (`tablespoons`). Default `'short'`. */
|
package/dist/ingredient/parse.js
CHANGED
|
@@ -16,16 +16,16 @@ var ABOUT = /(about|approx(?:imately|\.)?) /iy;
|
|
|
16
16
|
var PHRASE = /((?:an? )?(?:handful|few|couple|little|splash|drizzle|knob|squeeze|sprinkle|dollop))(?: of)? /iy;
|
|
17
17
|
var HYPHENATED_MIXED = /^(\d+)-(?=(\d+)[/⁄](\d+)(?![\d/⁄]))/;
|
|
18
18
|
var AMOUNT_CHARS = /(?:an? )?(?:[\d .,/⁄¼-¾⅐-⅞–—-]|to )*/iy;
|
|
19
|
-
var UNIT_OF = /([a-z]+) of /iy;
|
|
20
19
|
var TIMES = / ?[x×] ?(?=\d)/iy;
|
|
21
|
-
var UNREAD = / ?(?:(?:or|to|and|plus|half)\
|
|
20
|
+
var UNREAD = / ?(?:(?:or|to|and|plus|half)(?![\p{L}\p{M}\d_])|[-–—/+&]|\d+(?:\.\d+)?(?= |$))/iuy;
|
|
22
21
|
var UNREAD_AFTER_UNIT = / (?:or|to|[-–—&])(?= )|[-–—+&](?=\d)/iy;
|
|
23
22
|
var PAREN = / ?\(([^()]*)\)/y;
|
|
24
23
|
var PARENS = / ?\(([^()]*)\)/g;
|
|
25
24
|
var MODIFIER = / ?(heaping|heaped|level|scant|rounded|generous|good|small|medium|large|big)(?= )/iy;
|
|
26
|
-
var JOIN = /(?: (plus|and|\+)(?![
|
|
25
|
+
var JOIN = /(?: (plus|and|\+)(?![\p{L}\p{M}]))? ?/iuy;
|
|
27
26
|
var SEPARATOR = / ?[;/] ?/y;
|
|
28
27
|
var OF = / ?of(?: (?:an?|the))?(?= |$)/iy;
|
|
28
|
+
var NAMED = /(?!(?:for|to|an?|yields?|total)(?![\p{L}\p{M}\d_])|(?:makes|serv(?:es|ings?)(?: size)?|protein|carbs|carbohydrates?|fiber|fibre|sodium|cholesterol|saturated fat|fat) ?:)([^\d:]+):/iuy;
|
|
29
29
|
var PHRASE_NOTE = / (?=to taste|as needed|as required|plus more|plus extra|or more|or to taste|for (?:serving|garnish|dusting|greasing|frying|drizzling|decoration))/i;
|
|
30
30
|
var OPTIONAL_NOTE = /(?:^|,) ?optional(?= ?(?:,|$))/gi;
|
|
31
31
|
var OPTIONAL_PAREN = /^optional\b[,;:]? ?/i;
|
|
@@ -144,11 +144,22 @@ function readLine(line) {
|
|
|
144
144
|
if (found) {
|
|
145
145
|
;
|
|
146
146
|
[amount, i] = found;
|
|
147
|
-
} else
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
147
|
+
} else {
|
|
148
|
+
const modifier = exec(MODIFIER, line, i);
|
|
149
|
+
const unit = readUnit(line, modifier ? MODIFIER.lastIndex : i);
|
|
150
|
+
if (unit && exec(OF, line, unit[1])) {
|
|
151
|
+
if (modifier) {
|
|
152
|
+
addNote(modifier[1]);
|
|
153
|
+
}
|
|
154
|
+
quantity = { amount: 1, unit: unit[0] };
|
|
155
|
+
i = unit[1];
|
|
156
|
+
} else if (match = exec(NAMED, line, i)) {
|
|
157
|
+
const measure = readMeasure(line, NAMED.lastIndex, false);
|
|
158
|
+
if (measure && (line[measure[1]] ?? ",") === ",") {
|
|
159
|
+
quantity = measure[0];
|
|
160
|
+
line = match[1] + line.slice(measure[1]);
|
|
161
|
+
i = 0;
|
|
162
|
+
}
|
|
152
163
|
}
|
|
153
164
|
}
|
|
154
165
|
}
|
|
@@ -283,7 +294,7 @@ function readUnit(text, start) {
|
|
|
283
294
|
const { twoWordUnit, unit } = getPatterns();
|
|
284
295
|
for (const pattern of [twoWordUnit, unit]) {
|
|
285
296
|
const match = exec(pattern, text, start);
|
|
286
|
-
const id = match && findUnit(match
|
|
297
|
+
const id = match && findUnit(match.slice(1).join(" "));
|
|
287
298
|
if (id) {
|
|
288
299
|
return [id, pattern.lastIndex];
|
|
289
300
|
}
|
|
@@ -381,7 +392,13 @@ function countForms(name, many) {
|
|
|
381
392
|
k = CONTAINER.test(words[0]) ? 0 : words.length - 1;
|
|
382
393
|
}
|
|
383
394
|
const word = words[k];
|
|
384
|
-
const other = many ?
|
|
395
|
+
const other = many ? word.replace(
|
|
396
|
+
/(?:(lea|hal|loa)ves|([rtdv])ies|(o|ch|sh|x|ss|chill?i)es|([^su])s)$/i,
|
|
397
|
+
(_, f, y, es, s) => f ? `${f}f` : y ? `${y}y` : es ?? s
|
|
398
|
+
) : word.replace(
|
|
399
|
+
/(?:(lea|hal|loa)f|([^aeiou])y|(ch|sh|x|z|tomato|potato|mango|chill?i)|[a-rt-z])$/i,
|
|
400
|
+
(match, f, y, es) => f ? `${f}ves` : y ? `${y}ies` : es ? `${es}es` : `${match}s`
|
|
401
|
+
);
|
|
385
402
|
if (other === word) {
|
|
386
403
|
return [name, void 0];
|
|
387
404
|
}
|
|
@@ -389,18 +406,6 @@ function countForms(name, many) {
|
|
|
389
406
|
const swapped = words.join(" ");
|
|
390
407
|
return many ? [swapped, name] : [name, swapped];
|
|
391
408
|
}
|
|
392
|
-
function singular(word) {
|
|
393
|
-
return word.replace(
|
|
394
|
-
/(?:(lea|hal|loa)ves|([rtdv])ies|(o|ch|sh|x|ss|chill?i)es|([^su])s)$/i,
|
|
395
|
-
(_, f, y, es, s) => f ? `${f}f` : y ? `${y}y` : es ?? s
|
|
396
|
-
);
|
|
397
|
-
}
|
|
398
|
-
function pluralize(word) {
|
|
399
|
-
return word.replace(
|
|
400
|
-
/(?:(lea|hal|loa)f|([^aeiou])y|(ch|sh|x|z|tomato|potato|mango|chill?i)|[a-rt-z])$/i,
|
|
401
|
-
(match, f, y, es) => f ? `${f}ves` : y ? `${y}ies` : es ? `${es}es` : `${match}s`
|
|
402
|
-
);
|
|
403
|
-
}
|
|
404
409
|
export {
|
|
405
410
|
parseIngredientLine
|
|
406
411
|
};
|