README
pathfindr
safely traverse objects or arrays without breaking your application.
pathfindr(path: string, model: any, fallbackValue?: any) : result | fallbackValue
Example
const data = {
users: {
images: [
{
url: '/image.png'
}
]
}
};
const result = pathfindr('users/images/0/url', data); // => /image.png
This will not break the application
const data = {};
const result = pathfindr('data/images/0/url', data); // => null
This will not break the application and set fallback value
const data = {};
const result = pathfindr('data/images/0/url', data, '/fallback.png'); // => /fallback.png