From c10355ef707b41ad75848bc9a41426d0b1bfaccc Mon Sep 17 00:00:00 2001 From: Beef Date: Tue, 4 Apr 2023 19:45:53 +0100 Subject: [PATCH] [Metro] Implement findByTypeName(All) --- src/def.d.ts | 2 ++ src/lib/metro/filters.ts | 3 +++ 2 files changed, 5 insertions(+) diff --git a/src/def.d.ts b/src/def.d.ts index 35a34c9..cd2d1dc 100644 --- a/src/def.d.ts +++ b/src/def.d.ts @@ -346,6 +346,8 @@ interface VendettaObject { findByNameAll: (name: string, defaultExp?: boolean) => any[]; findByDisplayName: (displayName: string, defaultExp?: boolean) => any; findByDisplayNameAll: (displayName: string, defaultExp?: boolean) => any[]; + findByTypeName: (typeName: string, defaultExp?: boolean) => any; + findByTypeNameAll: (typeName: string, defaultExp?: boolean) => any[]; findByStoreName: (name: string) => any; common: { constants: PropIntellisense<"API_HOST">; diff --git a/src/lib/metro/filters.ts b/src/lib/metro/filters.ts index a1bc1d1..59df4d1 100644 --- a/src/lib/metro/filters.ts +++ b/src/lib/metro/filters.ts @@ -66,6 +66,7 @@ export const findAll = filterModules(modules); const propsFilter = (props: (string | symbol)[]) => (m: any) => props.every((p) => m[p] !== undefined); const nameFilter = (name: string, defaultExp: boolean) => (defaultExp ? (m: any) => m?.name === name : (m: any) => m?.default?.name === name); const dNameFilter = (displayName: string, defaultExp: boolean) => (defaultExp ? (m: any) => m?.displayName === displayName : (m: any) => m?.default?.displayName === displayName); +const tNameFilter = (typeName: string, defaultExp: boolean) => (defaultExp ? (m: any) => m?.type?.name === typeName : (m: any) => m?.default?.type?.name === typeName); const storeFilter = (name: string) => (m: any) => m.getName && m.getName.length === 0 && m.getName() === name; export const findByProps: PropsFinder = (...props) => find(propsFilter(props)); @@ -74,4 +75,6 @@ export const findByName = (name: string, defaultExp = true) => find(nameFilter(n export const findByNameAll = (name: string, defaultExp = true) => findAll(nameFilter(name, defaultExp)); export const findByDisplayName = (displayName: string, defaultExp = true) => find(dNameFilter(displayName, defaultExp)); export const findByDisplayNameAll = (displayName: string, defaultExp = true) => findAll(dNameFilter(displayName, defaultExp)); +export const findByTypeName = (typeName: string, defaultExp = true) => find(tNameFilter(typeName, defaultExp)); +export const findByTypeNameAll = (typeName: string, defaultExp = true) => findAll(tNameFilter(typeName, defaultExp)); export const findByStoreName = (name: string) => find(storeFilter(name)); \ No newline at end of file