Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Grep your js objects (github.com/begriffs)
23 points by begriffs on Feb 10, 2013 | hide | past | favorite | 11 comments


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.


Fixed.

Great suggestion, thank you!


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)?


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.


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.


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


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?


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


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?


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


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




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: