dividab / uom

Extensible unit of measure conversion with type safety for typescript
MIT License
18 stars 1 forks source link

Remove UnitFormat #53

Closed jonaskello closed 3 years ago

jonaskello commented 3 years ago

It seems like UnitFormat has been refactored to the point where it bascially does nothing. Could it be removed?

The README has an example of using UnitFormat.getUnitFormat() that takes an Amount but this is not how the code actually works anymore:

This is the example:

const length = Amount.create(10, Units.Meter);
const format = UnitFormat.getUnitFormat(length);
console.log(
  "The amount is " +
    Math.round(Amount.valueAs(Units.Inch, amount), format.decimalCount) +
    " " +
    format.label
);

This is how the code works:

export function getUnitFormat(
  unit: Unit.Unit<unknown>,
  unitsFormat: UnitFormatMap
): UnitFormat | undefined {
  return unitsFormat[unit.name];
}
jonaskello commented 3 years ago

It turns out UnitFormat is used in the uom-units package. The example was changed in this commit to reflect this.