Giter Club home page Giter Club logo

Comments (4)

librilex avatar librilex commented on May 24, 2024 1

No updates, but it already works out of the box:

Qty('1 N*m').to('lbf*ft') // outputs a quantity of roughly '0.74 lbf*ft'

One could add the unit 'Nm' though:

var UNITS = {
  // ... //
  /* torque */
  "<Newton-meter>" : [["Nm"], 1.0, "energy", ["<kilogram>","<meter>","<meter>"], ["<second>","<second>"]],
  // ... //
};

from js-quantities.

rage-shadowman avatar rage-shadowman commented on May 24, 2024

This seems like it should have been a few separate tickets. Or maybe a blog post.

This library is a port of https://github.com/olbrich/ruby-units.

  • As far as "lb ft" goes, as you said, that is wrong. You need to use the correct type ("lbf" in this case). If you want your users to type incorrect (or ambiguous) stuff in by hand and still get the same results as if they typed in the unambiguous correct units, you will probably have to handle this context yourself.
  • Force has dimensions "(kg_m)/(s_s)", energy "(kg_m_m)/(s*s)". I believe those should not be compatible units unless you divide your energy by a length (or multiply your force by a length). If you are able to convert incompatible units, that sounds like a bug and should be filed.
  • This library needs a way to compute degF -> degC as a rate of change as well as tempF -> tempC as a temperature value. Since ruby-units used the deg/temp naming convention, so does js-quantities. This separation was done to avoid ambiguity and namespace collisions.
  • In order to avoid ambiguity and namespace collisions, there are spaces (or "*"s) required between the different units. If you have a better way, perhaps with an additional "kind" parameter to the constructor, perhaps you should fork the project, add a new constructor, and file a pull request?

Conclusion: Yes, it looks like you are trying to do something that js-quantities was not intended to do. It was intended to convert values between 2 compatible unambiguous unit types, and it does that very well (my team is using it in production to convert weather station data to localized values). It was not intended to be used to guess a user's intention and decide what they really wanted was X despite what they asked for. For that you'll want to use Google. ;)

PS - If you do come up with a good (unit testable) new constructor, I would definitely be interested in merging it into my fork (and who knows, @gentooboontoo might merge it too). However, the unit tests would need to be thorough (possibly generated programmatically by looping through all possible unit types with and without prefixes and joining them to determine which ones are ambiguous -- there might not be many, but there definitely are some).

from js-quantities.

rage-shadowman avatar rage-shadowman commented on May 24, 2024

Looks like I'm wrong, lbf is pound-force not pound-foot maybe it's lbf*ft that is wanted? Which also explains why you said force (meaning torque) is compatible with energy (so not a bug). And there doesn't seem to be a simple way to differentiate torque from energy here.

from js-quantities.

sheam avatar sheam commented on May 24, 2024

Any update on js-quantities being able to handle torque?

from js-quantities.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.