UNPKG

e-lado

Version:

[![CircleCI](https://circleci.com/gh/sharetribe/sharetribe/tree/master.svg?style=svg)](https://circleci.com/gh/sharetribe/sharetribe/tree/master) [![Dependency Status](https://gemnasium.com/sharetribe/sharetribe.png)](https://gemnasium.com/sharetribe/shar

28 lines (22 loc) 695 B
import propName from './propName'; const DEFAULT_OPTIONS = { ignoreCase: true, }; /** * Returns the JSXAttribute itself or undefined, indicating the prop * is not present on the JSXOpeningElement. * */ export default function getProp(props = [], prop = '', options = DEFAULT_OPTIONS) { const propToFind = options.ignoreCase ? prop.toUpperCase() : prop; return props.find((attribute) => { // If the props contain a spread prop, then skip. if (attribute.type === 'JSXSpreadAttribute') { return false; } const currentProp = options.ignoreCase ? propName(attribute).toUpperCase() : propName(attribute); return propToFind === currentProp; }); }