

Grep your js objects - begriffs
https://github.com/begriffs/objgrep

======
oinksoft
A small thing: If you are targeting Chrome, or modern browsers in general, use

    
    
      Object.defineProperty(Object.prototype, 'grep', {
        enumerable: false,
        value: /* ... */
      });
    

rather than

    
    
      Object.prototype.grep = /* ... */
    

This way, your 'grep' does not pollute for () loops.

~~~
begriffs
Fixed.

Great suggestion, thank you!

------
solox3
Wouldn't it be better if the return is just a list of either the result (in
the case that the value of a KV pair matches), or a reference to the result
(in the case that the key of a KV pair matches)?

------
shurcooL
I would like something like this for getting fields/values from nested Go
structs.

Does something like that already exist, or will I have to write it?

------
pbiggar
Looks cool. It should be straightforward to make it avoid cycles itself, and
default to infinite depth, which feels like a better default than 5.

~~~
begriffs
Actually it does mark visited objects to avoid cycles in its search. The
default depth limit prevents it from taking too long on huge dom objects, but
the choice of an arbitrary depth limit (of 5) does seem kind of gross. I'm
open to suggestions for improvement.

~~~
pbiggar
Oh cool. The readme (at the very bottom) makes it appear like it doesn't mark
visited objects.

------
indubitably

                if (i.match(/^[$A-Z_][0-9A-Z_$]*$/i)) {
    

broken

~~~
begriffs
You're saying it is too simple of a regex to reliably match well-behaved js
identifiers? Or is it broken in another way as well?

What would you suggest as a better test?

------
chadscira
this will be very useful when trying to reverse engineer something :).

------
underwires
nice use of jabberwocky - I think I'll switch my lorem ipsum to that.

