1.0.1 • Published 6 years ago

safe-get-attr v1.0.1

Weekly downloads
4
License
ISC
Repository
github
Last release
6 years ago

safe-get-attr

Safe-get-attr can help us quickly get attributes and ensure program robustness.

get

    npm i safe-get-attr --save-dev

use

import safeGetAttr from 'safe-get-attr'

const Tom = {
    name:'Tom',
    child:{
        name:'Dick',
        child:{
            name:'Jack',
            child:{
                name:'Jerry'
            }
        }
    },
}

const name1 = safeGetAttr(Tom, 'child', 'child', 'child', 'name')

// Jerry

const name2 = safeGetAttr(Tom, 'child', 'child', 'child', 'child', 'name')

// undefined but there's no error