64 lines
2.7 KiB
TypeScript
64 lines
2.7 KiB
TypeScript
// This Code is auto generated by gen_ts_unit_systems.py
|
|
export type UnitDimension = "mass" | "volume";
|
|
|
|
export type UnitSystem = "metric" | "us";
|
|
|
|
export interface StandardizedUnit {
|
|
dimension: UnitDimension;
|
|
/** How many base units (grams for mass, millilitres for volume) are in one of this unit. */
|
|
base: number;
|
|
/** Customary rather than metric, so a recipe using it is already in a customary system. */
|
|
customary: boolean;
|
|
}
|
|
|
|
export interface UnitRung {
|
|
/** The pint unit name. */
|
|
unit: string;
|
|
/** Key into the seeded unit names merged into i18n messages under `unit-names`. */
|
|
seedKey: string;
|
|
base: number;
|
|
/** Whole units needed before this rung takes over from the one below it. */
|
|
takeover: number;
|
|
fraction: boolean;
|
|
}
|
|
|
|
export const STANDARDIZED_UNITS: Record<string, StandardizedUnit> = {
|
|
fluid_ounce: { dimension: "volume", base: 29.5735295625, customary: true },
|
|
cup: { dimension: "volume", base: 236.5882365, customary: true },
|
|
ounce: { dimension: "mass", base: 28.349523125, customary: true },
|
|
pound: { dimension: "mass", base: 453.59237, customary: true },
|
|
milliliter: { dimension: "volume", base: 1.0, customary: false },
|
|
liter: { dimension: "volume", base: 1000.0, customary: false },
|
|
gram: { dimension: "mass", base: 1.0, customary: false },
|
|
kilogram: { dimension: "mass", base: 1000.0, customary: false },
|
|
};
|
|
|
|
/** Systems made of customary units. An ingredient already in the reader's system is left alone. */
|
|
export const CUSTOMARY_SYSTEMS: UnitSystem[] = ["us"];
|
|
|
|
export const UNIT_SYSTEMS: Record<UnitSystem, Record<UnitDimension, UnitRung[]>> = {
|
|
metric: {
|
|
mass: [
|
|
{ unit: "gram", seedKey: "gram", base: 1.0, takeover: 1.0, fraction: false },
|
|
{ unit: "kilogram", seedKey: "kilogram", base: 1000.0, takeover: 1.0, fraction: false },
|
|
],
|
|
volume: [
|
|
{ unit: "milliliter", seedKey: "milliliter", base: 1.0, takeover: 1.0, fraction: false },
|
|
{ unit: "liter", seedKey: "liter", base: 1000.0, takeover: 1.0, fraction: false },
|
|
],
|
|
},
|
|
us: {
|
|
mass: [
|
|
{ unit: "ounce", seedKey: "ounce", base: 28.349523125, takeover: 1.0, fraction: true },
|
|
{ unit: "pound", seedKey: "pound", base: 453.59237, takeover: 1.0, fraction: true },
|
|
],
|
|
volume: [
|
|
{ unit: "teaspoon", seedKey: "teaspoon", base: 4.92892159375, takeover: 1.0, fraction: true },
|
|
{ unit: "tablespoon", seedKey: "tablespoon", base: 14.78676478125, takeover: 1.0, fraction: true },
|
|
{ unit: "cup", seedKey: "cup", base: 236.5882365, takeover: 0.25, fraction: true },
|
|
{ unit: "quart", seedKey: "quart", base: 946.352946, takeover: 1.0, fraction: true },
|
|
{ unit: "gallon", seedKey: "gallon", base: 3785.411784, takeover: 1.0, fraction: true },
|
|
],
|
|
},
|
|
};
|