Skip to content

Commit

Permalink
feat(classMapper): add class mapper
Browse files Browse the repository at this point in the history
thanks valve
  • Loading branch information
AAGaming00 committed Mar 9, 2024
1 parent 17b99df commit a8eeb91
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/class-mapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Module, findAllModules } from "./webpack";

export interface ClassModule {
[name: string]: string
};

export const classMap: ClassModule[] = findAllModules((m: Module) => {
if (typeof m == "object" && !m.__esModule) {
const keys = Object.keys(m);
// special case some libraries
if (keys.length == 1 && m.version) return false;
// special case localization
if (keys.length > 1000 && m.AboutSettings) return false;

return keys.length > 0 && keys.every(k => !Object.getOwnPropertyDescriptor(m, k)?.get && typeof m[k] == "string")
}
return false;
});

export function findClass(name: string): string | void {
return classMap.find(m => m?.[name])?.[name];
}

export function findClassModule(filter: (module: any) => boolean) : ClassModule | void {
return classMap.find(m => filter(m));
}

export function unminifyClass(minifiedClass: string): string | void {
for (let m of classMap) {
for (let className of Object.keys(m)) {
if (m[className] == minifiedClass) return className;
}
}
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export * from './deck-hooks';
export * from './plugin';
export * from './webpack';
export * from './utils';
export * from './class-mapper';

0 comments on commit a8eeb91

Please sign in to comment.