grunt-dom-munger icon indicating copy to clipboard operation
grunt-dom-munger copied to clipboard

Add read filter option

Open jamesspencer opened this issue 11 years ago • 5 comments

Inspired by issue #2 https://github.com/cgross/grunt-dom-munger/issues/2

jamesspencer avatar May 09 '13 09:05 jamesspencer

@jamesspencer I'm curious what the filter function you're using is.

ProLoser avatar Feb 18 '14 23:02 ProLoser

We needed to strip any leading slashes from script sources before passing the results directly to another 3rd party task:

{
  selector: 'script[src]',
  attribute: 'src',
  writeto: 'myJsRefs',
  isPath: true,
  filter: function(val) {
    return val.replace(/^\//, '');
  }
}

Looking back, filter is the wrong term to use as this is about modifying the data rather than determining whether it should be added to the collection.

jamesspencer avatar Feb 19 '14 01:02 jamesspencer

Yeah. I would just change the property to callback. You also could improve performance by simply doing an if-set check instead of declaring a noop.

ProLoser avatar Feb 19 '14 01:02 ProLoser

Actually. It would make sense if it worked as both a cleanup AND filter. Such as if you return 'false' it doesn't get added to the collection.

ProLoser avatar Feb 19 '14 01:02 ProLoser

Changing to callback sounds good, also performance note.

RE filtering: this did cross my mind but by allowing the user to manipulate the data also allows then to return non-string values; should their intent be to collect a list of booleans (based on some criteria) then this functionality would strip results. A more flexible and explicit design would have separate callback and filter operations.

jamesspencer avatar Feb 19 '14 02:02 jamesspencer