⚠️ This is pre-release documentation for v3. For stable docs, visit v2.
Skip to content

@tmlmt/cooklang-parser / UnitDefinition

Interface: UnitDefinition

Represents a fully defined unit with conversion and alias information

Extends

Properties

aliases

aliases: string[]

e.g. ['gram', 'grams']


fractions?

optional fractions?: UnitFractionConfig

Fraction display configuration


integerProtected?

optional integerProtected?: boolean

This property is set to true when the unit is prefixed by an = sign in the cooklang file, e.g. =g Indicates that quantities with this unit should be treated as integers only (no decimal/fractional values).

Inherited from

Unit.integerProtected


isBestUnit?

optional isBestUnit?: boolean

Whether this unit is a candidate for "best unit" selection (default: true)


maxValue?

optional maxValue?: number

Maximum value before upgrading to a larger unit (default: 999)


name

name: string

Inherited from

Unit.name


system

system: UnitSystem


toBase

toBase: number

Conversion factor to the base unit of its type (uses default system for ambiguous units)


toBaseBySystem?

optional toBaseBySystem?: Partial<Record<SpecificUnitSystem, number>>

For ambiguous units: conversion factors for each possible system


type

type: UnitType


unitFirstAliases?

optional unitFirstAliases?: string[]

Aliases that should be formatted with the unit before the quantity (e.g. Japanese 大さじ1).


unitOrder?

optional unitOrder?: "quantity-first" | "unit-first"

Controls whether the unit is rendered before or after the numeric quantity. Populated automatically by resolveUnit when the alias is listed in unitFirstAliases. Can also be set directly on a custom Unit object as an override.

Inherited from

Unit.unitOrder