pathfindr

1.0.9 • Public • Published

pathfindr

safely traverse objects or arrays without breaking your application.

pathfindr(pathstring, modelany, 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

/pathfindr/

    Package Sidebar

    Install

    npm i pathfindr

    Weekly Downloads

    5

    Version

    1.0.9

    License

    ISC

    Unpacked Size

    4.17 kB

    Total Files

    4

    Last publish

    Collaborators

    • zapdos