Skip to content

Commit

Permalink
Add entries to get() and has()
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Mar 20, 2022
1 parent d07fcff commit ec83ce7
Showing 1 changed file with 7 additions and 22 deletions.
29 changes: 7 additions & 22 deletions src/config/normalize/lib/wild_wild_path/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,46 +36,31 @@ export const list = function (
export const get = function (
target,
query,
{ childFirst, roots, leaves, sort, classes, inherited } = {},
{ childFirst, roots, leaves, sort, entries, classes, inherited } = {},
) {
const entry = getEntry(target, query, {
return iterate(target, query, {
childFirst,
roots,
leaves,
sort,
entries,
missing: false,
classes,
inherited,
})
return entry === undefined ? undefined : entry.value
}).next().value
}

// Check if a property is not missing according to a query
export const has = function (target, query, { classes, inherited } = {}) {
return (
getEntry(target, query, {
get(target, query, {
childFirst: false,
roots: false,
leaves: false,
sort: false,
entries: true,
classes,
inherited,
}) !== undefined
)
}

// Find the first non-missing entry
const getEntry = function (
target,
query,
{ childFirst, roots, leaves, sort, classes, inherited },
) {
return iterate(target, query, {
childFirst,
roots,
leaves,
sort,
missing: false,
classes,
inherited,
}).next().value
}

0 comments on commit ec83ce7

Please sign in to comment.