UNPKG

frontend-util-everything

Version:
669 lines (553 loc) 16.5 kB
declare module Util{ /** * Graph class implementation */ declare class Graph { /** * Adds a vertex to the graph. */ addVertex(vertex: any): void; /** * Adds an edge between two vertices in the graph. */ addEdge(vertex1: any, vertex2: any): void; /** * Removes an edge between two vertices in the graph. */ removeEdge(vertex1: any, vertex2: any): void; /** * Removes a vertex and all edges connected to it. */ removeVertex(vertex: any): void; /** * Grahp has vertex. * @returns True if the vertex exists, false otherwise. */ hasVertex(vertex: any): boolean; /** * Checks if two vertices are connected. * @returns True if the vertices are connected, false otherwise. */ isConnected(vertex1: any, vertex2: any): boolean; /** * Gets all edges in the graph. * @returns An array of edges. */ getEdges(): any[]; /** * bfs Gets all vertices in the graph. */ bfs(startVertex: any, callback: any): void; /** * dfs Gets all vertices in the graph. */ dfs(startVertex: any, callback: any): void; /** * Gets all vertices in the graph. * @returns An array of vertices. */ clear(): any[]; } /** * Node class */ declare class Node { } /** * LinkedList class */ declare class LinkedList { /** * @returns head of the linked list */ getHead(): Node; /** * @returns current node of the linked list */ getSize(): Node; /** * Adds a node to the end of the linked list. */ add(data: any): void; /** * Remove node from the linked list. */ remove(data: any): void; /** * Get the index of a node in the linked list. */ indexOf(data: any): number; /** * Check if the linked list contains a node. */ contains(data: any): boolean; /** * Get the node at the index. * @returns node at the index */ get(index: any): Node; /** * Insert a node at the index. */ insert(index: any, data: any): void; /** * Clears the linked list. */ clear(): void; } /** * Queue implementation using an array */ declare class Queue { /** * Adds an item to the queue. */ enqueue(item: any): void; /** * Removes the first item from the queue. * @returns The first item in the queue. */ dequeue(): any; /** * Gets the first item in the queue without removing it. * @returns The first item in the queue. */ isEmpty(): any; /** * Gets the first item in the queue without removing it. * @returns The first item in the queue. */ size(): any; /** * Gets the first item in the queue without removing it. * @returns The first item in the queue. */ has(): any; /** * Executes all items in the queue. */ execute(callback: any): void; /** * Clears ths Queus. * @returns void. */ clear(): any; } /** * Stack implementation in JavaScript */ declare class Stack { /** * Adds an item to the stack. */ push(element: any): void; /** * Removes the last item from the stack. * @returns The last item in the stack. */ pop(): any; /** * Gets the last item in the stack without removing it. * @returns The last item in the stack. */ peek(): any; /** * Checks if the stack is empty. * @returns True if the stack is empty, false otherwise. */ isEmpty(): boolean; /** * Gets the size of the stack. */ size(): number; /** * print stack. * @returns A string representation of the stack. */ printStack(): string; /** * Checks if the stack has an item. */ excute(callback: any): void; /** * Clears the stack. */ clear(): void; } /** * Generates an array of numbers starting from a given number. */ declare function generateNumbers(n: number, start?: number): any[]; /** * Flattens a nested array up to a specified depth. */ declare function flattenArray(arr: any[], depth?: number): any[]; /** * Removes duplicates from an array. */ declare function removeDuplicates(arr: any[], value: number): any[]; /** * Finds all the index of the first occurrence of a value in an array. */ declare function findAllIndexes(arr: any[], value: value): any[]; /** * Checks if an array is empty. */ declare function isEmptyArray(arr: any[]): boolean; /** * sorts an array in ascending order. */ declare function sortArrayAscending(arr: any[]): any[]; /** * sorts an array in descending order. */ declare function sortArrayDescending(arr: any[]): any[]; /** * bubble sort algorithm implementation. */ declare function bubbleSort(arr: any[]): any[]; /** * Removes all duplicate values from an array, returning a new array with unique values. */ declare function uniqueArray(arr: any[]): any[]; /** * Pauses execution for a specified number of milliseconds. */ declare function sleep(ms: number): Promise; /** * Executes an array of asynchronous functions in order, waiting for each to complete before starting the next. */ declare function executeAsyncFunctionsInOrder(functions: ((...params: any[]) => void)[]): Promise<void>; /** * Executes an array of asynchronous functions concurrently, waiting for all to complete. */ declare function executeAsyncFunctionsConcurrently(functions: ((...params: any[]) => void)[]): Promise<any[]>; /** * Runs an array of asynchronous tasks with a specified maximum concurrency. */ declare function runWithConcurrency(tasks: ((...params: any[]) => void)[], maxConcurrency: number): any[]; /** * Converts a synchronous function to an asynchronous one, allowing it to be used with async/await. */ declare function asyncify(fn: (...params: any[]) => any): Promise; /** * This file contains functions to get the current local date and time in various formats. * @returns Current local date and time in different formats */ declare function getCurrentLocalDateTime(): string; /** * This function returns the specific local date. */ declare function getSpecificLocalDateTime(date: Date): string; /** * This function returns the current local date. * @returns Current date in the format YYYY-MM-DD */ declare function getCurrentLocalDate(): string; /** * This function returns the specific date in the format YYYY/MM/DD. */ declare function getSpecificLocalDate(date: Date): string; /** * This function returns the current local time. * @returns Current time in the format HH:MM:SS */ declare function getCurrentLocalTime(): string; /** * This function returns the specific time in the format HH:MM:SS. */ declare function getSpecificTime(date: Date): string; /** * @returns Current UTC date */ declare function getUtcTime(): string; /** * This function returns the specific format date. */ declare function getFormattedDate(date: Date, format: string): string; /** * This function returns the specific format time. */ declare function getFormattedTime(date: Date, format: string): string; /** * This function returns the specific format date and time. */ declare function getSpecificDateTime(date: Date, format: string): string; /** * This function returns a relative time string based on the given date. * @returns Relative time string like "2 days ago", "1 hour ago", etc. */ declare function getRelativeTime(date: Date): string; /** * This function calculates the difference between two dates in the specified unit. * @param unit - 'day' |'hour'|'minute'|'second'|'year'|'month' * @returns Difference in the specified unit */ declare function dateDiff(date1: Date, date2: Date, unit?: string): number; /** * This function returns the first day of the month for a given date. */ declare function getFirstDayOfMonth(date: Date): Date; /** * This function returns the last day of the month for a given date. * @returns Last day of the month */ declare function getLastDayOfMonth(date: Date): number; /** * Gets the height of the DOM. * @returns The height of the DOM. */ declare function getDomHeight(): number; /** * Gets the width of the DOM. * @returns The width of the DOM. */ declare function getDomWidth(): number; /** * Gets the height of the viewport. * @returns The height of the viewport. */ declare function getViewportHeight(): number; /** * Gets the width of the viewport. * @returns The width of the viewport. */ declare function getViewportWidth(): number; /** * Gets the scroll top position of the document. * @returns The scroll top position of the document. */ declare function getScrollTop(): number; /** * Gets the scroll left position of the document. * @returns The scroll left position of the document. */ declare function getScrollLeft(): number; /** * Checks if the mouse is inside an element. */ declare function mouseInElement(element: HTMLElement, x: number, y: number): boolean; /** * Gets the mouse position relative to an element. */ declare function mousePositioninElement(element: HTMLElement, event: Event): any; /** * Gets the mouse position in document. */ declare function getMousePosition(event: Event): any; /** * Gets the real height of an element. */ declare function getRealElementHeight(element: HTMLElement): number; /** * Gets the real width of an element. */ declare function getRealElementWidth(element: HTMLElement): number; /** * Checks if an element is visible. */ declare function isElVisible(el: HTMLElement): boolean; /** * Removes an element from the DOM. */ declare function removeElement(el: HTMLElement): void; /** * Checks if an element has a child. */ declare function hasChild(el: HTMLElement, child: HTMLElement): boolean; /** * Checks if the document has focus. */ declare function documentHasFocus(): boolean; /** * Gets the position of an element in the document. */ declare function getElementPosition(el: HTMLElement): any; /** * Adds an event listener to a target. */ declare function addEventListener(target: HTMLElement, event: string, callback: (...params: any[]) => any, options: any): void; /** * Downloads a file with the given data and file name. */ declare function downloadFile(data: any, fileName: string): void; /** * Downloads an image from an img element or canvas element. */ declare function downloadImage(imgElement: HTMLElement, fileName: string): void; /** * Downloads an image by its URL. */ declare function downloadImageByUrl(imgUrl: string, fileName: string): void; /** * Uploads a file from an input element and calls a callback with the file data. */ declare function uploadFile(fileInput: HTMLElement, callback: (...params: any[]) => any): void; /** * Copies text to the clipboard. */ declare function copyToClipboard(text: string): Promise<boolean>; /** * Reads text from the clipboard. */ declare function readFromClipboard(): Promise<string>; /** * This function checks if the current environment is a React environment. * @returns Boolean */ declare function isReactEnv(): any; /** * This function checks if the current environment is a Vue environment. * @returns Boolean */ declare function isVueEnv(): any; /** * This function checks if the current environment is an Angular environment. * @returns Boolean */ declare function isAngularEnv(): any; /** * This function checks if the current environment is a Svelte environment. * @returns Boolean */ declare function isSvelteEnv(): any; /** * This function checks if the current environment is a Preact environment. * @returns Boolean */ declare function isPreactEnv(): any; /** * This function checks if the current environment is a Solid environment. */ declare function isSolidEnv(): boolean; /** * This function checks if the current environment is a Lit environment. */ declare function isAlpineEnv(): boolean; /** * This function checks if the current environment is a Node.js environment. */ declare function isNodeEnv(): boolean; declare function isMobile(): boolean; /** * This function checks the current browser name. * @returns The current browser name. */ declare function curBrowser(): string; /** * This function checks if a document global variable is defined. */ declare function hasGlobalVariable(variable: string): boolean; declare function isType(target: any, type: string): boolean; declare function isNumber(target: any): boolean; declare function isString(target: any): boolean; declare function isBoolean(target: any): boolean; declare function isFunction(target: any): boolean; declare function isObject(target: any): boolean; declare function isArray(target: any): boolean; declare function isNull(target: any): boolean; declare function isUndefined(target: any): boolean; declare function isSymbol(target: any): boolean; declare function isBigInt(target: any): boolean; declare function isDate(target: any): boolean; declare function isRegExp(target: any): boolean; declare function isError(target: any): boolean; declare function isMap(target: any): boolean; declare function isSet(target: any): boolean; declare function isWeakMap(target: any): boolean; declare function isWeakSet(target: any): boolean; declare function isArrayBuffer(target: any): boolean; declare function isTypedArray(target: any): boolean; declare function isDataView(target: any): boolean; declare function isPromise(target: any): boolean; /** * @returns A random integer between min and max, inclusive. */ declare function getRandomInt(min: number, max: number): number; /** * This function returns a random arrray in array. */ declare function getRandomFromArray(array: any[]): any; /** * This function returns int number */ declare function getInteger(num: number): number; /** * This function returns float number */ declare function getFloat(num: number): number; /** * This function returns the radian to angle. */ declare function radianToAngle(radian: number): number; /** * This function returns the angle to radian. */ declare function angleToRadian(angle: number): number; /** * This function returns the radian between point and center of a circle . * @returns The radian between the point (x, y) and the center of the circle (centerX, centerY). */ declare function getRadian(x: number, y: number, centerX: number, centerY: number): number; /** * @returns The nth largest number or null if n is greater than the array length. */ declare function getNthLargest(arr: number[], n: number): number | null; /** * @returns The number of decimal places in the number. */ declare function getDecimalPlaces(num: number): number; /** * @returns The sum of the two numbers with precision. */ declare function addFloat(num1: number, num2: number): number; /** * @returns The difference of the two numbers with precision. */ declare function subtractFloat(num1: number, num2: number): number; /** * @returns The product of the two numbers with precision. */ declare function multiplyFloat(num1: number, num2: number): number; /** * @returns The quotient of the two numbers with precision. */ declare function divideFloat(num1: number, num2: number): number; declare function formatNumber(num: number): string; declare function convertToDecimal(num: string): number; declare function clampNumber(num: number, min: number, max: number): number; declare function convertBase(number: number, base?: number): string; declare function isInteger(num: any): boolean; declare function padNumber(num: number | string, padNum: number | string, length?: number): string; declare function deepClone(target: any): any; /** * Shallow clones an object or array. */ declare function shallowClone(target: any): any; /** * Checks if two objects or arrays are equal. */ declare function isEqual(obj1: any, obj2: any): boolean; /** * inherits the prototype of a parent class for a child class. */ declare function inheritPrototype(child: any, parent: any): void; /** * Checks if an object is empty. */ declare function isEmptyObject(obj: any): boolean; /** * Picks specific keys from an object. */ declare function pick(obj: any, keys: any): any; /** * Omits specific keys from an object. */ declare function omit(obj: any, keys: any): any; /** * Converts an object to a query string. */ declare function objectToQueryString(obj: any): string; const _default: Util; export default _default; }