Skip to content

How should be managed unknown units with conversion ? #21

@tpoisseau

Description

@tpoisseau

https://en.wikipedia.org/wiki/Hectare#Are

Let say runtime known meter unit, be we want work with Are (1a = 100m2) and this unit is not known by the runtime.

Should this proposal allow to add custom units and describe possible conversions ?

API Idea (pseudocode):

Measure.addUnit({
  symbol: 'a',
  name: 'are',
  kind: {type: 'distance', exponent: 2} // surface
  conversions: [
    {
      type: 'distance',
      exponent: 2,
      unit: 'meter',
      convertTo: (ares: number) => ares * 100,
      convertFrom: (m2: number) => m2 / 100,
    }
  ],
});

const measureAre = new Measure(1, {unit: 'are'});
const measureM2 = measureAre.convertTo('meter');
// Measure { value: 100, unit: 'meter', exponent: 2}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions