ericman314 / UnitMath

JavaScript library for unit conversion and arithmetic
Apache License 2.0
31 stars 7 forks source link

Transform between systems (US, Imperial, Metric, etc) #22

Closed codingedgar closed 1 year ago

codingedgar commented 5 years ago

Referencing https://github.com/josdejong/mathjs/issues/1449#issuecomment-536841614

I haven't found anything that solves the US system, Imperial, Metric differences of cup, Tbs etc well, same issue happens in measuring-cup. The need of

  1. Transform between systems (US, Imperial, Metric, etc)
  2. Transform between units (cup of sugar -> g of sugar)

Are very common use cases for cooking, (the 2nd point is a total different issue, but would be amazing to have something to do it).

For the second point maybe a complement like Moment timezone, could store all the transformations density of common ingredient, and some way to add explicit densities would be great.

ghost commented 2 years ago

The 2nd point is probably not realistically feasible. There are just far too many ingredients and methods of preparation to deal with. Consider kosher salt vs table salt .. anything that can be sliced, diced, chopped, minced... packed vs loose brown sugar, or dried parsley vs fresh.. you get the idea. Each variation results in different weight/vol.. in some cases the difference can be drastic.

I'm sure it could just include the ubiquitous ingredients like flour/sugar/salt/etc, but then it has pretty limited usefulness.

ericman314 commented 1 year ago

For what it's worth, UnitMath does have the capability of defining custom units. This will get even easier in v1.0.0, which is almost ready. So you could, for instance, add the different cup variants, assigning each to a different system, and then easily convert between them.

To the second point of converting between volume and mass, that can be done using unit arithmetic by multiplying or dividing by the density of the ingredient. It's beyond the scope of this library to define what those densities are, but you could definitely do that in another project that imports UnitMath to do the arithmetic.