automation/medusa-upstream-review
| 1 | import { UnistNodeWithData } from "types" |
| 2 | |
| 3 | export default function getAttribute( |
| 4 | node: UnistNodeWithData, |
| 5 | attrName: string |
| 6 | ) { |
| 7 | const attributeIndex = node.attributes?.findIndex( |
| 8 | (attribute) => attribute.name === attrName |
| 9 | ) |
| 10 | if (attributeIndex === undefined || attributeIndex === -1) { |
| 11 | return |
| 12 | } |
| 13 | const attribute = node.attributes![attributeIndex] |
| 14 | |
| 15 | if (!attribute) { |
| 16 | return |
| 17 | } |
| 18 | |
| 19 | return attribute |
| 20 | } |