utils/parsedimensionwithunit
module
Type Definitions
module:utils/parsedimensionwithunit~DimensionWithUnit
Functions
tryCastDimensionsToUnit( parentDimensionPx, dimension, targetUnit ) → DimensionWithUnitinternalmodule:utils/parsedimensionwithunit~tryCastDimensionsToUnitConverts dimension between
px->%and%->px.Parameters
parentDimensionPx: numberDimension of parent element that contains measured element.
dimension: DimensionWithUnitMeasured element dimension.
targetUnit: stringTarget unit for conversion.
Returns
DimensionWithUnitCasted dimension.
tryParseDimensionWithUnit( dimension ) → DimensionWithUnit | nullinternalmodule:utils/parsedimensionwithunit~tryParseDimensionWithUnitParses provided string with dimension value and returns extracted numeric value and unit.
Copy code* If non-string dimension is passed then `null` value is returned. * If unit is missing then `null` is returned. * If numeric value part of string is not a number then `null` is returned.Example:
"222px"=>{ value: 222, unit: "px" }"99%"=>{ value: 99, unit: "%" }Parameters
dimension: string | null | undefinedUnsafe string with dimension.
Returns
DimensionWithUnit | nullParsed dimension with extracted numeric value and units.