function parseDimensions(dimensions) {
  if (!dimensions) {
    return null;
  }

  const values = dimensions
    .replace(/ (centimeters|inches)$/, '')
    .split(' x ')
    .map(parseFloat)
    .filter((dm) => !Number.isNaN(dm));

  if (values.length !== 3) {
    return null;
  }

  return {
    width: values[1],
    height: values[0],
    unit: dimensions.includes('centimeters') ? 'CENTIMETER' : 'INCH',
  };
}
Parse the Open Library dimensions format into a proper object.

@param {string} dimensionsStr The Open Library dimensions.
@returns A object with width and height if valid.