UNPKG

vcc-ui

Version:

A React library for building user interfaces at Volvo Cars

41 lines (38 loc) 1.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.applySpaceMultiplier = applySpaceMultiplier; // TODO: Fix eslint issues the next time this file is edited. /* eslint-disable eqeqeq */ function applyFactor(factor) { return value => { if (value === undefined || value === null) { return undefined; } // this allows stringy numbers e.g. <View paddingLeft="4" /> to be parsed and multiplied as well if (typeof value === 'string') { const parsedValue = parseInt(value, 10); return Number(value) == parsedValue ? parsedValue * factor : value; } if (typeof value !== 'number') { return value; } return value * factor; }; } function applySpaceMultiplier() { let factor = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1; const applyFactorToValue = applyFactor(factor); return value => { if (Array.isArray(value)) { return value.map(applyFactorToValue); } else if (value && typeof value === 'object') { return Object.keys(value).reduce((out, key) => { out[key] = applyFactorToValue(value[key]); return out; }, {}); } return applyFactorToValue(value); }; }