@vitejs/plugin-rsc
Version:
React Server Components (RSC) support for Vite.
65 lines (64 loc) • 2.13 kB
JavaScript
//#region ../../node_modules/.pnpm/@hiogawa+utils@1.7.0/node_modules/@hiogawa/utils/dist/index.js
function tinyassert(value, message) {
if (value) return;
if (message instanceof Error) throw message;
throw new TinyAssertionError(message, tinyassert);
}
var TinyAssertionError = class extends Error {
constructor(message, stackStartFunction) {
super(message ?? "TinyAssertionError");
if (stackStartFunction && "captureStackTrace" in Error) Error.captureStackTrace(this, stackStartFunction);
}
};
function safeFunctionCast(f) {
return f;
}
function once(f) {
let result;
let called = false;
return safeFunctionCast(function(...args) {
if (!called) {
result = f.apply(this, args);
called = true;
}
return result;
});
}
function memoize(f, options) {
const keyFn = options?.keyFn ?? ((...args) => args[0]);
const cache = options?.cache ?? /* @__PURE__ */ new Map();
return safeFunctionCast(function(...args) {
const key = keyFn(...args);
const value = cache.get(key);
if (typeof value !== "undefined") return value;
const newValue = f.apply(this, args);
cache.set(key, newValue);
return newValue;
});
}
function escapeRegExp(input) {
return input.replace(/[/\-\\^$*+?.()|[\]{}]/g, "\\$&");
}
function createDebug(namespace) {
const pattern = createDebugPattern(namespace);
return (...args) => {
const flag = globalThis.process?.env?.["DEBUG"] ?? globalThis.__DEBUG;
if (typeof flag === "string" && pattern.test(flag)) {
let prefix = `\u22B3 ${namespace}`;
const stderr = globalThis?.process?.stderr;
if (stderr) {
if (stderr?.isTTY) prefix = `\x1B[1m${prefix}\x1B[22m`;
console.error(prefix, ...args);
} else console.debug(prefix, ...args);
}
};
}
function createDebugPattern(namespace) {
const parts = namespace.split(":");
const alts = [namespace];
for (let i = 1; i < parts.length; i++) alts.push(parts.slice(0, i).join(":") + ":*");
const pattern = alts.map((pattern2) => escapeRegExp(pattern2)).join("|");
return /* @__PURE__ */ new RegExp(`(^|,)(${pattern})($|,)`);
}
//#endregion
export { tinyassert as i, memoize as n, once as r, createDebug as t };