版博士V2.0程序
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

chunk-utils-base.b5ddfcc9.js 3.0 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. function isFinalObj(obj) {
  2. return obj === Object.prototype || obj === Function.prototype || obj === RegExp.prototype;
  3. }
  4. function collectOwnProperties(obj, collector) {
  5. const collect = typeof collector === "function" ? collector : (key) => collector.add(key);
  6. Object.getOwnPropertyNames(obj).forEach(collect);
  7. Object.getOwnPropertySymbols(obj).forEach(collect);
  8. }
  9. function groupBy(collection, iteratee) {
  10. return collection.reduce((acc, item) => {
  11. const key = iteratee(item);
  12. acc[key] || (acc[key] = []);
  13. acc[key].push(item);
  14. return acc;
  15. }, {});
  16. }
  17. function isPrimitive(value) {
  18. return value === null || typeof value !== "function" && typeof value !== "object";
  19. }
  20. function getAllMockableProperties(obj, isModule) {
  21. const allProps = /* @__PURE__ */ new Map();
  22. let curr = obj;
  23. do {
  24. if (isFinalObj(curr))
  25. break;
  26. collectOwnProperties(curr, (key) => {
  27. const descriptor = Object.getOwnPropertyDescriptor(curr, key);
  28. if (descriptor)
  29. allProps.set(key, { key, descriptor });
  30. });
  31. } while (curr = Object.getPrototypeOf(curr));
  32. if (isModule && !allProps.has("default") && "default" in obj) {
  33. const descriptor = Object.getOwnPropertyDescriptor(obj, "default");
  34. if (descriptor)
  35. allProps.set("default", { key: "default", descriptor });
  36. }
  37. return Array.from(allProps.values());
  38. }
  39. function notNullish(v) {
  40. return v != null;
  41. }
  42. function slash(str) {
  43. return str.replace(/\\/g, "/");
  44. }
  45. const noop = () => {
  46. };
  47. function toArray(array) {
  48. if (array === null || array === void 0)
  49. array = [];
  50. if (Array.isArray(array))
  51. return array;
  52. return [array];
  53. }
  54. const toString = (v) => Object.prototype.toString.call(v);
  55. const isPlainObject = (val) => toString(val) === "[object Object]" && (!val.constructor || val.constructor.name === "Object");
  56. function isObject(item) {
  57. return item != null && typeof item === "object" && !Array.isArray(item);
  58. }
  59. function deepMerge(target, ...sources) {
  60. if (!sources.length)
  61. return target;
  62. const source = sources.shift();
  63. if (source === void 0)
  64. return target;
  65. if (isMergeableObject(target) && isMergeableObject(source)) {
  66. Object.keys(source).forEach((key) => {
  67. if (isMergeableObject(source[key])) {
  68. if (!target[key])
  69. target[key] = {};
  70. deepMerge(target[key], source[key]);
  71. } else {
  72. target[key] = source[key];
  73. }
  74. });
  75. }
  76. return deepMerge(target, ...sources);
  77. }
  78. function isMergeableObject(item) {
  79. return isPlainObject(item) && !Array.isArray(item);
  80. }
  81. function stdout() {
  82. return console._stdout || process.stdout;
  83. }
  84. function getEnvironmentTransformMode(config, environment) {
  85. var _a, _b;
  86. if (!((_b = (_a = config.deps) == null ? void 0 : _a.experimentalOptimizer) == null ? void 0 : _b.enabled))
  87. return void 0;
  88. return environment === "happy-dom" || environment === "jsdom" ? "web" : "ssr";
  89. }
  90. export { isPrimitive as a, getEnvironmentTransformMode as b, noop as c, deepMerge as d, stdout as e, getAllMockableProperties as f, groupBy as g, isObject as i, notNullish as n, slash as s, toArray as t };