Skip to content
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

Is arithmetic in scope for ECMA-402? #10

Open
sffc opened this issue Jul 20, 2020 · 1 comment
Open

Is arithmetic in scope for ECMA-402? #10

sffc opened this issue Jul 20, 2020 · 1 comment

Comments

@sffc
Copy link

sffc commented Jul 20, 2020

@zbraniecki and @littledan have pushed back on the idea of performing math on units as part of ECMA-402's black box. For example, this proposal necesitates the ability to provide input such as "2 meters" and have that converted to the correct unit or units, such as "600 cm" or "6 ft, 3 in".

I can see both perspectives here. On the one hand, a third-party math library would be better suited to performing this arithmetic. On the other, the current proposal covers the full-stack i18n use case, and exposing the individual pieces would amount to a much larger API surface that we would need to design.

@devsnek
Copy link
Member

devsnek commented Jul 20, 2020

Obviously not proposing this exact api, but is this the sort of abstraction level that is being suggested? This math seems like the exact sort of thing intl should be responsible for.

new Intl.NumberFormat('en-US', {
  style: 'unit',
  unit: 'meter',
  usage: 'person-height',
  unitDisplay: 'long'
}).format(1.8, (from, to, value) => {
  switch (from) {
    case 'meter':
	  switch (to) {
	    case 'foot':
	      return value * 3.281;
	    case 'inch':
	      return value * 39.37;
	    // ...
	    default:
	      break;
	  }
    case 'foot':
      // ...  
  }
  return 'unknown';
});

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

2 participants