[Utils > without] Move to util

This commit is contained in:
Beef 2023-04-09 19:53:26 +01:00
parent f89238cfce
commit c4a25744d4
4 changed files with 13 additions and 12 deletions

1
src/def.d.ts vendored
View file

@ -390,6 +390,7 @@ interface VendettaObject {
findInTree: (tree: SearchTree, filter: SearchFilter, options: FindInTreeOptions) => any; findInTree: (tree: SearchTree, filter: SearchFilter, options: FindInTreeOptions) => any;
safeFetch: (input: RequestInfo | URL, options?: RequestInit) => Promise<Response>; safeFetch: (input: RequestInfo | URL, options?: RequestInit) => Promise<Response>;
unfreeze: (obj: object) => object; unfreeze: (obj: object) => object;
without: <O extends object, K extends readonly (keyof O)[]>(object: O, ...keys: K) => Omit<O, typeof keys[number]>;
}; };
debug: { debug: {
connectToDebugger: (url: string) => void; connectToDebugger: (url: string) => void;

View file

@ -3,3 +3,4 @@ export { default as findInReactTree } from "@utils/findInReactTree";
export { default as findInTree } from "@utils/findInTree"; export { default as findInTree } from "@utils/findInTree";
export { default as safeFetch } from "@utils/safeFetch"; export { default as safeFetch } from "@utils/safeFetch";
export { default as unfreeze } from "@utils/unfreeze"; export { default as unfreeze } from "@utils/unfreeze";
export { default as without } from "@utils/without";

5
src/lib/utils/without.ts Normal file
View file

@ -0,0 +1,5 @@
export default function without<O extends object, K extends readonly (keyof O)[]>(object: O, ...keys: K): Omit<O, typeof keys[number]> {
const cloned = { ...object };
keys.forEach((k) => delete cloned[k]);
return cloned;
}

View file

@ -17,18 +17,12 @@ import * as assets from "@ui/assets";
import * as color from "@ui/color"; import * as color from "@ui/color";
import * as utils from "@utils"; import * as utils from "@utils";
function without<O extends object, K extends readonly (keyof O)[]>(object: O, ...keys: K): Omit<O, typeof keys[number]> {
const cloned = { ...object };
keys.forEach((k) => delete cloned[k]);
return cloned;
}
export default async (unloads: any[]): Promise<VendettaObject> => ({ export default async (unloads: any[]): Promise<VendettaObject> => ({
patcher: without(patcher, "unpatchAll"), patcher: utils.without(patcher, "unpatchAll"),
metro: { ...metro, common: { ...common } }, metro: { ...metro, common: { ...common } },
constants, constants,
utils, utils,
debug: without(debug, "versionHash", "patchLogHook"), debug: utils.without(debug, "versionHash", "patchLogHook"),
ui: { ui: {
components, components,
toasts, toasts,
@ -36,9 +30,9 @@ export default async (unloads: any[]): Promise<VendettaObject> => ({
assets, assets,
...color, ...color,
}, },
plugins: without(plugins, "initPlugins", "evalPlugin"), plugins: utils.without(plugins, "initPlugins", "evalPlugin"),
themes: without(themes, "initThemes"), themes: utils.without(themes, "initThemes"),
commands: without(commands, "patchCommands"), commands: utils.without(commands, "patchCommands"),
storage, storage,
settings, settings,
loader: { loader: {