Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Mar 20, 2022
1 parent 35ff0d1 commit 0150956
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/config/normalize/lib/wild_wild_utils/merge.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { map } from './map.js'

// Like `set()` but push an array of values to the target array instead
// eslint-disable-next-line max-params
export const push = function (target, query, newValue, opts = {}) {
const mapFunc = pushValue.bind(undefined, newValue)
return map(target, query, mapFunc, { ...opts, entries: false })
const pushUnshift = function (mapFunc, target, query, newValue, opts = {}) {
return map(target, query, mapFunc.bind(undefined, newValue), {
...opts,
entries: false,
})
}

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 })
}
// Like `set()` but push an array of values to the target array instead
export const push = pushUnshift.bind(undefined, pushValue)

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

// Like `push()` but from the beginning
export const unshift = pushUnshift.bind(undefined, unshiftValue)

0 comments on commit 0150956

Please sign in to comment.