get-attribute.js 544 B

1234567891011121314151617
  1. function getAttribute(tag, attributeName, options) {
  2. const debug = (options && options.debug) || false;
  3. if (debug) console.log("getting " + attributeName + " in " + tag);
  4. const xml = typeof tag === "object" ? tag.outer : tag;
  5. const pattern = `${attributeName}\\="\([^"]*\)"`;
  6. if (debug) console.log("pattern:", pattern);
  7. const re = new RegExp(pattern);
  8. const match = re.exec(xml);
  9. if (debug) console.log("match:", match);
  10. if (match) return match[1];
  11. }
  12. module.exports = getAttribute;
  13. module.exports.default = getAttribute;