Skip to content

Commit

Permalink
feat: better check-if-undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
LuXDAmore committed Dec 9, 2019
1 parent 9b0272d commit c74b8b0
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,18 @@ const moduleName = 'apis-to-file'
requests: [],
axios: {},
}
;
, checkIfUndefinedAndReturnDifferentData = (
check,
value,
) => {

return typeof check === 'undefined'
? value
: check
;

// [GitHub](https://github.com/nuxt/nuxt.js/issues/123#issuecomment-272246782)
// Gitignore
}
;

export default async function(
moduleOptions,
Expand Down Expand Up @@ -111,12 +119,14 @@ export default async function(
),
);

const request = requests[ index ]
, key = request.field || index
, emptyValue = typeof request.emptyValue !== 'undefined' ? request.emptyValue : []
const {
field: key = index,
emptyValue = [],
pathToData,
} = requests[ index ]
, value = (
request.pathToData
? request.pathToData
pathToData
? pathToData
.split(
'.',
)
Expand All @@ -126,12 +136,18 @@ export default async function(
key,
) => (
typeof acc !== 'undefined' && acc !== null
? acc[ key ] || emptyValue
? checkIfUndefinedAndReturnDifferentData(
acc[ key ],
emptyValue
)
: acc || {}
),
data || {},
)
: data || emptyValue
: checkIfUndefinedAndReturnDifferentData(
data,
emptyValue
)
)
;

Expand Down

0 comments on commit c74b8b0

Please sign in to comment.