How to use the cssstyle/lib/parsers.parseInteger function in cssstyle

To help you get started, we’ve selected a few cssstyle examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github facebook / jest / src / lib / jsdom-compat.js View on Github external
}

if (cssPropertyParsers) {
  // The shorthandParser function should never return a string, but it
  // does when given an empty string. Here we detect that case and make it
  // return an empty object instead, to work around bugs in later code
  // that assume the result of shorthandParser is always an object.
  var shorthandParser = cssPropertyParsers.shorthandParser;
  cssPropertyParsers.shorthandParser = function() {
    var result = shorthandParser.apply(this, arguments);
    return result === '' ? {} : result;
  };

  // Current versions of the cssstyle parseInteger function can't actually
  // handle string inputs.
  var badInt = cssPropertyParsers.parseInteger('5');
  if (badInt !== '5') {
    cssPropertyParsers.parseInteger = function parseInteger(val) {
      return String(parseInt(val, 10));
    };
  }

  // Current versions of the cssstyle parseNumber function can't actually
  // handle string inputs.
  var badNum = cssPropertyParsers.parseNumber('0.5');
  if (badNum !== '0.5') {
    cssPropertyParsers.parseNumber = function parseNumber(val) {
      return String(parseFloat(val, 10));
    };
  }
}