kaven-utils
Version:
Utils for Node.js.
175 lines (174 loc) • 6.1 kB
TypeScript
/********************************************************************
* @author: Kaven
* @email: kaven@wuwenkai.com
* @website: http://blog.kaven.xyz
* @file: [Kaven-Utils] /src/KavenUtility.ts
* @create: 2018-08-25 08:19:55.120
* @modify: 2025-10-15 17:31:12.753
* @version: 6.1.1
* @times: 360
* @lines: 529
* @copyright: Copyright © 2018-2025 Kaven. All Rights Reserved.
* @description: Utils for Node.js.
* @license:
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import { ILoggingAgent } from "kaven-basic";
import { ICertificateSubject, IFindAndReplaceInFilesOptions, IMongoDBBackupOptions } from "./base/Interfaces.js";
/**
* @since 1.0.5
* @version 2025-10-14
*/
export declare function GetColoredStatus(code: string | number | undefined, logger?: ILoggingAgent): string | number | undefined;
/**
*
* @param fileName
* @param backupFolder
* @since 4.1.0
* @version 2022-04-22
*/
export declare function BackupFile(fileName: string, backupFolder?: string): Promise<string>;
/**
* @since 1.0.5
* @version 2025-10-14
*/
export declare function ResetLogFile(fileName: string, backupFolder?: string, logger?: ILoggingAgent): Promise<boolean>;
/**
* 2019-08-05:
* add param: `logFile`
* @param overBytes
* @since 1.0.9
* @version 2020-07-11
*/
export declare function ResetLogFileIf(overBytes?: number, logFile?: string): Promise<boolean>;
/**
* @since 1.0.5
* @version 2025-10-14
*/
export declare function BackupMongoDB(outputDir: string, options?: IMongoDBBackupOptions): Promise<string>;
/**
* @param {string} data
* @param {BufferEncoding} [encoding="utf8"]
* @version 1.0.0
* @since 1.0.6
* @see http://www.rfc-editor.org/rfc/rfc4648.txt
*/
export declare function Base64Encode(data: string,
/**
* ascii, base64, binary, hex, ucs2/ucs-2/utf16le/utf-16le, utf8/utf-8, latin1 (ISO8859-1, only in node 6.4.0+)
*/
encoding?: BufferEncoding): string;
/**
* @param {string} base64Data
* @param {string} [encoding="ascii"]
* @version 1.0.0
* @since 1.0.6
* @see http://www.rfc-editor.org/rfc/rfc4648.txt
*/
export declare function Base64Decode(base64Data: string,
/**
* ascii, base64, binary, hex, ucs2/ucs-2/utf16le/utf-16le, utf8/utf-8, latin1 (ISO8859-1, only in node 6.4.0+)
*/
encoding?: BufferEncoding): string;
/**
* In cryptography, an HMAC (sometimes expanded as either keyed-hash message authentication code or
* hash-based message authentication code) is a specific type of
* message authentication code (MAC)
* involving a cryptographic hash function and a secret cryptographic key.
* @param {string} stringToSign
* @param {string} secret
* @since 1.1.6
* @version 2018-08-20
*/
export declare function HMAC_SHA1(stringToSign: string, secret: string): NonSharedBuffer;
/**
* List all files in a directory in Node.js recursively in a synchronous fashion
* @param {string} dir
* @returns
* @since 1.1.6
* @version 2018-08-27
*/
export declare function GetAllFilesRecursively(dir: string, extensions?: string[], ignorePaths?: string[]): string[];
/**
* Simple wrap for readdirSync
* @param dir
* @since 1.1.18
* @version 2018-10-22
*/
export declare function GetAllFiles(dir: string): string[];
/**
* @since 1.1.6
* @version 2025-10-14
*/
export declare function FindAndReplaceInFiles(dirOrFiles: string | string[], options?: IFindAndReplaceInFilesOptions): Promise<void>;
/**
*
* @param filesOrFolders
* @param excludeFilesOrFolders
* @param fileTypes
* @since 1.1.7
* @version 2018-09-01
*/
export declare function GetFileList(filesOrFolders: string[], excludeFilesOrFolders?: string[], fileTypes?: string[]): string[];
/**
*
* @param file
* @param length
* @param offset
* @version 1.1.18
* @since 2023-11-18
*/
export declare function ReadFileBytes(file: string, length: number, offset?: number): Promise<Buffer<ArrayBuffer>>;
/**
* @since 4.3.10
* @version 2023-11-18
*/
export declare function ReadFileAsBase64(file: string): Promise<string>;
/**
* @since 1.1.23
* @version 2025-10-14
*/
export declare function GetProtocolFromURL(url: string, logger?: ILoggingAgent): string | undefined;
/**
* @since 3.0.5
* @version 2025-06-18
*/
export declare function TryParseVersionFromFile(file: string): Promise<import("kaven-basic").IParsedVersion | undefined>;
/**
* Support `package.json` and `pubspec.yaml`
* @since 3.0.5
* @version 2021-12-07
*/
export declare function TryUpdateVersion(file: string): Promise<string>;
export declare function TryUpdateVersion(file: string, index: number, increment: number): Promise<string>;
/**
*
* @param subj
* @since 4.1.0
* @version 2022-04-21
*/
export declare function CertificateSubjectToString(subj?: ICertificateSubject): string;
/**
*
* @since 4.1.0
* @version 2022-04-23
*/
export declare function RemoveFileComments(srcFile: string, destFile: string): Promise<string>;
export declare function RemoveFileComments(srcFile: string, backup: boolean): Promise<string>;
export declare function RemoveFileComments(srcFile: string): Promise<string>;