MCPcopy Create free account
hub / github.com/BrasilAPI/BrasilAPI / parseDimensions

Function parseDimensions

services/isbn/openLibrary.js:14–34  ·  view source on GitHub ↗

* 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.

(dimensions)

Source from the content-addressed store, hash-verified

12 * @returns A object with width and height if valid.
13 */
14function parseDimensions(dimensions) {
15 if (!dimensions) {
16 return null;
17 }
18
19 const values = dimensions
20 .replace(/ (centimeters|inches)$/, '')
21 .split(' x ')
22 .map(parseFloat)
23 .filter((dm) => !Number.isNaN(dm));
24
25 if (values.length !== 3) {
26 return null;
27 }
28
29 return {
30 width: values[1],
31 height: values[0],
32 unit: dimensions.includes('centimeters') ? 'CENTIMETER' : 'INCH',
33 };
34}
35
36/**
37 * Parse the Open Library publish date into a proper year number.

Callers 1

searchInOpenLibraryFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected