-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
matches #5
Comments
Should this return a list of objects that match(1), a list of values from the objects that match(2), or a new object from the matcher(3)? var sampleObject = {a: 1, B: 2, C: 3, d: 4}
match(sampleObject, new RegExp('[A-Z]'));
=> [{B: 2}, {C: 3}] //1
=> [2, 3] //2
=> {B:2, C:3} //3 I'm leaning towards 2 or 3, maybe specify as a third parameter? |
Nevermind, just saw that I was describing |
Example: // support strings
[ 'a', 'aa', 'b' ].map(matches(/a/)); // [ true, true, false ]
// support objects
[ { foo: 'a' }, { foo: 'aa' }, { foo: 'b' } ].map(matches({
foo: /^a/
})); // [ true, true, false ] |
|
I have something that works nicely but waiting for #55 to be merged. I could add it the request if it's alright to have added all at once. |
Further thoughts: // support strings
[ 'a', 'aa', 'b' ].map(matches(/^a/)); // [ true, true, false ]
// is equivalent to
var re = /^a/;
[ 'a', 'aa', 'b' ].map(re.test.bind(re)); // [ true, true, false ] |
Also, maybe this object behavior may work well as an overloaded |
After your comments (esp, "Further thoughts") I've had second thoughts about a full var obj = {foo: '1', bar: 2};
hasKeypaths(obj, {foo: /\d/}); // true
hasKeypaths(obj, {bar: /\d/}); // true |
thoughts: accept an object that takes keypaths and regexp values too.
The text was updated successfully, but these errors were encountered: