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" |
wire option is."kg" and "" are bad input.mg/dL is written as mg/dl.
If your server uses case-sensitive UCUM codes, do a check of your units.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' })],
})