8000 How should be managed unknown units with conversion ? · Issue #21 · tc39/proposal-measure · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

How should be managed unknown units with conversion ? #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
tpoisseau opened this issue Dec 23, 2024 · 0 comments
Open

How should be managed unknown units with conversion ? #21

tpoisseau opened this issue Dec 23, 2024 · 0 comments

Comments

@tpoisseau
Copy link
tpoisseau commented Dec 23, 2024

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}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant
0