grunt-dom-munger
grunt-dom-munger copied to clipboard
Add read filter option
Inspired by issue #2 https://github.com/cgross/grunt-dom-munger/issues/2
@jamesspencer I'm curious what the filter function you're using is.
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.
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.
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.
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.