propfinder
A micro library to find a property on an object. It was specifically written to solve this problem:
if foo && foobar && foobarbaz === 'something' {}
You cannot just write the following because you might have a ReferenceError thrown.
if foobarbaz === 'something' {}
But with propfinder you can do:
if === 'something' {}
If the property does not exist, propfinder will return undefined
.
It is curryable, so you can do stuff like this:
var someJsonStructure = meta: id: 123 ...; var someOtherJsonStructure = error: "Not found" var getId = ; var id = ; // => 123 var id2 = ; // => undefined
It takes a method as the third optional argument.
The return value from the optional method is also returned from propfinder.
var resultId = ;
It should work in all ES3 browsers and in node.