Comments (10)
This would require adding "Ah" as a unit. We can't simply guess what the combined units mean or we would have issues with things like "mm" (millimeter
s? or meter*meter
?).
from js-quantities.
Disambiguating theses cases could be supported by choosing a conventional way to parse them.
For cases represented by joined characters with no separators (other cases are not ambiguous), the first character could be always considered as a prefix (if compatible of course) and the remaining characters would be parsed as raw units. If this convention is followed, we have:
'mm': milli, meter
'm m': meter, meter
'mN: milli, newton
'Nm: newton, meter
'm*N': meter, newton
'm N': meter, newton
'mmN': milli, meter, newton
'mNm': milli, newton, meter
'Ah', // ampere, hour
'hA', // hecto, ampere
'mAh', // milli, ampere, hour
Like so, it seems to follow the principle of least surprise.
from js-quantities.
To play devil's advocate here, I would argue that hecto
isn't very commonly used and thus hA
not being hour*ampere
might be more surprising than you would expect (and the same goes for yocto
, maybe less so for deci
).
from js-quantities.
However, when I first started using this library, I was also surprised that this guess-work was not happening. But after looking into it and seeing the ambiguity I decided that wasn't such an issue for me.
from js-quantities.
Two arguments in favor of considering "hA" as hecto, ampere:
- Ampere-hour is often, if not always, denoted Ah so considering to parse "hA" as hecto, ampere should not be a real problem for anybody.
- Ruby-units parses "hA" as hecto, ampere and it would be desirable to have the same behavior.
That said, I really appreciate your opinions @rage-shadowman. It is a great help.
from js-quantities.
Q: Does ruby-units pars "Ah" as ampere*hour
?
If ruby-units does the guess work in this manner, then I agree with you (especially since I see no mention of "Ah" specifically in the ruby-units source). I do not have a running ruby environment to test it out on though.
from js-quantities.
No. Ironically it fails to parse it. But it is not surprising because js-quantities regexps were originally the same than Ruby-units ones. However, I would like to fix it because it is a bug.
from js-quantities.
Are you sure they consider it a bug in ruby-units? How would you define "hrs" then? hour
or hour*second
? There are likely many less obvious examples of ambiguity due to all of the aliases that are allowed for each unit. When I looked into making this change I gave up after I found a few that I couldn't state empirically should always go one way.
from js-quantities.
I do agree that "Ah" is a commonly used unit and thus may deserve its own unit definition. But I personally think that guess-work which results in direct answers to ambiguous questions is a bad idea.
from js-quantities.
I don't really have any authority in this matter, but given the conversation it does seem rage-shadowman's suggestion to give "Ah" its own definition is the solution with the least risk.
from js-quantities.
Related Issues (20)
- getSystems() It would be useful to tag/group the unit names by their SI, Imperial or other system and allow conversion toSystem('imperial')
- Possibility to add a method qty.getUnit() ? HOT 1
- Dividing by temperatures HOT 1
- Dividing by temperature HOT 1
- add metric ton symbol "t" HOT 1
- surfaces (m², km², hectares) HOT 1
- compatibility with Unified Code for Units of Measure HOT 1
- Translation of units into different languages
- no power operators? HOT 1
- Human readable value in contrained range HOT 2
- js-quantities is incompatible with sugarjs and prototypejs
- Lacking precision necessary for required comparisons HOT 10
- No converter for Miliradians
- Swift Converter error: Incompatible units
- Values formatted with group separators do not parse
- Pretty unit output
- Publish new version to npm HOT 1
- Can't import the ES module in Angular HOT 4
- Rounding Issues when converting Millimeter to Centimeter HOT 3
- Can't convert nautical miles to meters correctly HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from js-quantities.