ignoreAttributes.js 611 B

1234567891011121314151617181920
  1. function getIgnoreAttributesFn(ignoreAttributes) {
  2. if (typeof ignoreAttributes === 'function') {
  3. return ignoreAttributes
  4. }
  5. if (Array.isArray(ignoreAttributes)) {
  6. return (attrName) => {
  7. for (const pattern of ignoreAttributes) {
  8. if (typeof pattern === 'string' && attrName === pattern) {
  9. return true
  10. }
  11. if (pattern instanceof RegExp && pattern.test(attrName)) {
  12. return true
  13. }
  14. }
  15. }
  16. }
  17. return () => false
  18. }
  19. module.exports = getIgnoreAttributesFn