-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
10 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |