import 'reflect-metadata'; import { Blob } from 'buffer'; import { CoreModels } from './core-models'; export declare namespace Utils { const wait: (second: number) => Promise; const waitMilliseconds: (milliseconds: number) => Promise; const uniqArray: (array: any[], uniqueProperty?: keyof T) => T[]; /** * @param anyObject * @returns object with sorted keys */ const sortKeys: (anyObject: any) => any; /** * Example: * new RegExp(escapeStringForRegEx('a.b.c'),'g') => /a\.b\.c/g */ const escapeStringForRegEx: (stringForRegExp: string, options?: { skipEscapeSlashAndDash?: boolean; }) => string; function removeChalkSpecialChars(str: string): string; const fullDateTime: () => string; const fullDate: () => string; const getFreePort: (options?: { startFrom?: number; }) => Promise; const requireUncached: (module: string) => any; /** * similar to camelCase but remove * all non word / repeated characters */ const camelize: (str?: string) => string; enum DbBinaryFormatEnum { Blob = "Blob", File = "File", string = "string", Buffer = "Buffer" } type DbBinaryFormatForBrowser = Blob | File | string; type DbBinaryFormatForBackend = Buffer; /** * Binary format that can be stored in database * * for nodejs => Buffer * for sql.js => string (shoulb be blob - but not supported) * */ type DbBinaryFormat = DbBinaryFormatForBrowser | DbBinaryFormatForBackend; namespace binary { /** * This is for BROWSER ONLY * * @param buffer * @param contentType * @returns */ function arrayBufferToBlob(buffer: ArrayBuffer, contentType: CoreModels.ContentType): Promise; /** * This is for BROWSER ONLY * @param blob * @returns */ function blobToArrayBuffer(blob: Blob): Promise; /** * it is revers to base64toBlob * @param blob * @returns */ function blobToBase64(blob: Blob): Promise; /** * it is revers to blobToBase64() * @param base64Data * @returns */ function base64toBlob(base64Data: string, contentTypeOverride?: CoreModels.ContentType): Promise; function base64toDbBinaryFormat(text: string): Promise; function dbBinaryFormatToBase64(binaryFormat: DbBinaryFormat): Promise; function textToDbBinaryFormat(text: string): Promise; function dbBinaryFormatToText(binaryFormat: DbBinaryFormat): Promise; function base64toBuffer(base64Data: string, contentTypeOverride?: CoreModels.ContentType): Promise; function bufferToBase64(bufferData: Buffer): Promise; function fileToBlob(file: File): Promise; function blobToFile(blob: Blob, nameForFile?: string): Promise; function blobToBuffer(blob: Blob): Promise; function bufferToBlob(buffer: Buffer): Promise; function textToBuffer(text: string, type?: CoreModels.ContentType): Promise; function bufferToText(buffer: Buffer): Promise; function textToBlob(text: string, type?: CoreModels.ContentType): Promise; function blobToText(blob: Blob): Promise; function textToFile(text: string, fileRelativePathOrName: string): Promise; function fileToText(file: File): Promise; function jsonToBlob(jsonObj: object): Promise; /** * TODO NOT TESTED */ function blobToJson(blob: Blob): Promise; function getBlobFrom(url: string): Promise; } namespace css { /** * * @param pixelsCss pixels ex. 100px * @returns */ function numValue(pixelsCss: string | number): number; } } export declare namespace UtilsStringRegex { const containsNonAscii: (pathStringOrPathParts: string) => boolean; } /** * TODO @LAST @IN_PROGRESS * - utils for messages * - export when ready * - should be ready for everything async refactor */ export declare namespace UtilsMessages { const compilationWrapper: (fn: () => any, taskName?: string, executionType?: "Compilation of" | "Code execution of" | "Event:") => Promise; } export declare namespace UtilsSudo { /** * All possible sudo states on Windows 11 (24H2+) */ enum SudoStatus { NotInstalled = "NotInstalled", Disabled = "Disabled", Enabled_ForceNewWindow = "Enabled_ForceNewWindow",// Enabled = 2 Enabled_Inline = "Enabled_Inline",// Enabled = 3 ← current default Unknown = "Unknown" } /** * @returns true if current process is elevated (admin or sudo root), false otherwise */ export const isCurrentProcessElevated: () => Promise; /** * Main function – returns detailed sudo status */ export function getStatus(): Promise<{ status: SudoStatus; label: string; isAvailable: boolean; isInline: boolean; }>; /** * check if sudo is available and in proper mode */ export const isInProperModeForTaon: ({ displayErrorMessage, }: { displayErrorMessage?: boolean; }) => Promise; export {}; } export declare namespace UtilsString { const kebabCaseNoSplitNumbers: (input: string) => string; } /** * Taon migration utilities */ export declare namespace UtilsMigrations { const getTimestampFromClassName: (className: string) => number | undefined; const getFormattedTimestampFromClassName: (className: string) => string | undefined; const formatTimestamp: (timestamp: number) => string; const isValidTimestamp: (value: any) => boolean; } export declare namespace UtilsJson { interface AttrJsoncProp { name: string; value?: any; } /** * ! TODO handle packages like zone.js with dot * Get attributes from jsonc or json5 file * @param jsonDeepPath lodash path to property in json ex. deep.path.to.prop * @param fileContent jsonc or json5 - json with comments * @returns array of attributes */ const getAtrributiesFromJsonWithComments: (jsonDeepPath: string, // lodash path to property in json ex. deep.path.to.prop fileContent: string) => AttrJsoncProp[]; const getAttributiesFromComment: (comment: string, attributes?: AttrJsoncProp[]) => AttrJsoncProp[]; /** * read json from absolute path * @returns json object */ const readJson: (absoluteFilePath: string | string[], defaultValue?: {}, useJson5?: boolean) => any; const readJsonWithComments: (absoluteFilePath: string | string[], defaultValue?: any) => any; } export declare namespace UtilsYaml { const yamlToJson: (yamlString: string) => any; const jsonToYaml: (json: any) => string; const readYamlAsJson: (absFilePathToYamlOrYmlFile: string, options?: { defaultValue?: FORMAT; }) => FORMAT; const writeJsonToYaml: (destinationYamlfileAbsPath: string, json: any) => void; } export declare namespace FilePathMetaData { /** * Embed metadata into filename while preserving the extension. * * Example: * embedData({ version: "1.2.3", envName: "__" }, "project.zip") * -> "version|-|1.2.3||--||envName|-|__|||project.zip" * * keysMap = { * projectName: "pn", * envName: "en", * version: "v" * } */ const embedData: >(data: T, orgFilename: string, options?: { skipAddingBasenameAtEnd?: boolean; keysMap?: Record; }) => string; /** * Extract metadata from filename (reverse of embedData). * * Example: * extractData<{ version: string; env: string }>("myfile__version-1.2.3__env-prod.zip") * -> { version: "1.2.3", env: "prod" } * * keysMap = { * projectName: "pn", * envName: "en", * version: "v" * } */ const extractData: >(filename: string, options?: { keysMap?: Record; }) => T; const getOnlyMetadataString: (filename: string) => string; } export declare namespace UtilsDotFile { const setValueToDotFile: (dotFileAbsPath: string | string[], key: string, value: string | number | boolean) => void; const setCommentToKeyInDotFile: (dotFileAbsPath: string | string[], key: string, comment: string) => void; const getValueFromDotFile: (dotFileAbsPath: string | string[], key: string) => string | number | boolean; const addCommentAtTheBeginningOfDotFile: (dotFileAbsPath: string | string[], comment: string) => void; const setValuesKeysFromObject: (dotFileAbsPath: string | string[], obj: Record, options?: { /** * if true, it will overwrite existing keys */ setAsNewFile?: boolean; }) => void; const getValuesKeysAsJsonObject: >(dotFileAbsPath: string | string[]) => T; /** * @returns key|comment pairs as json object */ const getCommentsKeysAsJsonObject: >(dotFileAbsPath: string | string[]) => T; } /** * Easy way to connect CLI commands to cli class methods. * * Example: * in clic class * * $FirstCli { * static [UtilsCliClassMethod.staticClassNameProperty] = '$FirstCli'; * * @UtilsCliClassMethod.decoratorMethod('doSomething') * doSomething() { * console.log('doing something'); * } * } * * UtilsCliClassMethod.getFrom($FirstCli.prototype.doSomething) // "firstcli:dosomething" * */ export declare namespace UtilsCliClassMethod { const decoratorMethod: (methodName: string) => MethodDecorator; const getFrom: (ClassPrototypeMethodFnHere: Function, options?: { globalMethod?: boolean; /** * arguments to parse into CLI format * Example: { projectName: "myproj", envName: "prod" } => "--projectName=myproj --envName=prod" * TODO @LAST add support for DEEP args parsing with lodash-walk-object */ argsToParse?: ARGS_TO_PARSE; }) => string; }