line_push/node_modules/webpack-external-import/webpack/utils.js
2022-07-17 13:16:16 +08:00

130 lines
3.3 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.mergeDeep = mergeDeep;
exports.removeNull = removeNull;
exports.getInterleaveConfig = void 0;
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
var mem = require("mem");
var getInterleaveConfig = mem(function () {
var pkgUp = require("pkg-up").sync();
var packageJson;
if (pkgUp) {
// eslint-disable-next-line import/no-dynamic-require
packageJson = require(pkgUp);
}
return packageJson.interleave || null;
});
/* eslint-disable no-param-reassign */
exports.getInterleaveConfig = getInterleaveConfig;
function mergeDeep() {
var isObject = function isObject(obj) {
return obj && _typeof(obj) === "object";
};
for (var _len = arguments.length, objects = new Array(_len), _key = 0; _key < _len; _key++) {
objects[_key] = arguments[_key];
}
return objects.reduce(function (prev, obj) {
Object.keys(obj).forEach(function (key) {
var pVal = prev[key];
var oVal = obj[key];
if (Array.isArray(pVal) && Array.isArray(oVal)) {
prev[key] = pVal.concat.apply(pVal, _toConsumableArray(oVal));
} else if (isObject(pVal) && isObject(oVal)) {
prev[key] = mergeDeep(pVal, oVal);
} else {
prev[key] = oVal;
}
});
return prev;
}, {});
}
/* eslint-enable no-param-reassign */
// TODO: delete this function in V2
function removeNull() {
var nullCount = 0;
var length = this.length;
for (var i = 0, len = this.length; i < len; i++) {
if (!this[i]) {
nullCount++;
}
} // no item is null
if (!nullCount) {
return this;
} // all items are null
if (nullCount === length) {
this.length = 0;
return this;
} // mix of null // non-null
var idest = 0;
var isrc = length - 1;
length -= nullCount;
while (nullCount) {
while (!this[isrc]) {
isrc--;
nullCount--;
} // find a non null (source) slot on the right
if (!nullCount) {
break;
} // break if found all null
while (this[idest]) {
idest++;
} // find one null slot on the left (destination)
// perform copy
this[idest] = this[isrc];
if (! --nullCount) {
break;
}
idest++;
isrc--;
}
this.length = length;
return this;
} // eslint-disable-next-line no-extend-native
Object.defineProperty(Array.prototype, "removeNull", {
value: removeNull,
writable: true,
configurable: true
});