Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Mar 13, 2022
1 parent ed619fc commit 27fa428
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/config/normalize/lib/wild_wild_path/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,21 @@ export const list = function (target, queryOrPath) {
// Retrieve a single property's value in `target` matching a query string.
// Wildcards can be used, but only the first value is returned.
export const get = function (target, queryOrPath) {
// eslint-disable-next-line fp/no-loops
for (const { value, missing } of iterate(target, queryOrPath)) {
// eslint-disable-next-line max-depth
if (!missing) {
return value
}
}
const entry = find(target, queryOrPath)
return entry === undefined ? undefined : entry.value
}

// Check if a property is not missing according to a query
export const has = function (target, queryOrPath) {
return find(target, queryOrPath) !== undefined
}

const find = function (target, queryOrPath) {
// eslint-disable-next-line fp/no-loops
for (const { missing } of iterate(target, queryOrPath)) {
for (const { value, missing } of iterate(target, queryOrPath)) {
// eslint-disable-next-line max-depth
if (!missing) {
return true
return { value }
}
}

return false
}

0 comments on commit 27fa428

Please sign in to comment.