From b4742851803c10b4fa0ae76f850c953dfd85c90e Mon Sep 17 00:00:00 2001 From: OTKUSteyler <90369564+OTKUSteyler@users.noreply.github.com> Date: Wed, 10 Dec 2025 17:22:24 +0100 Subject: [PATCH] Delete utils directory --- utils/constants.ts | 15 ---- utils/cyrb64.ts | 29 ------- utils/findInReactTree.ts | 8 -- utils/findInTree.ts | 53 ------------ utils/hookDefineProperty.ts | 30 ------- utils/index.ts | 20 ----- utils/invariant.ts | 23 ----- utils/isValidHttpUrl.ts | 12 --- utils/lazy.ts | 166 ------------------------------------ utils/logger.ts | 15 ---- utils/safeFetch.ts | 16 ---- utils/types.ts | 1 - 12 files changed, 388 deletions(-) delete mode 100644 utils/constants.ts delete mode 100644 utils/cyrb64.ts delete mode 100644 utils/findInReactTree.ts delete mode 100644 utils/findInTree.ts delete mode 100644 utils/hookDefineProperty.ts delete mode 100644 utils/index.ts delete mode 100644 utils/invariant.ts delete mode 100644 utils/isValidHttpUrl.ts delete mode 100644 utils/lazy.ts delete mode 100644 utils/logger.ts delete mode 100644 utils/safeFetch.ts delete mode 100644 utils/types.ts diff --git a/utils/constants.ts b/utils/constants.ts deleted file mode 100644 index d1587b5..0000000 --- a/utils/constants.ts +++ /dev/null @@ -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"; diff --git a/utils/cyrb64.ts b/utils/cyrb64.ts deleted file mode 100644 index 23e3307..0000000 --- a/utils/cyrb64.ts +++ /dev/null @@ -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"); -} - diff --git a/utils/findInReactTree.ts b/utils/findInReactTree.ts deleted file mode 100644 index 29a2b4a..0000000 --- a/utils/findInReactTree.ts +++ /dev/null @@ -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"], - }); -} diff --git a/utils/findInTree.ts b/utils/findInTree.ts deleted file mode 100644 index 5dae4a8..0000000 --- a/utils/findInTree.ts +++ /dev/null @@ -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; -export type SearchFilter = (tree: SearchTree) => boolean; -export interface FindInTreeOptions { - walkable?: string[]; - ignore?: string[]; - maxDepth?: number; -} - -function treeSearch(tree: SearchTree, filter: SearchFilter, opts: Required, 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); -} diff --git a/utils/hookDefineProperty.ts b/utils/hookDefineProperty.ts deleted file mode 100644 index 1d2f156..0000000 --- a/utils/hookDefineProperty.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { LiteralUnion } from "type-fest"; - -type KeyOfOrAny = P extends keyof T ? T[P] : any; - -export default function hookDefineProperty< - T extends object, - P extends LiteralUnion ->(target: T, property: LiteralUnion, cb: (val: KeyOfOrAny) => KeyOfOrAny) { - 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; - }; -} diff --git a/utils/index.ts b/utils/index.ts deleted file mode 100644 index 75f6d25..0000000 --- a/utils/index.ts +++ /dev/null @@ -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 }; diff --git a/utils/invariant.ts b/utils/invariant.ts deleted file mode 100644 index 7dc4ea6..0000000 --- a/utils/invariant.ts +++ /dev/null @@ -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); -} diff --git a/utils/isValidHttpUrl.ts b/utils/isValidHttpUrl.ts deleted file mode 100644 index 067df3d..0000000 --- a/utils/isValidHttpUrl.ts +++ /dev/null @@ -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:"; -} diff --git a/utils/lazy.ts b/utils/lazy.ts deleted file mode 100644 index 3ad8a62..0000000 --- a/utils/lazy.ts +++ /dev/null @@ -1,166 +0,0 @@ -/* eslint-disable func-call-spacing */ - -type ExemptedEntries = Record; - -interface LazyOptions { - hint?: "function" | "object"; - exemptedEntries?: E; -} - -interface ContextHolder { - options: LazyOptions; - factory: any; -} - -const unconfigurable = new Set(["arguments", "caller", "prototype"]); -const isUnconfigurable = (key: PropertyKey) => - typeof key === "string" && unconfigurable.has(key); - -const factories = new WeakMap any>(); -const proxyContextHolder = new WeakMap(); - -const lazyHandler: ProxyHandler = { - ...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( - factory: () => T, - opts: LazyOptions = {}, -): 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, - I extends ExemptedEntries, ->(factory: () => T, opts: LazyOptions = {}): 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(obj: T): (() => T) | void { - return factories.get(obj) as (() => T) | void; -} diff --git a/utils/logger.ts b/utils/logger.ts deleted file mode 100644 index 67a161c..0000000 --- a/utils/logger.ts +++ /dev/null @@ -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"); diff --git a/utils/safeFetch.ts b/utils/safeFetch.ts deleted file mode 100644 index 45be8ad..0000000 --- a/utils/safeFetch.ts +++ /dev/null @@ -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; -} diff --git a/utils/types.ts b/utils/types.ts deleted file mode 100644 index 649532b..0000000 --- a/utils/types.ts +++ /dev/null @@ -1 +0,0 @@ -export type Nullish = null | undefined;