NEWCKEditor 5 Long-term Support is here! Find out more
Sign up (with export icon)

image/imageresize/utils/tryparsedimensionwithunit

Api-module icon module

Type Definitions

Functions

  • Chevron-right icon

    tryCastDimensionsToUnit( parentDimensionPx, dimension, targetUnit ) → DimensionWithUnit
    internal

    Converts dimension between px -> % and % -> px.

    Parameters

    parentDimensionPx : number

    Dimension of parent element that contains measured element.

    dimension : DimensionWithUnit

    Measured element dimension.

    targetUnit : string

    Returns

    DimensionWithUnit

    Casted dimension.

  • Chevron-right icon

    tryParseDimensionWithUnit( dimension ) → null | DimensionWithUnit
    internal

    Parses provided string with dimension value and returns extracted numeric value and unit.

    * 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.
    
    Copy code

    Example: "222px" => { value: 222, unit: "px" } "99%" => { value: 99, unit: "%" }

    Parameters

    dimension : undefined | null | string

    Unsafe string with dimension.

    Returns

    null | DimensionWithUnit

    Parsed dimension with extracted numeric value and units.