Millwork
    Preparing search index...

    Module @millwork-ts/quantity

    @millwork-ts/quantity

    A Millwork codec for units of measure with js-quantities.

    pnpm add @millwork-ts/quantity @millwork-ts/core js-quantities
    
    Codec Value Raw
    quantity a frozen js-quantities Qty { "value": 12.5, "unit": "kg" } or "12.5 kg"
    • The codec reads both raw forms, whatever the wire option is.
    • A string must start with a number. "kg" and "" are bad input.
    • The codec writes the unit of the value. It does not convert the value to a different unit.
    • js-quantities writes some units in its own case. For example, mg/dL is written as mg/dl. If your server uses case-sensitive UCUM codes, do a check of your units.
    • The package exports Qty, the js-quantities function with types. js-quantities has no types of its own.
    Option Type Use
    wire 'object' | 'string' The raw form that the codec writes. The default is 'object'.

    equals converts the two values to one unit, then compares them. "1 m" equals "100 cm". Values with incompatible units, such as kg and m, are not equal.

    Register the codecs before the store calls transformations(), because transformations() reads the registry when it runs. See the @millwork-ts/warp-drive README.

    import { codecs } from '@millwork-ts/quantity'
    import { registerCodecs, valueField } from '@millwork-ts/warp-drive'
    import { withDefaults } from '@warp-drive/core/reactive'

    registerCodecs(codecs)

    export const ParcelSchema = withDefaults({
    type: 'parcel',
    fields: [valueField('weight', 'quantity', { wire: 'string' })],
    })
    Qty
    QtyFactory
    QuantityObject
    QuantityOptions
    QuantityRaw
    codecs
    Qty
    quantity