* Parse the Google Books dimensions format into a proper object. * * @param {string} dimensions The Google Books dimensions. * @returns A object with width and height if valid.
(dimensions)
| 12 | * @returns A object with width and height if valid. |
| 13 | */ |
| 14 | function parseDimensions(dimensions) { |
| 15 | if (!dimensions) { |
| 16 | return null; |
| 17 | } |
| 18 | |
| 19 | return { |
| 20 | width: parseFloat(dimensions.width.replace(/\s(cm|in)+$/, '')), |
| 21 | height: parseFloat(dimensions.height.replace(/\s(cm|in)+$/, '')), |
| 22 | unit: dimensions.width.includes('cm') ? 'CENTIMETER' : 'INCH', |
| 23 | }; |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * Parse the Google Books price format into a proper object. |
no outgoing calls
no test coverage detected