import typing


def shutter_value(
    val: typing.Union[str, int, float]
) -> typing.Union[float, str]:
    """Convert val to a standard shutter speed value.

    val format depends on the camera manufacturer.

    YAML: 1/N
    Canon: TBD
    Nikon: <decimal>s e.g. 0.1250s or fraction, or string.

    Args:
        val: shutter speed.

    Returns:
        shutter speed or 'error'
    """
    if not isinstance(val, str):
        return val

    tokens = val.split('/')
    if len(tokens) < 2:
        # Decimal format.
        try:
            shutter_speed = float(tokens[0].strip('s'))
        except ValueError:
            # Not a number.
            shutter_speed = 'error'

    else:
        # Fractional format.
        shutter_speed = float(tokens[0]) / float(tokens[1])

    return shutter_speed