Function parseUnit

  • Parses a number or string representing a number with units. The result is a tuple type with the number and unit separated. If the value provided is a number, the default unit is px.

    Example

    parseUnit('1px') // Returns [1, 'px']
    parseUnit('1em', 'em') // Returns [1, 'em']

    Parameters

    • value: string | number

      String or number to parse.

    • defaultUnit: string = 'px'

      Default unit if the unit is absent.

    Returns UnitTuple

    Parsed number/unit tuple.