UNPKG

kaven-utils

Version:

Utils for Node.js.

211 lines (210 loc) 7.03 kB
/******************************************************************** * @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: 2024-11-01 14:34:18.998 * @version: 5.4.5 * @times: 349 * @lines: 585 * @copyright: Copyright © 2018-2024 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 { ICertificateSubject } from "./base/Interfaces.js"; /** * * @param code * @since 1.0.5 * @version 2023-03-28 */ export declare function GetColoredStatus(code: string | number | undefined): 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>; /** * 2019-08-05: * remove default value "./data/logs/" for `backupFolder`; * change backup file name * @param fileName * @param backupFolder * @since 1.0.5 * @version 2022-04-22 */ export declare function ResetLogFile(fileName: string, backupFolder?: string): 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>; /** * * @param outputDir * @param databaseName * @param host * @param databaseUser * @param databasePassword * @version 1.0.1 * @since 1.0.5 */ export declare function BackupMongoDB(outputDir: string, databaseName?: string, host?: string, databaseUser?: string, databasePassword?: string): 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): Buffer<ArrayBufferLike>; /** * 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[]; /** * @param {string | string[]} dirOrFiles * @param {string} [conditions=[ * ["link(rel='stylesheet', href=\"", "\")"], * ["link(rel='stylesheet', href='", "')"], * ["link(rel=\"stylesheet\", href=\"", "\")"], * ["link(rel=\"stylesheet\", href='", "')"], * ["script(src=\"", "\")"], * ["script(src='", "')"], * ]] * @param {(str: string) => string} [newStrMethod] * @param {string} [extensions=[ * ".jade", * ".pug" * ]] * @param {boolean?} showLog * @since 1.1.6 * @version 2018-09-01 */ export declare function FindAndReplaceInFiles(dirOrFiles: string | string[], conditions?: string[][], newStrMethod?: (str: string) => string, extensions?: string[], showLog?: boolean): 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>>; /** * * @param file * @since 4.3.10 * @version 2023-11-18 */ export declare function ReadFileAsBase64(file: string): Promise<string>; /** * * @param url * @since 1.1.23 * @version 2019-02-27 */ export declare function GetProtocolFromURL(url: string): string | undefined; /** * @since 3.0.5 * @version 2022-05-01 */ export declare function TryParseVersionFromFile(file: string): Promise<{ endOfLineSequence: string | undefined; lines: string[]; versionLine: string; version: string | undefined; } | 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>;