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

Function parseDimensions

services/isbn/cbl.js:24–42  ·  view source on GitHub ↗

* Parse the CBL dimensions format into a proper object. * * @param {string} dimensionsStr The CBL dimensions. * @returns A object with width and height if valid.

(dimensionsStr)

Source from the content-addressed store, hash-verified

22 * @returns A object with width and height if valid.
23 */
24function parseDimensions(dimensionsStr) {
25 const dimensions = dimensionsStr
26 ? dimensionsStr.match(/(\d{2})(\d)?x(\d{2})(\d)?$/)
27 : null;
28
29 if (!dimensions) {
30 return null;
31 }
32
33 return {
34 width: parseFloat(
35 dimensions[1] + (dimensions[2] ? `.${dimensions[2]}` : '')
36 ),
37 height: parseFloat(
38 dimensions[3] + (dimensions[4] ? `.${dimensions[4]}` : '')
39 ),
40 unit: 'CENTIMETER',
41 };
42}
43
44/**
45 * Parse separated city and state strings into a full

Callers 1

searchInCblFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected