Skip to content

Commit

Permalink
Add pick()
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Mar 6, 2022
1 parent c26b3a9 commit 7b2168d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/config/normalize/lib/star_dot_path_utils/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { map } from './map.js'
export { pick } from './pick.js'
11 changes: 11 additions & 0 deletions src/config/normalize/lib/star_dot_path_utils/pick.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { list, set } from '../star_dot_path/main.js'

// Returns an object with only the properties being queried.
export const pick = function (target, queryOrPath) {
const entries = list(target, queryOrPath)
return entries.reduce(pickEntry, {})
}

const pickEntry = function (target, { path, value }) {
return set(target, path, value)
}

0 comments on commit 7b2168d

Please sign in to comment.