Delete utils directory

This commit is contained in:
OTKUSteyler 2025-12-10 17:22:24 +01:00
parent 0ac9ee6dd3
commit b474285180
12 changed files with 0 additions and 388 deletions

View file

@ -1,15 +0,0 @@
export const DISCORD_SERVER = "https://discord.gg/nQykFF9Ud6";
export const GITHUB = "https://github.com/kmmiio99o/ShiggyCord";
export const HTTP_REGEX =
/^https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_+.~#?&/=]*)$/;
export const HTTP_REGEX_MULTI =
/https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_+.~#?&\/=]*)/g;
export const NEXPID_PLUGINS_REPO_URL = "https://revenge.nexpid.xyz";
export const OFFICIAL_PLUGINS_REPO_URL =
"https://raw.githubusercontent.com/Purple-EyeZ/Plugins-List/refs/heads/main/src/plugins-data.json";
export const VD_PROXY_PREFIX = "https://vd-plugins.github.io/proxy";
export const VD_DISCORD_SERVER_ID = "1427396621905432699";
export const VD_PLUGINS_CHANNEL_ID = "1091880384561684561";
export const VD_THEMES_CHANNEL_ID = "1091880434939482202";

View file

@ -1,29 +0,0 @@
// cyrb53 (c) 2018 bryc (github.com/bryc). License: Public domain. Attribution appreciated.
// A fast and simple 64-bit (or 53-bit) string hash function with decent collision resistance.
// Largely inspired by MurmurHash2/3, but with a focus on speed/simplicity.
// See https://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript/52171480#52171480
// https://github.com/bryc/code/blob/master/jshash/experimental/cyrb53.js
export default function cyrb64(str: string, seed = 0) {
let h1 = 0xdeadbeef ^ seed, h2 = 0x41c6ce57 ^ seed;
for (let i = 0, ch; i < str.length; i++) {
ch = str.charCodeAt(i);
h1 = Math.imul(h1 ^ ch, 2654435761);
h2 = Math.imul(h2 ^ ch, 1597334677);
}
h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507);
h1 ^= Math.imul(h2 ^ (h2 >>> 13), 3266489909);
h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507);
h2 ^= Math.imul(h1 ^ (h1 >>> 13), 3266489909);
// For a single 53-bit numeric return value we could return
// 4294967296 * (2097151 & h2) + (h1 >>> 0);
// but we instead return the full 64-bit value:
return [h2 >>> 0, h1 >>> 0];
}
// An improved, *insecure* 64-bit hash that's short, fast, and has no dependencies.
// Output is always 14 characters.
export function cyrb64Hash(str: string, seed = 0) {
const [h2, h1] = cyrb64(str, seed);
return h2.toString(36).padStart(7, "0") + h1.toString(36).padStart(7, "0");
}

View file

@ -1,8 +0,0 @@
import { findInTree } from "@lib/utils";
import { SearchFilter } from "@lib/utils/findInTree";
export default function findInReactTree(tree: { [key: string]: any; }, filter: SearchFilter): any {
return findInTree(tree, filter, {
walkable: ["props", "children", "child", "sibling"],
});
}

View file

@ -1,53 +0,0 @@
// This has been completely reimplemented at this point, but the disclaimer at the end of disclaimers still counts.
// https://github.com/Cordwood/Cordwood/blob/91c0b971bbf05e112927df75415df99fa105e1e7/src/lib/utils/findInTree.ts
export type SearchTree = Record<string, any>;
export type SearchFilter = (tree: SearchTree) => boolean;
export interface FindInTreeOptions {
walkable?: string[];
ignore?: string[];
maxDepth?: number;
}
function treeSearch(tree: SearchTree, filter: SearchFilter, opts: Required<FindInTreeOptions>, depth: number): any {
if (depth > opts.maxDepth) return;
if (!tree) return;
try {
if (filter(tree)) return tree;
} catch { }
if (Array.isArray(tree)) {
for (const item of tree) {
if (typeof item !== "object" || item === null) continue;
try {
const found = treeSearch(item, filter, opts, depth + 1);
if (found) return found;
} catch { }
}
} else if (typeof tree === "object") {
for (const key of Object.keys(tree)) {
if (typeof tree[key] !== "object" || tree[key] === null) continue;
if (opts.walkable.length && !opts.walkable.includes(key)) continue;
if (opts.ignore.includes(key)) continue;
try {
const found = treeSearch(tree[key], filter, opts, depth + 1);
if (found) return found;
} catch { }
}
}
}
export default function findInTree(
tree: SearchTree,
filter: SearchFilter,
{
walkable = [],
ignore = [],
maxDepth = 100
}: FindInTreeOptions = {},
): any | undefined {
return treeSearch(tree, filter, { walkable, ignore, maxDepth }, 0);
}

View file

@ -1,30 +0,0 @@
import { LiteralUnion } from "type-fest";
type KeyOfOrAny<P, T extends object> = P extends keyof T ? T[P] : any;
export default function hookDefineProperty<
T extends object,
P extends LiteralUnion<keyof T, PropertyKey>
>(target: T, property: LiteralUnion<keyof T, PropertyKey>, cb: (val: KeyOfOrAny<P, T>) => KeyOfOrAny<P, T>) {
const targetAsAny = target as any;
if (property in target) {
return void cb(targetAsAny[property]);
}
let value: any;
Object.defineProperty(targetAsAny, property, {
get: () => value,
set(v) {
value = cb(v) ?? v;
},
configurable: true,
enumerable: false
});
return () => {
delete targetAsAny[property];
targetAsAny[property] = value;
};
}

View file

@ -1,20 +0,0 @@
import * as constants from "./constants";
import cyrb64 from "./cyrb64";
import findInReactTree from "./findInReactTree";
import findInTree from "./findInTree";
import hookDefineProperty from "./hookDefineProperty";
import invariant from "./invariant";
import * as lazy from "./lazy";
import * as logger from "./logger";
import safeFetch from "./safeFetch";
export {
constants,
cyrb64,
findInReactTree,
findInTree,
hookDefineProperty,
invariant,
lazy,
logger,
safeFetch };

View file

@ -1,23 +0,0 @@
/**
* `invariant` is used to [assert](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#assertion-functions) that the `condition` is [truthy](https://github.com/getify/You-Dont-Know-JS/blob/bdbe570600d4e1107d0b131787903ca1c9ec8140/up%20%26%20going/ch2.md#truthy--falsy).
* 💥 `invariant` will `throw` an `Error` if the `condition` is [falsey](https://github.com/getify/You-Dont-Know-JS/blob/bdbe570600d4e1107d0b131787903ca1c9ec8140/up%20%26%20going/ch2.md#truthy--falsy)
* 🤏 `message`s are not displayed in production environments to help keep bundles small
*
* ```ts
* const value: Person | null = { name: "Alex" };
* invariant(value, "Expected value to be a person");
* // type of `value`` has been narrowed to `Person`
* ```
*/
export default function invariant(
condition: any,
message?: string | (() => string),
): asserts condition {
if (condition) return;
const resolvedMessage: string | undefined = typeof message === "function" ? message() : message;
const prefix = "[Invariant Violation]";
const value = resolvedMessage ? `${prefix}: ${resolvedMessage}` : prefix;
throw new Error(value);
}

View file

@ -1,12 +0,0 @@
// https://stackoverflow.com/a/43467144/15031462
export default function isValidHttpUrl(input: string) {
let url: URL;
try {
url = new URL(input);
} catch {
return false;
}
return url.protocol === "http:" || url.protocol === "https:";
}

View file

@ -1,166 +0,0 @@
/* eslint-disable func-call-spacing */
type ExemptedEntries = Record<symbol | string, unknown>;
interface LazyOptions<E extends ExemptedEntries> {
hint?: "function" | "object";
exemptedEntries?: E;
}
interface ContextHolder {
options: LazyOptions<any>;
factory: any;
}
const unconfigurable = new Set(["arguments", "caller", "prototype"]);
const isUnconfigurable = (key: PropertyKey) =>
typeof key === "string" && unconfigurable.has(key);
const factories = new WeakMap<any, () => any>();
const proxyContextHolder = new WeakMap<any, ContextHolder>();
const lazyHandler: ProxyHandler<any> = {
...Object.fromEntries(
Object.getOwnPropertyNames(Reflect).map((fnName) => {
return [
fnName,
(target: any, ...args: any[]) => {
const contextHolder = proxyContextHolder.get(target);
const resolved = contextHolder?.factory();
if (!resolved)
throw new Error(
`Trying to Reflect.${fnName} of ${typeof resolved}`,
);
// @ts-expect-error
return Reflect[fnName](resolved, ...args);
},
];
}),
),
has(target, p) {
const contextHolder = proxyContextHolder.get(target);
if (contextHolder?.options) {
const { exemptedEntries: isolatedEntries } = contextHolder.options;
if (isolatedEntries && p in isolatedEntries) return true;
}
const resolved = contextHolder?.factory();
if (!resolved)
throw new Error(`Trying to Reflect.has of ${typeof resolved}`);
return Reflect.has(resolved, p);
},
get(target, p, receiver) {
if (__DEV__ && p === "__IS_BUNNY_LAZY_PROXY__") return true;
const contextHolder = proxyContextHolder.get(target);
if (contextHolder?.options) {
const { exemptedEntries: isolatedEntries } = contextHolder.options;
if (isolatedEntries?.[p]) return isolatedEntries[p];
}
const resolved = contextHolder?.factory();
if (!resolved)
throw new Error(`Trying to Reflect.get of ${typeof resolved}`);
return Reflect.get(resolved, p, receiver);
},
ownKeys: (target) => {
const contextHolder = proxyContextHolder.get(target);
const resolved = contextHolder?.factory();
if (!resolved)
throw new Error(`Trying to Reflect.ownKeys of ${typeof resolved}`);
const cacheKeys = Reflect.ownKeys(resolved);
unconfigurable.forEach(
(key) => !cacheKeys.includes(key) && cacheKeys.push(key),
);
return cacheKeys;
},
getOwnPropertyDescriptor: (target, p) => {
if (isUnconfigurable(p)) return Reflect.getOwnPropertyDescriptor(target, p);
const contextHolder = proxyContextHolder.get(target);
const resolved = contextHolder?.factory();
if (!resolved)
throw new Error(
`Trying to getOwnPropertyDescriptor of ${typeof resolved}`,
);
const descriptor = Reflect.getOwnPropertyDescriptor(resolved, p);
if (descriptor) Object.defineProperty(target, p, descriptor);
return descriptor;
},
};
/**
* Lazy proxy that will only call the factory function when needed (when a property is accessed)
* @param factory Factory function to create the object
* @param asFunction Mock the proxy as a function
* @returns A proxy that will call the factory function only when needed
* @example const ChannelStore = proxyLazy(() => findByProps("getChannelId"));
*/
export function proxyLazy<T, I extends ExemptedEntries>(
factory: () => T,
opts: LazyOptions<I> = {},
): T {
let cache: T;
const dummy = opts.hint !== "object" ? function () {} : {};
const proxyFactory = () => (cache ??= factory());
const proxy = new Proxy(dummy, lazyHandler) as T & I;
factories.set(proxy, proxyFactory);
// Use the proxyFactory in the context holder so the lazy handler calls the cached
// resolver instead of the raw factory. This avoids attempting to Reflect.* on
// an unresolved/undefined value when the original factory hasn't produced the object yet.
proxyContextHolder.set(dummy, {
factory: proxyFactory,
options: opts,
});
return proxy;
}
/**
* Lazily destructure an object with all the properties being lazified. This assumes all the properties are either an object or a function
* @param factory Factory function which resolves to the object (and caches it)
* @param asFunction Mock the proxy as a function
* @example
*
* const { uuid4 } = lazyDestructure(() => findByProps("uuid4"))
* uuid4; // <- is a lazy proxy!
*/
export function lazyDestructure<
T extends Record<PropertyKey, unknown>,
I extends ExemptedEntries,
>(factory: () => T, opts: LazyOptions<I> = {}): T {
const proxiedObject = proxyLazy(factory);
return new Proxy(
{},
{
get(_, property) {
if (property === Symbol.iterator) {
return function* () {
yield proxiedObject;
yield new Proxy(
{},
{
get: (_, p) => proxyLazy(() => proxiedObject[p], opts),
},
);
throw new Error(
"This is not a real iterator, this is likely used incorrectly",
);
};
}
return proxyLazy(() => proxiedObject[property], opts);
},
},
) as T;
}
export function getProxyFactory<T>(obj: T): (() => T) | void {
return factories.get(obj) as (() => T) | void;
}

View file

@ -1,15 +0,0 @@
import { findByNameLazy } from "@metro/wrappers";
type LoggerFunction = (...messages: any[]) => void;
export interface Logger {
log: LoggerFunction;
info: LoggerFunction;
warn: LoggerFunction;
error: LoggerFunction;
time: LoggerFunction;
trace: LoggerFunction;
verbose: LoggerFunction;
}
export const LoggerClass = findByNameLazy("Logger");
export const logger: Logger = new LoggerClass("ShiggyCord");

View file

@ -1,16 +0,0 @@
// A really basic fetch wrapper which throws on non-ok response codes
export default async function safeFetch(input: RequestInfo | URL, options?: RequestInit, timeout = 10000) {
const req = await fetch(input, {
signal: timeoutSignal(timeout),
...options
});
if (!req.ok) throw new Error(`Request returned non-ok: ${req.status} ${req.statusText}`);
return req;
}
function timeoutSignal(ms: number): AbortSignal {
const controller = new AbortController();
setTimeout(() => controller.abort(`Timed out after ${ms}ms`), ms);
return controller.signal;
}

View file

@ -1 +0,0 @@
export type Nullish = null | undefined;