Skip to content

Commit

Permalink
Improve get()
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Mar 6, 2022
1 parent 83482a7 commit c353683
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/config/normalize/lib/star_dot_path/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,15 @@ 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) {
const entries = listExistingEntries(target, queryOrPath)
return entries.length === 0 ? undefined : entries[0].value
const entry = listEntries(target, queryOrPath).find(isExisting)
return entry === undefined ? undefined : entry.value
}

// Check if a property is not missing according to a query
export const has = function (target, queryOrPath) {
return listEntries(target, queryOrPath).some(isExisting)
}

const listExistingEntries = function (target, queryOrPath) {
return listEntries(target, queryOrPath).filter(isExisting)
}

const isExisting = function ({ missing }) {
return !missing
}

0 comments on commit c353683

Please sign in to comment.