# utils/parsedimensionwithunit

module

<a id="type-definitions">

## Type Definitions

<a id="typedef-DimensionWithUnit">

### `DimensionWithUnit`

<a id="functions">

## Functions

<a id="function-tryCastDimensionsToUnit">

### `tryCastDimensionsToUnit( parentDimensionPx, dimension, targetUnit ) → DimensionWithUnit` _(internal)_

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

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/parsedimensionwithunit.ts#L52)

#### Parameters

* `parentDimensionPx: number`

  Dimension of parent element that contains measured element.

* `dimension: DimensionWithUnit`

  Measured element dimension.

* `targetUnit: string`

  Target unit for conversion.

#### Returns

* `DimensionWithUnit`

  Casted dimension.

<a id="function-tryParseDimensionWithUnit">

### `tryParseDimensionWithUnit( dimension ) → DimensionWithUnit | null` _(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.
```

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

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/parsedimensionwithunit.ts#L25)

#### Parameters

* `dimension: string | null | undefined`

  Unsafe string with dimension.

#### Returns

* `DimensionWithUnit | null`

  Parsed dimension with extracted numeric value and units.

---

Full index of the CKEditor 5 API reference: [llms.txt](llms.txt)
