Skip to content

Commit

Permalink
Add unshift()
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Mar 20, 2022
1 parent d3a7017 commit 35ff0d1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/config/normalize/lib/wild_wild_utils/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { find } from './find.js'
export { pick, include, exclude } from './include/main.js'
export { map } from './map.js'
export { push } from './merge.js'
export { push, unshift } from './merge.js'
11 changes: 11 additions & 0 deletions src/config/normalize/lib/wild_wild_utils/merge.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,14 @@ export const push = function (target, query, newValue, opts = {}) {
const pushValue = function (newValue, value) {
return Array.isArray(value) ? [...value, ...newValue] : newValue
}

// Like `push()` but from the beginning
// eslint-disable-next-line max-params
export const unshift = function (target, query, newValue, opts = {}) {
const mapFunc = unshiftValue.bind(undefined, newValue)
return map(target, query, mapFunc, { ...opts, entries: false })
}

const unshiftValue = function (newValue, value) {
return Array.isArray(value) ? [...newValue, ...value] : newValue
}

0 comments on commit 35ff0d1

Please sign in to comment.