safe-get-attr

1.0.1 • Public • Published

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
 

Package Sidebar

Install

npm i safe-get-attr

Weekly Downloads

0

Version

1.0.1

License

ISC

Unpacked Size

3.33 kB

Total Files

4

Last publish

Collaborators

  • panshanshan