-
Notifications
You must be signed in to change notification settings - Fork 8
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
Equally use singular for unit types as in the c# project #29
Comments
Hi @Shentoza Are you referring to the unit's enum? This enum convention is not the same as in the C#, and I do agree that it was better to be the same convention, but why is this so painful? Can you please share a use case for why it's so matter? I can think of a use case, when you want to pass the unit as part of an API response, for instance: {
"value": 10,
"unit": "Meters"
} Then in the consumer, you want to do the following: const res = api_call()
const length = new Length(res.value, res.unit) But, if this is the case, it doesn't matter what the enum key name is, but what the actual value is. BTW, currently, the enums value of the units are random numbers (depending on the order, auto set number) |
Because the object coming from my Backend is
I'm using the enum name here to have a more speaking response in case anyone not using UnitsNet is calling my API, where the enum value of e.g. 12 would be confusing. I have seen that in the generator files ( |
For now I defined a lookup table that converts the units to their singular equivalent
which works but is more of a workaround |
I understand, so basically if I will change the value of the enum from some random number to the unit non-plural name Like this one Meters = 'Meter', It will work for you even if the enum key is still plural, like this: const length = new Length(res.value, res.unit as LengthUnits) I have seen that in the generator files ( unit-generator.ts ) in buildEnum it is specified to take the plural name, which should be easy to alter, no? |
That would be great! |
@Shentoza |
Yes, sorry I have to upgrade --latest since it's a new major version, which I forgot |
We're using the unitsnet-js as a way to have the same information in our frontend, that we also have in our backend.
However in this package all unitnames are in plural (e.g.
Meters
,Millimeters
,Inches
) while in the c# project they are singular (e.g.Meter
,Millimeter
,Inch
) which makes conversion between our c# backend and our typescript frontend really painful.Is this a conscious decision?
The text was updated successfully, but these errors were encountered: