| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|---|
| 4 |
|
|---|
| 5 | const flattenDepth = require('./flattenDepth.js');
|
|---|
| 6 | const isIndex = require('../_internal/isIndex.js');
|
|---|
| 7 | const isKey = require('../_internal/isKey.js');
|
|---|
| 8 | const toKey = require('../_internal/toKey.js');
|
|---|
| 9 | const at = require('../object/at.js');
|
|---|
| 10 | const unset = require('../object/unset.js');
|
|---|
| 11 | const isArray = require('../predicate/isArray.js');
|
|---|
| 12 | const toPath = require('../util/toPath.js');
|
|---|
| 13 |
|
|---|
| 14 | function pullAt(array, ..._indices) {
|
|---|
| 15 | const indices = flattenDepth.flattenDepth(_indices, 1);
|
|---|
| 16 | if (!array) {
|
|---|
| 17 | return Array(indices.length);
|
|---|
| 18 | }
|
|---|
| 19 | const result = at.at(array, indices);
|
|---|
| 20 | const indicesToPull = indices
|
|---|
| 21 | .map(index => (isIndex.isIndex(index, array.length) ? Number(index) : index))
|
|---|
| 22 | .sort((a, b) => b - a);
|
|---|
| 23 | for (const index of new Set(indicesToPull)) {
|
|---|
| 24 | if (isIndex.isIndex(index, array.length)) {
|
|---|
| 25 | Array.prototype.splice.call(array, index, 1);
|
|---|
| 26 | continue;
|
|---|
| 27 | }
|
|---|
| 28 | if (isKey.isKey(index, array)) {
|
|---|
| 29 | delete array[toKey.toKey(index)];
|
|---|
| 30 | continue;
|
|---|
| 31 | }
|
|---|
| 32 | const path = isArray.isArray(index) ? index : toPath.toPath(index);
|
|---|
| 33 | unset.unset(array, path);
|
|---|
| 34 | }
|
|---|
| 35 | return result;
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | exports.pullAt = pullAt;
|
|---|