@@ -185,14 +185,14 @@ export const MEASUREMENT_UNITS: Record<string, MeasurementUnit> = {
185185 } ,
186186} ;
187187
188- export function getMeasurementUnit ( unitStr : string ) : MeasurementUnit {
188+ export function getMeasurementUnit ( unitStr : string ) : MeasurementUnit | null {
189189 if ( ! unitStr ) return null ;
190+ const unitStrLc = unitStr . toLowerCase ( ) ;
190191
191- const unit = MEASUREMENT_UNITS [ unitStr ?. toLowerCase ( ) ] ;
192+ const unit = MEASUREMENT_UNITS [ unitStrLc ] ;
192193 if ( unit ) return unit ;
193194
194- const unitStrLc = unitStr . toLowerCase ( ) ;
195- if ( MEASUREMENT_UNITS . unit . altLabels . indexOf ( unitStrLc ) > - 1 ) {
195+ if ( MEASUREMENT_UNITS . unit . altLabels ?. indexOf ( unitStrLc ) > - 1 ) {
196196 return {
197197 ...MEASUREMENT_UNITS . unit ,
198198 label : unitStrLc ,
@@ -204,11 +204,7 @@ export function getMeasurementUnit(unitStr: string): MeasurementUnit {
204204 return null ;
205205}
206206
207- /**
208- * @param unitAStr
209- * @param unitBStr
210- */
211- export function areUnitsCompatible ( unitAStr : string , unitBStr : string ) {
207+ export function areUnitsCompatible ( unitAStr : string , unitBStr : string ) : boolean {
212208 if ( unitAStr == unitBStr ) {
213209 return true ;
214210 }
@@ -221,19 +217,19 @@ export function areUnitsCompatible(unitAStr: string, unitBStr: string) {
221217 if ( ! unitAStr && unitBStr ) {
222218 return false ;
223219 }
224- const unitA : MeasurementUnit = getMeasurementUnit ( unitAStr ) ;
225- const unitB : MeasurementUnit = getMeasurementUnit ( unitBStr ) ;
220+ const unitA = getMeasurementUnit ( unitAStr ) ;
221+ const unitB = getMeasurementUnit ( unitBStr ) ;
226222 if ( ! unitA || ! unitB ) {
227223 return false ;
228224 }
229225 return unitA . kind === unitB . kind ;
230226}
231227
232228export function getMetricUnitOptions ( metricUnit ?: string , showLongLabel ?: boolean ) : { label : string ; value : string } [ ] {
233- const unit : MeasurementUnit = getMeasurementUnit ( metricUnit ) ;
229+ const unit = getMeasurementUnit ( metricUnit ) ;
234230
235231 const options = [ ] ;
236- for ( const [ key , value ] of Object . entries ( MEASUREMENT_UNITS ) ) {
232+ for ( const value of Object . values ( MEASUREMENT_UNITS ) ) {
237233 if ( ! unit || value . kind === unit . kind ) {
238234 if ( value . kind === UNITS_KIND . COUNT ) {
239235 if ( showLongLabel )
@@ -274,36 +270,20 @@ export function getMetricUnitOptionsFromKind(
274270 return getMetricUnitOptions ( metricUnit , showLongLabel ) ;
275271}
276272
277- export function getAltUnitKeys ( unitTypeStr ) : string [ ] {
278- const unit : MeasurementUnit = getMeasurementUnit ( unitTypeStr ) ;
273+ export function getAltUnitKeys ( unitTypeStr : string ) : string [ ] {
274+ const unit = getMeasurementUnit ( unitTypeStr ) ;
279275 const options = [ ] ;
280- Object . values ( MEASUREMENT_UNITS ) . forEach ( value => {
276+ for ( const value of Object . values ( MEASUREMENT_UNITS ) ) {
281277 if ( ! unit || value . kind === unit . kind ) {
282278 if ( value . altLabels ) {
283279 options . push ( ...value . altLabels ) ;
284280 } else options . push ( value . label ) ;
285281 }
286- } ) ;
287-
288- return options ;
289- }
290-
291- export function getVolumeMinStep ( sampleTypeUnit ?: MeasurementUnit | string ) {
292- const step = 0.01 ;
293- if ( ! sampleTypeUnit ) {
294- return step ;
295282 }
296283
297- const unit = typeof sampleTypeUnit === 'string' ? getMeasurementUnit ( sampleTypeUnit ) : sampleTypeUnit ;
298-
299- // If we don't know the units, or it is 'unit' then use the default
300- if ( ! unit || unit . baseUnit === MEASUREMENT_UNITS . unit . baseUnit ) {
301- return step ;
302- }
303-
304- return Math . pow ( 10 , - unit . displayPrecision ) ; // Track uL and mg to a single unit
284+ return options ;
305285}
306286
307- export function isMeasurementUnitIgnoreCase ( expected : MeasurementUnit , val : string ) {
287+ export function isMeasurementUnitIgnoreCase ( expected : MeasurementUnit , val : string ) : boolean {
308288 return expected . label . localeCompare ( val , 'en-US' , { sensitivity : 'base' } ) === 0 ;
309289}
0 commit comments