Module

image/imageresize/utils/tryparsedimensionwithunit

@ckeditor/ckeditor5-image/src/imageresize/utils/tryparsedimensionwithunit

module

Filtering

Type Definitions

  • DimensionWithUnit

Functions

  • tryCastDimensionsToUnit( parentDimensionPx, dimension, targetUnit ) → DimensionWithUnit

    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.

  • tryParseDimensionWithUnit( dimension ) → DimensionWithUnit | null

    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.
    

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

    Parameters

    dimension : undefined | null | string

    Unsafe string with dimension.

    Returns

    DimensionWithUnit | null

    Parsed dimension with extracted numeric value and units.