redull
v0.0.4
Published
JavaScript module for null check on JSON object
Downloads
12
Maintainers
Readme
redull
redull library exported as a node.js module
Installation
npm install redull
Usage
const foo = (response !=null && response.data !=null && response.data.item !=null && response.data.item.id != null) ? response.data.item.id : ''
Instead of above condition, you can use below
Scenario 1:
This will return the actual value
import redull from 'redull'
const response = {
data:{
item: {
id: "F56Gh"
}
}
}
const foo = redull.getVal(response,"data.item.id");
// result will be `F56Gh`
Scenario 2:
This will return undefined
instead of breaking the code.
import redull from 'redull'
const response = {
data:{
item: {
id: "F56Gh"
}
}
}
const foo = redull.getVal(response,"data.item.name");
// result will be `undefined`