UNPKG

@nasriya/hypercloud

Version:

Nasriya HyperCloud is a lightweight Node.js HTTP2 framework.

287 lines (286 loc) 10.1 kB
import fs from 'fs'; import { DeepReadonly, MimeType, RandomOptions } from '../docs/docs'; declare class Helpers { #private; constructor(); /** * Load a `JSON` file * @param filePath The absolute path of the `JSON` file */ loadJSON(filePath: string): Record<string, any> | Array<any>; /** * Deep freeze an object or an array * @param obj The object or array you want to freeze */ deepFreeze<T>(obj: T): DeepReadonly<T>; /**Get the name if this package (project) from the `package.json` file */ getProjectName(): string; /** * Calculate the hash value if a file * @param {string} filePath The file path * @returns {Promise<string>} The hashed value */ calculateHash(filePath: string): Promise<string>; /** * Print something on the debug level * @param {string|any} message * @returns {void} */ printConsole(message: string | any): void; readonly validate: { /** * Validate a currency (regardless of letter case) * @param {string} currency A currency to validate * @returns {boolean} */ currency: (currency: string) => boolean; /** * Validate a locale * @param {string} locale A locale to validate * @returns {boolean} */ locale: (locale: string) => boolean; /** * Validate an IPv4 or IPv6 address * @example * // Example usage: * console.log(validate.ipAddress('192.168.0.1')); // true * console.log(validate.ipAddress('2001:0db8:85a3:0000:0000:8a2e:0370:7334')); // true * console.log(validate.ipAddress('invalid')); // false * @param {string} ip The IP address to validate * @returns {boolean} */ ipAddress: (ip: string) => boolean; /** * Pass domain(s) to check whether they're valid to be used for the SSL certificate * @param {string|string[]} toCheck The domain(s) to check * @returns {boolean} */ domains: (toCheck: string | string[]) => boolean; /** * Check the syntax validity of an email address * @param {string} email The email address to check * @returns {boolean} */ email: (email: string) => boolean; /** * @param {string} certbotPath * @returns {boolean} */ certbotPath: (certbotPath: string) => boolean; /** * Validate the project path * @param {string} projectPath * @returns {boolean} */ projectPath: (projectPath: string) => boolean; }; /** * Check the accessibility of a directory. This also checks whether the directory exists or not. * @param {string} path The path to check */ checkPathAccessibility(path: fs.PathLike): { valid: false; errors: { notString: boolean; doesntExist: boolean; notAccessible: boolean; }; } | { valid: true; }; /** * Add a message/comment to a bat file * @param {string} batStr The original BAT string * @param {string} msg The message you want to add to the BAT string * @returns {string} The updated BAT string */ addBatMessage(batStr: string, msg: string): string; /** * Parse the request's cookies header * @param {string} cookiesHeader The cookies header from a request * @returns The cookies as an object */ parseCookies(cookiesHeader: string): {}; /** * Verify whether your Node.js process is running in CommonJS `cjs` or ECMAScript modules `esm` * @returns {'commonjs'|'module'} */ getNodeEnv(): 'commonjs' | 'module'; /** * Load a module (either a file or a package) * @param {string} name The name of the module to load * @param {Object} [options] Additional options * @param {boolean} [options.isFile] Whether the name is a file path * @returns {Promise<any>} A promise that resolves with the loaded module * @throws {Error} If the module couldn't be loaded */ loadModule(name: string, options?: { isFile?: boolean; }): Promise<any>; /** * Load a module from a file * @param {string} filePath The path to the file * @returns {Promise<any>} The module */ loadFileModule(filePath: string): Promise<any>; /** * Get the local IP address of the server * @returns {string[]} An array of local IPs */ getLocalIPs(): Promise<string[]>; /** * Generate a random text * @param length The length of the text. Minimum of `4` * @param [options] Options for generating the text * @returns */ generateRandom(length: number, options?: RandomOptions): string; readonly is: { /** * Check if a given value is a number. * @param {any} value The value to check. * @returns {value is number} */ number: (value: any) => value is number; /** * Check if a given value is a string. * @param {any} value The value to check. * @returns {value is string} */ string: (value: any) => value is string; /** * Check if a given MIME type is valid. * @param {any} mime The MIME type to check. * @returns {boolean} */ validMime: (mime: any) => mime is MimeType; /** * Check if a given value is a valid URL. * @param {any} str The value to check. * @returns {boolean} */ validURL: (str: any) => boolean; /** * Check if a given value is path-like. * @param {any} value The value to check. * @returns {value is fs.PathLike} */ pathLike: (value: any) => value is fs.PathLike; /** * Check if a given value can be frozen (i.e., is an object or array). * @param {any} value The value to check. * @returns {boolean} */ freezable: (value: any) => boolean; /** * Check if a given string is valid HTML code. * @param {string} string The string to check. * @returns {boolean} */ html: (string: string) => boolean; /** * Check if a given value is a real object (i.e., not null or an array). * @param {any} obj The value to check. * @returns {boolean} */ realObject: (obj: any) => boolean; /** * Check if a given value is a valid string. * @param {any} str The value to check. * @returns {boolean} */ validString: (str: any) => boolean; /** * Check if a given value is undefined. * @param {any} arg The value to check. * @returns {arg is undefined} */ undefined: (arg: any) => arg is undefined; /** * Check if a given value is an integer. * @param {any} value The value to check. * @returns {boolean} */ integer: (value: any) => boolean; }; readonly isNot: { /** * Check if a given value is not a number. * @param {any} value The value to check. * @returns {value is Exclude<any, number>} */ number: (value: any) => value is Exclude<any, number>; /** * Check if a given value is not a string. * @param {any} value The value to check. * @returns {value is Exclude<any, string>} */ string: (value: any) => value is Exclude<any, string>; /** * Check if a given MIME type is not valid. * @param {any} mime The MIME type to check. * @returns {boolean} */ validMime: (mime: any) => boolean; /** * Check if a given value is not a valid URL. * @param {any} str The value to check. * @returns {boolean} */ validURL: (str: any) => boolean; /** * Check if a given value is not path-like. * @param {any} value The value to check. * @returns {value is Exclude<fs.PathLike, string | Buffer | URL>} */ pathLike: (value: any) => value is Exclude<fs.PathLike, string | Buffer | URL>; /** * Check if a given value is not freezable. * @param {any} value The value to check. * @returns {boolean} */ freezable: (value: any) => boolean; /** * Check if a given string is not valid HTML code. * @param {string} string The string to check. * @returns {boolean} */ html: (string: string) => boolean; /** * Check if a given value is not a real object. * @param {any} obj The value to check. * @returns {boolean} */ realObject: (obj: any) => boolean; /** * Check if a given value is not a valid string. * @param {any} str The value to check. * @returns {boolean} */ validString: (str: any) => boolean; /** * Check if a given value is not undefined. * @param {any} arg The value to check. * @returns {arg is Exclude<any, undefined>} */ undefined: (arg: any) => arg is Exclude<any, undefined>; /** * Check if a given value is not an integer. * @param {any} value The value to check. * @returns {boolean} */ integer: (value: any) => boolean; }; /** * Checks if the given object has the specified property as its own property. * This method does not check properties inherited through the prototype chain. * * @param obj - The object to check for the property. * @param prop - The name of the property to check for. * @returns A boolean indicating whether the object has the specified property as its own property. */ hasOwnProperty(obj: any, prop: string): boolean; } declare const _default: Helpers; export default _default;