easy-api.ts
Version:
A powerful library to create your own API with ease.
1 lines • 1.13 kB
JavaScript
Object.defineProperty(exports,"__esModule",{value:!0});let tslib_1=require("tslib"),APIFunction_1=require("../../classes/structures/APIFunction"),Error_1=require("../../classes/structures/Error"),Util_1=require("../../classes/internal/Util"),fs_1=tslib_1.__importDefault(require("fs"));class FileSize extends APIFunction_1.APIFunction{name="$fileSize";description="Returns the file size.";parameters=[{name:"Path",description:"The path of the file to be checked.",type:APIFunction_1.ParamType.String,required:!0,rest:!1,defaultValue:null},{name:"Decimals",description:"How many decimals for the file size number.",type:APIFunction_1.ParamType.Number,required:!1,rest:!1,defaultValue:"2"}];usage="$fileSize[path;decimals?]";returns=APIFunction_1.ParamType.Number;compile=!0;aliases=[];async run(e,[r,t="2"]){if(!Util_1.Util.isNumber(t))throw new Error_1.EATS_Error("Invalid number in: "+e.function?.name);try{return(fs_1.default.statSync(r).size/1024).toFixed(Number(t)).toString()}catch(r){throw new Error_1.EATS_Error(["Unable to check the file path: "+e.function?.name,"with reason: "+r].join("\n"))}}}exports.default=FileSize;