Saxonberg Server API
    Preparing search index...

    Class Quantity<U>

    Type Parameters

    Index

    Properties

    unit: U
    value: number

    Canonical-unit numeric value. Public-readonly so JSON.stringify produces the persistence shape directly (matches Light's pattern). Use rawValue() from inter-Stuff call sites; the field is structural for serialization.

    Methods

    • Instrument / analyze emission. Same wrapper, canonical text inside. The optional scaleName flows through to the <quantity tag="..."> attribute when a tag table is registered for the unit at that scale.

      Parameters

      • Optional_viewer: unknown
      • OptionalscaleName: string

      Returns Mml

    • Tag-table lookup. Returns the registered tag string when one is defined for the unit; otherwise falls back to the canonical format (so Quantity<g/mol>.tag() reads "55.845 g/mol", not "" or null).

      The optional scaleName selects which vocabulary to consult when the unit has multiple registered scales (e.g. 'color' vs 'thermal' for K). Without scaleName, falls back to the unit's default scale.

      Parameters

      • OptionalscaleName: string

      Returns string

    • Cross-unit conversion. Returns a Quantity<Unit> rather than a narrowly-typed Quantity<TargetUnit> because the target is a runtime parameter — callers that need narrow typing should call the unit-specific accessor on their host (e.g. light.intensity is statically Quantity<'lux'>).

      Parameters

      Returns Quantity<Unit>

    • Default-prose emission. Inner text is the tag (or canonical format for tagless units). Viewer parameter is forward-compat for the deferred pedagogical-seam setting. Optional scaleName picks the vocabulary when multiple scales are registered for the unit; default scale otherwise.

      Parameters

      • Optional_viewer: unknown
      • OptionalscaleName: string

      Returns Mml

    • Drop a registered scale for unit. When scaleName is omitted, removes every scale registered for the unit. Used by QuantityApi's reload path to handle entries that disappeared from the YAML, and by tests to reset registry state.

      Parameters

      • unit: Unit
      • OptionalscaleName: string

      Returns void

    • Snapshot of the (unit, scaleName) pairs currently carrying a registered table. Used by QuantityApi.reloadTagTables to compute which scales to delete after a re-read.

      Returns { scaleName: string; unit: Unit }[]

    • Compare two tags by their position in a (unit, scaleName)'s registered ordering. Returns a sign-only integer (negative when a precedes b, zero when equal, positive when a follows b) — same shape as Array.prototype.sort's comparator.

      Throws when no table is registered for the pair, or when either tag isn't present in the resolved table.

      Parameters

      • unit: Unit
      • a: string
      • b: string
      • OptionalscaleName: string

      Returns number

    • Reconstruct from the persistence shape produced by toJSON. Used by PropertiedMixin's hydrator and by callers passing { value, unit } plain objects through external boundaries.

      Type Parameters

      Parameters

      • json: { unit: U; value: number }

      Returns Quantity<U>

    • Tag-table reverse lookup. Resolves through the registered table to a canonical numeric value. The optional scaleName picks which vocabulary to consult when the unit has multiple registered scales (e.g. 'color' vs 'thermal' for K). Without scaleName, falls back to the unit's default scale.

      Throws for tags absent from the resolved table, or for unit / scale pairs with no registered table.

      Type Parameters

      Parameters

      • tag: string
      • unit: U
      • OptionalscaleName: string

      Returns Quantity<U>

    • Authoring-friendly parse. Four input shapes:

      • tag: "heavy" → registered threshold for the target unit.
      • canonical literal: "12 kg"Quantity<kg>(12).
      • alt-unit literal: "12000 g" (target kg) → Quantity<kg>(12).
      • bare number / bare-number string: 5 or "5" → canonical-unit interpretation. mass: 5 on a Quantity<kg> field is 5 kg, not 5 g.

      The optional scaleName selects which tag table to consult when the input is a tag string and the target unit has multiple scales registered.

      Throws on unrecognized tag, unparseable literal, or alt-unit with no registered converter to the target.

      Type Parameters

      Parameters

      • input: string | number
      • targetUnit: U
      • OptionalscaleName: string

      Returns Quantity<U>

    • Register a tag table for (unit, scaleName). Replaces any prior table at that pair. First scale registered for a unit becomes that unit's default scale (the one tag() / parse() / fromTag() consult when no scale name is given); setDefaultScale overrides explicitly.

      scaleName defaults to DEFAULT_SCALE ('default') for single-vocabulary units like kg or lux. Units with multiple vocabularies (K's color vs thermal) register each scale by an explicit name.

      Parameters

      Returns void

    • Pick which scale tag() / parse() / fromTag() consult for unit when no scaleName is passed. Throws if the scale isn't registered for that unit.

      Parameters

      • unit: Unit
      • scaleName: string

      Returns void

    • Shift a tag by integer band offset within its registered (unit, scaleName) ordering. Clamps to the [first, last] band range; non-finite shifts are treated as zero (the input tag passes through unchanged).

      Throws when:

      • No table is registered for the (unit, scaleName) pair.
      • tag isn't present in the resolved table.

      Worked example: shiftTag('lux', 'lit', -2)'very-dim' (assuming the lux scale order pitch-black/very-dim/dim/lit/ bright/blinding). shiftTag('lux', 'pitch-black', -10)'pitch-black' (clamped at the floor).

      Parameters

      • unit: Unit
      • tag: string
      • shift: number
      • OptionalscaleName: string

      Returns string

    • Ordered tag list for a (unit, scaleName) pair. Order is ascending by threshold (the registry sorts entries on register for tagFor's descending walk; this helper exposes the same ordering as a plain string array for callers that need to do shift/compare arithmetic over tag bands).

      Returns an empty array when no table is registered for the pair. scaleName defaults to the unit's registered default scale.

      Cross-unit consumer pattern: LightBand is the lux scale's tag list; a future thermal-K scale would expose its own ordered tag list the same way.

      Parameters

      • unit: Unit
      • OptionalscaleName: string

      Returns readonly string[]