Closed davismj closed 6 years ago
Perhaps put it in a string and then convert it to a RegEx inside your converter? I have a feeling this would be a major task to implement. @jdanyow Any thoughts?
I did that. It would just be a really nice to have, I think.
For the record here's my filter code:
const REMATCH = /\/(.*)\/(\w*)/;
export class FilterValueConverter {
toView(array, filter) {
let keys = Object.keys(filter).filter((key) => filter[key]);
if (!keys.length || keys.every((key) => filter[key] == null)) {
return array;
}
return array.filter((item) => {
return keys.some((key) => {
let re = filter[key] || '';
let match = REMATCH.exec(re);
if (match) {
re = new RegExp(match[1], match[2]);
} else {
re = new RegExp(re, 'i');
}
let value = item[key] || '';
return re.test(value);
});
});
}
}
It might be possible to add logic to the parser for this. I'm not sure how much trouble that will be. This section in the grammar worries me a little bit, but may be a non-issue:
It may be as easy as adding another condition here and a RegExLiteral
class to the AST. Will experiment when I get a chance. @davismj if you want to play around with it, I can try and answer any questions.
I'd say skip it for now. We can consider it again after 1.0. I think there are more important things to tackle in the mean time, esp. since this isn't a show stopper.
Stale since 2016 interesting use case though
Going to close this. I don't want to expand the expression grammar if we can help it. A workaround for the above would be to register RegEx by name and then have the filter lookup the RegEx.
Get this out of the box with http://aurelia.plus
I have a filter list value converter and I want to pass in a regexp literal:
/[^anythingbutthis]/i
This is currently a syntax error.