All files / react-native-web/src/modules/multiplyStyleLengthValue index.js

100% Statements 12/12
83.33% Branches 5/6
100% Functions 3/3
100% Lines 11/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29                  22x   22x   22x 3x     22x 25x 22x 22x 22x 3x 3x          
/**
 * Copyright (c) Nicolas Gallagher.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @noflow
 */
 
const CSS_UNIT_RE = /^[+-]?\d*(?:\.\d+)?(?:[Ee][+-]?\d+)?(%|\w*)/;
 
const getUnit = (str) => str.match(CSS_UNIT_RE)[1];
 
const isNumeric = (n) => {
  return !isNaN(parseFloat(n)) && isFinite(n);
};
 
const multiplyStyleLengthValue = (value: string | number, multiple) => {
  if (typeof value === 'string') {
    const number = parseFloat(value) * multiple;
    const unit = getUnit(value);
    return `${number}${unit}`;
  } else Eif (isNumeric(value)) {
    return value * multiple;
  }
};
 
export default multiplyStyleLengthValue;