Skip to content

Commit

Permalink
Add include()
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Mar 6, 2022
1 parent 0e5cec8 commit aae6aeb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/config/normalize/lib/wild_wild_path_utils/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { exclude } from './exclude.js'
export { map } from './map.js'
export { pick } from './pick.js'
export { pick, include } from './pick.js'
16 changes: 16 additions & 0 deletions src/config/normalize/lib/wild_wild_path_utils/pick.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,19 @@ export const pick = function (target, queryOrPath) {
const pickEntry = function (target, { path, value }) {
return set(target, path, value)
}

// Remove values matching a query
export const include = function (target, queryOrPath, condition) {
const entries = listExisting(target, queryOrPath)
return entries.reduce(includeEntry.bind(undefined, condition), {})
}

const includeEntry = function (
condition,
target,
{ path, query, value, missing },
) {
return condition({ path, query, value, missing })
? set(target, path, value)
: target
}

0 comments on commit aae6aeb

Please sign in to comment.