haimkastner / unitsnet-js

A better way to hold unit variables and easily convert to the destination unit
https://www.npmjs.com/package/unitsnet-js
MIT License
23 stars 8 forks source link

Full support for units.net features? #26

Open eddiesholl opened 10 months ago

eddiesholl commented 10 months ago

Hey there,

Stumbled on this library recently, for what it offers it’s a great API. I was wondering if you’d looked into the possibility of a full replication of units.net? An example of what might be possible, is cross conversion of units when you multiply and divide, so length.mul(anotherLength) returns an area, that sort of thing.

looking in the original repo, it’s all driven by even more codegen than is used here. I was just wondering if you’d already looked into what that whole task would look like, and if it would even work.

not sure if typescript method overloading would allow this sort of thing, for example.

That full API, where units are tracked for you in a type safe way, would be pretty freakin cool, I think.

thanks!

haimkastner commented 10 months ago

Hi @eddiesholl

Thanks for your comment.

I haven't yet thought much about how to design it, need to find some extra time for it :)

However, JavaScript (and TypeScript) is missing important and complex features compared to the strong-typed C#.

For instance, there is no way to overload operations, which forces operations implementation to be something like: unit1.add(unit2) instead of unit1 + unit2 which looks and feels way better, and I guess similar problems may come up in the implementation of other original library features.

Specific to your example with cross conversions, TypeScript does support abstract classes, so it should be possible to implement.

Did you already have some specific design in your mind?

eddiesholl commented 10 months ago

No nothing yet, I was more trying to think ahead to how much more could be possible. I’ll let you know if I get some time to try anything out