getTabIndex.js 921 B

12345678910111213141516171819202122232425262728293031323334353637
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports["default"] = getTabIndex;
  6. var _jsxAstUtils = require("jsx-ast-utils");
  7. /**
  8. * Returns the tabIndex value.
  9. */
  10. function getTabIndex(tabIndex) {
  11. var literalValue = (0, _jsxAstUtils.getLiteralPropValue)(tabIndex); // String and number values.
  12. if (['string', 'number'].indexOf(typeof literalValue) > -1) {
  13. // Empty string will convert to zero, so check for it explicity.
  14. if (typeof literalValue === 'string' && literalValue.length === 0) {
  15. return undefined;
  16. }
  17. var value = Number(literalValue);
  18. if (Number.isNaN(value)) {
  19. return undefined;
  20. }
  21. return Number.isInteger(value) ? value : undefined;
  22. } // Booleans are not valid values, return undefined.
  23. if (literalValue === true || literalValue === false) {
  24. return undefined;
  25. }
  26. return (0, _jsxAstUtils.getPropValue)(tabIndex);
  27. }