UNPKG

easy-api.ts

Version:

A powerful library to create your own API with ease.

1 lines 1.47 kB
Object.defineProperty(exports,"__esModule",{value:!0}),exports.FunctionManager=exports.overrides=void 0;let tslib_1=require("tslib"),APIFunction_1=require("../structures/APIFunction"),path_1=require("path"),fs_1=tslib_1.__importDefault(require("fs"));exports.overrides=[];class FunctionManager extends Map{#injections;constructor(e){super(e),this.#injections={}}add(e,t){return e=e.startsWith("$")?e.toLowerCase():"$".concat(e.toLowerCase()),super.has(e)&&exports.overrides.push(e),super.set(e,t),this}inject(e,t,s){e=e.startsWith("$")?e:"$"+e,t=t.startsWith("$")?t:"$"+t,this.#injections[e.toLowerCase()]={[""+t.toLowerCase()]:s}}getTargettedInjections(e){return e=e.startsWith("$")?e:"$"+e,this.#injections[e.toLowerCase()]}load(e=(0,path_1.join)(__dirname,"../../functions"),s){e.includes(process.cwd())&&(e=e.replace(process.cwd(),""));var i,r=process.cwd();for(i of fs_1.default.readdirSync((0,path_1.join)(r,e)))if(!i.endsWith("d.ts"))if(fs_1.default.lstatSync((0,path_1.join)(r,e,i)).isFile()&&i.endsWith(".js")){let t=new(require((0,path_1.join)(r,e,i)).default);t&&(t.init(),void 0!==s&&!0===s(t)?(this.add(t.name,t),t.aliases?.length&&t.aliases.forEach(e=>this.add(e,t))):t.parent instanceof APIFunction_1.APIFunction||(this.add(t.name,t),t.aliases?.length&&t.aliases.forEach(e=>this.add(e,t))))}else this.load((0,path_1.join)(e,i))}toArray(){return Array.from(super.values())}get injections(){return this.#injections}}exports.FunctionManager=FunctionManager;