Skip to content

Commit

Permalink
Add pure annotations & tree shaking
Browse files Browse the repository at this point in the history
  • Loading branch information
Zerthox committed Jan 13, 2022
1 parent 464c2d1 commit d891a79
Show file tree
Hide file tree
Showing 9 changed files with 518 additions and 242 deletions.
239 changes: 0 additions & 239 deletions discordium/api/finder.ts

This file was deleted.

26 changes: 26 additions & 0 deletions discordium/api/finder/filters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {Exports} from "./raw";

export const byExports = (exported: Exports) => {
return (target) => target === exported || (target instanceof Object && Object.values(target).includes(exported));
};

export const byName = (name: string) => {
return (target) => target instanceof Object && Object.values(target).some(byDisplayName(name) as any);
};

export const byDisplayName = (name: string) => {
return (target: any) => target?.displayName === name || target?.constructor?.displayName === name;
};

export const byProps = (props: string[]) => {
return (target) => target instanceof Object && props.every((prop) => prop in target);
};

export const byProtos = (protos: string[]) => {
return (target: any) => target instanceof Object && target.prototype instanceof Object && protos.every((proto) => proto in target.prototype);
};

export const bySource = (contents: string[]) => {
// TODO: allow regex?
return (target) => target instanceof Function && contents.every((content) => target.toString().includes(content));
};
Loading

0 comments on commit d891a79

Please sign in to comment.