mirror of
https://github.com/CharaChorder/DeviceManager.git
synced 2026-01-15 22:42:52 +00:00
115 lines
3.7 KiB
JavaScript
115 lines
3.7 KiB
JavaScript
export { assertTypes, clone, createDefer, deepClone, getCallLastIndex, getOwnProperties, getType, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray } from './helpers.js';
|
|
export { f as format, i as inspect, o as objDisplay, s as stringify } from './chunk-display.js';
|
|
import { S as SAFE_TIMERS_SYMBOL } from './chunk-colors.js';
|
|
export { a as SAFE_COLORS_SYMBOL, c as createColors, b as getColors, g as getDefaultColors, s as setupColors } from './chunk-colors.js';
|
|
import 'pretty-format';
|
|
import 'loupe';
|
|
|
|
function getSafeTimers() {
|
|
const {
|
|
setTimeout: safeSetTimeout,
|
|
setInterval: safeSetInterval,
|
|
clearInterval: safeClearInterval,
|
|
clearTimeout: safeClearTimeout,
|
|
setImmediate: safeSetImmediate,
|
|
clearImmediate: safeClearImmediate
|
|
} = globalThis[SAFE_TIMERS_SYMBOL] || globalThis;
|
|
const {
|
|
nextTick: safeNextTick
|
|
} = globalThis[SAFE_TIMERS_SYMBOL] || globalThis.process || { nextTick: (cb) => cb() };
|
|
return {
|
|
nextTick: safeNextTick,
|
|
setTimeout: safeSetTimeout,
|
|
setInterval: safeSetInterval,
|
|
clearInterval: safeClearInterval,
|
|
clearTimeout: safeClearTimeout,
|
|
setImmediate: safeSetImmediate,
|
|
clearImmediate: safeClearImmediate
|
|
};
|
|
}
|
|
function setSafeTimers() {
|
|
const {
|
|
setTimeout: safeSetTimeout,
|
|
setInterval: safeSetInterval,
|
|
clearInterval: safeClearInterval,
|
|
clearTimeout: safeClearTimeout,
|
|
setImmediate: safeSetImmediate,
|
|
clearImmediate: safeClearImmediate
|
|
} = globalThis;
|
|
const {
|
|
nextTick: safeNextTick
|
|
} = globalThis.process || { nextTick: (cb) => cb() };
|
|
const timers = {
|
|
nextTick: safeNextTick,
|
|
setTimeout: safeSetTimeout,
|
|
setInterval: safeSetInterval,
|
|
clearInterval: safeClearInterval,
|
|
clearTimeout: safeClearTimeout,
|
|
setImmediate: safeSetImmediate,
|
|
clearImmediate: safeClearImmediate
|
|
};
|
|
globalThis[SAFE_TIMERS_SYMBOL] = timers;
|
|
}
|
|
|
|
const RealDate = Date;
|
|
function random(seed) {
|
|
const x = Math.sin(seed++) * 1e4;
|
|
return x - Math.floor(x);
|
|
}
|
|
function shuffle(array, seed = RealDate.now()) {
|
|
let length = array.length;
|
|
while (length) {
|
|
const index = Math.floor(random(seed) * length--);
|
|
const previous = array[length];
|
|
array[length] = array[index];
|
|
array[index] = previous;
|
|
++seed;
|
|
}
|
|
return array;
|
|
}
|
|
|
|
function createSimpleStackTrace(options) {
|
|
const { message = "error", stackTraceLimit = 1 } = options || {};
|
|
const limit = Error.stackTraceLimit;
|
|
const prepareStackTrace = Error.prepareStackTrace;
|
|
Error.stackTraceLimit = stackTraceLimit;
|
|
Error.prepareStackTrace = (e) => e.stack;
|
|
const err = new Error(message);
|
|
const stackTrace = err.stack || "";
|
|
Error.prepareStackTrace = prepareStackTrace;
|
|
Error.stackTraceLimit = limit;
|
|
return stackTrace;
|
|
}
|
|
|
|
const lineSplitRE = /\r?\n/;
|
|
function positionToOffset(source, lineNumber, columnNumber) {
|
|
const lines = source.split(lineSplitRE);
|
|
const nl = /\r\n/.test(source) ? 2 : 1;
|
|
let start = 0;
|
|
if (lineNumber > lines.length)
|
|
return source.length;
|
|
for (let i = 0; i < lineNumber - 1; i++)
|
|
start += lines[i].length + nl;
|
|
return start + columnNumber;
|
|
}
|
|
function offsetToLineNumber(source, offset) {
|
|
if (offset > source.length) {
|
|
throw new Error(
|
|
`offset is longer than source length! offset ${offset} > length ${source.length}`
|
|
);
|
|
}
|
|
const lines = source.split(lineSplitRE);
|
|
const nl = /\r\n/.test(source) ? 2 : 1;
|
|
let counted = 0;
|
|
let line = 0;
|
|
for (; line < lines.length; line++) {
|
|
const lineLength = lines[line].length + nl;
|
|
if (counted + lineLength >= offset)
|
|
break;
|
|
counted += lineLength;
|
|
}
|
|
return line + 1;
|
|
}
|
|
|
|
export { SAFE_TIMERS_SYMBOL, createSimpleStackTrace, getSafeTimers, lineSplitRE, offsetToLineNumber, positionToOffset, setSafeTimers, shuffle };
|