Closed DanielBuchberger closed 2 years ago
Would it be possible to store the abbreviation of a unit, which is used in the .toString() method in an array or a dictionary, so that you can access the abbreviation based on the given enum? Let's take the temperature for example: https://github.com/haimkastner/unitsnet-js/blob/3e6fa5d22df3d7fa190115e55967395f82b585e8/src/temperature.g.ts#L304-L331
.toString()
It would be great if I could do the following (which would also shorten the .toString() method):
unitAbbreviations = { Kelvins : 'K', DegreesCelsius: '°C', // and all the others... } public toString(toUnit: TemperatureUnits = TemperatureUnits.Kelvins): string { return this.convertFromBase(toUnit).toString() + this.unitAbbreviations[toUnit]
Alternatively also a method would work:
public getUnitAbbreviation(toUnit: TemperatureUnits = TemperatureUnits.Kelvins): string { switch (toUnit) { case TemperatureUnits.Kelvins: return ` K`; case TemperatureUnits.DegreesCelsius: return ` °C`; case TemperatureUnits.MillidegreesCelsius: return ` m°C`; case TemperatureUnits.DegreesDelisle: return ` °De`; case TemperatureUnits.DegreesFahrenheit: return ` °F`; case TemperatureUnits.DegreesNewton: return ` °N`; case TemperatureUnits.DegreesRankine: return ` °R`; case TemperatureUnits.DegreesReaumur: return ` °Ré`; case TemperatureUnits.DegreesRoemer: return ` °Rø`; case TemperatureUnits.SolarTemperatures: return ` T⊙`; default: break; } return '';
Thanks anyways for the effort!
Hi @DanielBuchberger Thanks for this good idea.
I have added a new function named getUnitAbbreviation as part of version 1.0.28 The new version is available on the NPM registry.
getUnitAbbreviation
Would it be possible to store the abbreviation of a unit, which is used in the
.toString()
method in an array or a dictionary, so that you can access the abbreviation based on the given enum? Let's take the temperature for example: https://github.com/haimkastner/unitsnet-js/blob/3e6fa5d22df3d7fa190115e55967395f82b585e8/src/temperature.g.ts#L304-L331It would be great if I could do the following (which would also shorten the
.toString()
method):Alternatively also a method would work:
Thanks anyways for the effort!