@onurege3467/zerohelper
Version:
ZeroHelper is a versatile high-performance utility library and database framework for Node.js, fully written in TypeScript.
224 lines (223 loc) • 9.14 kB
TypeScript
import * as security from './security';
import * as toon from './toon';
import * as ai from './ai';
export declare function makeUniqueId(): string;
export declare function randomArray<T>(arr: T[]): T;
export declare function randomText(length?: number): string;
export declare function randomNumber(min?: number, max?: number): number;
export declare function randomEmoji(): string;
export declare function randomHex(): string;
export declare function randomFloat(min: number, max: number): number;
export declare function titleCase(sentence: string): string;
export declare function generateRandomString(length: number): string;
export declare function generateSlug(text: string): string;
export declare function wordCount(text: string): number;
export declare function shuffleArray<T>(array: T[]): T[];
export declare function flattenArray(arr: any[]): any[];
export declare function removeFalsyValues<T>(arr: T[]): T[];
export declare function groupBy<T>(arr: T[], key: keyof T): Record<string, T[]>;
export declare function pluck<T, K extends keyof T>(arr: T[], key: K): T[K][];
export declare function sortBy<T>(arr: T[], key: keyof T): T[];
export declare function filterObjectByKey<T extends object>(obj: T, keys: string[]): Partial<T>;
export declare function deepMerge(obj1: any, obj2: any): any;
export declare function encryptText(text: string, secret: string): {
encryptedText: string;
iv: string;
};
export declare function decryptText(encryptedText: string, secret: string, ivHex: string): string;
export declare function hashPassword(password: string): string;
export declare function verifyPassword(password: string, hash: string): boolean;
export declare function generateJWT(payload: object, secret: string): string;
export declare function verifyJWT(token: string, secret: string): any;
export declare function generateSalt(): string;
export declare function validateUUID(uuid: string): boolean;
export declare function isPasswordStrong(password: string): boolean;
export declare function mean(arr: number[]): number;
export declare function median(arr: number[]): number;
export declare function variance(arr: number[]): number;
export declare function standardDeviation(arr: number[]): number;
export declare function sum(arr: number[]): number;
export declare function max(arr: number[]): number;
export declare function min(arr: number[]): number;
export declare function range(start: number, end: number): number[];
export declare function isPrime(num: number): boolean;
export declare function factorial(n: number): number;
export declare function combination(n: number, r: number): number;
export declare function permutation(n: number, r: number): number;
export declare function formatDate(date: Date, format?: string): string;
export declare function dateDifference(date1: Date, date2: Date): number;
export declare function addDays(date: Date, days: number): Date;
export declare function subtractDays(date: Date, days: number): Date;
export declare function fetchData(url: string): Promise<any>;
export declare function postData(url: string, data: any): Promise<any>;
export declare function isEmail(email: string): boolean;
export declare function isPhone(phone: string): boolean;
export declare function isURL(url: string): boolean;
export declare function sanitizeHTML(html: string): string;
export declare function validateCreditCard(cardNumber: string): boolean;
export interface ValidationSchema {
[key: string]: {
required?: boolean;
type?: string;
minLength?: number;
maxLength?: number;
pattern?: RegExp;
min?: number;
max?: number;
};
}
export declare function validateSchema(data: any, schema: ValidationSchema): {
isValid: boolean;
errors: string[];
};
export declare function sanitizeInput(input: any, options?: {
trim?: boolean;
removeHTML?: boolean;
escape?: boolean;
}): any;
export type LogLevel = 'error' | 'warn' | 'info' | 'debug';
export interface LoggerOptions {
level?: LogLevel;
enableColors?: boolean;
enableTimestamp?: boolean;
logFile?: string | null;
}
export declare class Logger {
private level;
private enableColors;
private enableTimestamp;
private logFile;
private levels;
private colors;
constructor(options?: LoggerOptions);
private shouldLog;
private formatMessage;
private writeToFile;
log(level: LogLevel, message: string, data?: any): void;
error(message: string, data?: any): void;
warn(message: string, data?: any): void;
info(message: string, data?: any): void;
debug(message: string, data?: any): void;
setLevel(level: LogLevel): void;
getLevel(): LogLevel;
}
export declare function createLogger(options?: LoggerOptions): Logger;
export declare function logInfo(message: string, data?: any): void;
export declare function logError(message: string, data?: any): void;
export declare function logWarn(message: string, data?: any): void;
export declare function logDebug(message: string, data?: any): void;
export declare const http_module: {
fetchData: typeof fetchData;
postData: typeof postData;
};
export declare const date_module: {
formatDate: typeof formatDate;
dateDifference: typeof dateDifference;
addDays: typeof addDays;
subtractDays: typeof subtractDays;
};
export declare const random_module: {
makeUniqueId: typeof makeUniqueId;
randomArray: typeof randomArray;
randomText: typeof randomText;
randomNumber: typeof randomNumber;
randomEmoji: typeof randomEmoji;
randomHex: typeof randomHex;
randomFloat: typeof randomFloat;
};
export declare const string_module: {
titleCase: typeof titleCase;
generateRandomString: typeof generateRandomString;
generateSlug: typeof generateSlug;
wordCount: typeof wordCount;
};
export declare const array_module: {
shuffleArray: typeof shuffleArray;
flattenArray: typeof flattenArray;
removeFalsyValues: typeof removeFalsyValues;
groupBy: typeof groupBy;
pluck: typeof pluck;
sortBy: typeof sortBy;
};
export declare const object_module: {
filterObjectByKey: typeof filterObjectByKey;
deepMerge: typeof deepMerge;
};
export declare const crypto_module: {
encryptText: typeof encryptText;
decryptText: typeof decryptText;
hashPassword: typeof hashPassword;
verifyPassword: typeof verifyPassword;
generateJWT: typeof generateJWT;
verifyJWT: typeof verifyJWT;
generateSalt: typeof generateSalt;
validateUUID: typeof validateUUID;
isPasswordStrong: typeof isPasswordStrong;
};
export declare const math_module: {
mean: typeof mean;
median: typeof median;
variance: typeof variance;
standardDeviation: typeof standardDeviation;
sum: typeof sum;
max: typeof max;
min: typeof min;
range: typeof range;
isPrime: typeof isPrime;
combination: typeof combination;
permutation: typeof permutation;
};
export declare const validation_module: {
isEmail: typeof isEmail;
isPhone: typeof isPhone;
isURL: typeof isURL;
sanitizeHTML: typeof sanitizeHTML;
validateCreditCard: typeof validateCreditCard;
validateSchema: typeof validateSchema;
sanitizeInput: typeof sanitizeInput;
};
export declare const logger_module: {
createLogger: typeof createLogger;
Logger: typeof Logger;
info: typeof logInfo;
error: typeof logError;
warn: typeof logWarn;
debug: typeof logDebug;
};
export declare const security_module: {
checkRateLimit(key: string, options: security.RateLimiterOptions): Promise<{
allowed: boolean;
remaining: number;
reset: number;
}>;
};
export declare const worker_module: {
runAsyncTask<T>(taskFn: string, data: any): Promise<T>;
};
export declare const toon_module: {
stringify: typeof toon.stringify;
parse: typeof toon.parse;
};
export declare const ai_module: {
estimateTokens(text: string): number;
truncateToTokenLimit(text: string, maxTokens: number): string;
splitByTokenLimit(text: string, maxTokens: number): string[];
formatChatMessage(role: "system" | "user" | "assistant", content: string): ai.ChatMessage;
createFewShotPrompt(examples: Array<{
input: string;
output: string;
}>, query: string): string;
mergeSystemAndUser(systemPrompt: string, userPrompt: string): ai.ChatMessage[];
fitMessagesToContext(messages: ai.ChatMessage[], maxTokens: number): ai.ChatMessage[];
estimateConversationCost(messages: ai.ChatMessage[], model?: string, expectedOutputTokens?: number): ai.CostEstimate;
getModelTokenLimit(model: string): number;
getModelPricing(model: string): {
input: number;
output: number;
};
extractJSONFromMarkdown(text: string): any;
parseStreamingChunk(chunk: string): ai.StreamingResponse;
isTokenLimitExceeded(prompt: string, maxTokens: number): boolean;
truncatePromptByPercentage(prompt: string, percentage: number): string;
compressConversationHistory(messages: ai.ChatMessage[], keepRecent?: number, maxSummaryTokens?: number): ai.ChatMessage[];
};