easy-api.ts
Version:
A powerful library to create your own API with ease.
158 lines (157 loc) • 4.97 kB
TypeScript
import { type BaseAPIFunction } from "../managers/FunctionManager";
import { SKRSContext2D } from "@napi-rs/canvas";
import { Data } from "../structures/Data";
/**
* The information of a collected file.
* @example
* const file: ICollectedFile = {
* name: 'PHOTO_2021-09-01_12-00-00',
* path: 'C:/Users/username/Pictures/PHOTO_2021-09-01_12-00-00.png',
* extension: 'png'
* }
*/
export interface ICollectedFile {
/**
* The name of the file.
* @example
* 'PHOTO_2021-09-01_12-00-00'
*/
name: string;
/**
* The path of the file.
* @example
* 'C:/Users/username/Pictures/PHOTO_2021-09-01_12-00-00.png'
*/
path: string;
/**
* The extension of the file.
* @example
* 'png'
*/
extension: string;
}
export declare class Util {
/**
* Check whether brackets are balanced in code.
* @param code - Code to be checked.
* @returns {boolean}
*/
static areBracketsBalanced(code: string): boolean;
/**
* Converts the given arg to boolean.
* @param value - Value to be parsed.
* @returns {boolean}
*/
static booleanify(value: string): boolean;
/**
* Clones the given argument.
* @param pairs - Value to be cloned.
*/
static clone<T>(pairs: T): T | T[] | Map<any, any> | Set<any>;
/**
* @template T
* Fallbacks a value to null.
* @param value - The value to be returned.
* @returns {T | string}
*/
static fallbackNullString<T>(value?: T): "null" | NonNullable<T>;
/**
* Fills a canvas text.
* @param ctx - Canvas context.
* @param mytext - Text to be filled in the canvas.
* @param x - X text position.
* @param y - Y text position.
* @param width - Textbox width.
* @param height - Textbox height.
* @param align - Text align.
* @param vAlign - Text vertical align.
*/
static fillText(ctx: SKRSContext2D, mytext: string, x: number, y: number, width: number, height: number, align: string, vAlign: string): void;
/**
* Get the height of a canvas text.
* @param ctx - Canvas context.
* @param text - Text to be analyzed.
* @param style - Text style.
*/
static getTextHeight(ctx: SKRSContext2D, text: string, style: string): number;
/**
* Generates a random string.
* @param length - The length of the string.
* @returns {string}
*/
static hash(length?: number): string;
/**
* Check whether the given object is a valid function structure.
* @param data - The data to be validated.
* @returns {data is BaseAPIFunction}
*/
static isFunctionLike(data: any): data is BaseAPIFunction;
/**
* Parse a object.
* @param json - String object to be parsed.
*/
static loadObject<T>(json: string): T | null;
/**
* @param ctx - Canvas context.
* @param x - X position.
* @param y - Y position.
* @param width - Square width.
* @param height - Square height.
* @param radius - Square corner radius.
*/
static molde(ctx: SKRSContext2D, x: number, y: number, width: number, height: number, radius: number): void;
/**
* Check whether given arg is number.
* @param num - String number to be checked.
* @returns {boolean}
*/
static isNumber(num: string): boolean;
/**
* Check if the given arg is a valid hexadecimal code.
* @param value - Code to be tested.
* @returns {boolean}
*/
static isValidHex(value: string): boolean;
/**
* Parses a string-like value.
* @param text - String to be parsed.
*/
static parse(text: string): bigint | boolean | null | undefined;
/**
* Parses an array like value.
* @param arg - Value to be parsed.
* @returns {string[]}
*/
static parseArrayLike(arg: string): string[] | null;
/**
* Returns the compilation string from an input code.
* @param d - Interpreter data.
* @param code - Code to be resolved.
* @param returnType - Resolution return type.
* @returns
*/
static resolveCode<T>(d: Data, code: string, returnType?: "data" | "code"): Promise<T>;
/**
* Converts a integer to decimal fraction.
* @param value - Number to be converted.
* @returns {number}
*/
static resolvePercent(value: number): number;
/**
* Represents an array-like split pattern.
*/
static SPLIT_PATTERN: RegExp;
/**
* Returns a string representation of a boolean value.
* @param value - Value to be converted.
* @returns {string}
*/
static stringBool(value: boolean): string;
/**
* Collect all files inside a directory.
* @param path - Path to be collected.
* @param cb - Callback function.
* @returns {ICollectedFile[]}
*/
static recursiveCollectFiles(path: string, cb?: (file: string) => boolean): ICollectedFile[];
}