Files
Vlad Durnea cffdf8af86
Some checks failed
CI/CD Pipeline / unit-tests (push) Failing after 1m16s
CI/CD Pipeline / integration-tests (push) Failing after 2m32s
CI/CD Pipeline / lint (push) Successful in 5m22s
CI/CD Pipeline / e2e-tests (push) Has been skipped
CI/CD Pipeline / build (push) Has been skipped
wip:milestone 0 fixes
2026-03-15 12:35:42 +02:00

120 lines
3.5 KiB
JavaScript

import '@vitest/utils';
function collectOwnProperties(obj, collector) {
const collect = typeof collector === "function" ? collector : (key) => collector.add(key);
Object.getOwnPropertyNames(obj).forEach(collect);
Object.getOwnPropertySymbols(obj).forEach(collect);
}
function groupBy(collection, iteratee) {
return collection.reduce((acc, item) => {
const key = iteratee(item);
acc[key] || (acc[key] = []);
acc[key].push(item);
return acc;
}, {});
}
function isPrimitive(value) {
return value === null || typeof value !== "function" && typeof value !== "object";
}
function getAllMockableProperties(obj, isModule, constructors) {
const {
Map,
Object: Object2,
Function,
RegExp: RegExp2,
Array: Array2
} = constructors;
const allProps = new Map();
let curr = obj;
do {
if (curr === Object2.prototype || curr === Function.prototype || curr === RegExp2.prototype)
break;
collectOwnProperties(curr, (key) => {
const descriptor = Object2.getOwnPropertyDescriptor(curr, key);
if (descriptor)
allProps.set(key, { key, descriptor });
});
} while (curr = Object2.getPrototypeOf(curr));
if (isModule && !allProps.has("default") && "default" in obj) {
const descriptor = Object2.getOwnPropertyDescriptor(obj, "default");
if (descriptor)
allProps.set("default", { key: "default", descriptor });
}
return Array2.from(allProps.values());
}
function slash(str) {
return str.replace(/\\/g, "/");
}
function noop() {
}
function toArray(array) {
if (array === null || array === void 0)
array = [];
if (Array.isArray(array))
return array;
return [array];
}
function toString(v) {
return Object.prototype.toString.call(v);
}
function isPlainObject(val) {
return toString(val) === "[object Object]" && (!val.constructor || val.constructor.name === "Object");
}
function deepMerge(target, ...sources) {
if (!sources.length)
return target;
const source = sources.shift();
if (source === void 0)
return target;
if (isMergeableObject(target) && isMergeableObject(source)) {
Object.keys(source).forEach((key) => {
if (isMergeableObject(source[key])) {
if (!target[key])
target[key] = {};
deepMerge(target[key], source[key]);
} else {
target[key] = source[key];
}
});
}
return deepMerge(target, ...sources);
}
function isMergeableObject(item) {
return isPlainObject(item) && !Array.isArray(item);
}
function stdout() {
return console._stdout || process.stdout;
}
class AggregateErrorPonyfill extends Error {
errors;
constructor(errors, message = "") {
super(message);
this.errors = [...errors];
}
}
function isChildProcess() {
return typeof process !== "undefined" && !!process.send;
}
function setProcessTitle(title) {
try {
process.title = `node (${title})`;
} catch {
}
}
function escapeRegExp(s) {
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
function wildcardPatternToRegExp(pattern) {
return new RegExp(`^${pattern.split("*").map(escapeRegExp).join(".*")}$`, "i");
}
const urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
function nanoid(size = 21) {
let id = "";
let i = size;
while (i--)
id += urlAlphabet[Math.random() * 64 | 0];
return id;
}
export { AggregateErrorPonyfill as A, slash as a, isPrimitive as b, groupBy as c, deepMerge as d, nanoid as e, stdout as f, getAllMockableProperties as g, isChildProcess as i, noop as n, setProcessTitle as s, toArray as t, wildcardPatternToRegExp as w };