entity-baker
Version:
Generates simple and powerful entity classes for ORM systems, like Doctrine and/or Entity Framework.
244 lines (243 loc) • 7.75 kB
TypeScript
/// <reference types="glob" />
/// <reference types="node" />
/**
* This file is part of the node-entity-baker distribution.
* Copyright (c) Marcel Joachim Kloubert.
*
* node-entity-baker is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, version 3.
*
* node-entity-baker is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import * as FS from 'fs';
import * as Glob from 'glob';
/**
* Converts an input value to an array.
*
* @param {T|T[]} val The input value.
* @param {boolean} [removeEmpty] Removes items which are (null) or (undefined).
*
* @return {T[]} The value as array.
*/
export declare function asArray<T>(val: T | T[], removeEmpty?: boolean): T[];
/**
* Compares two values for sort operations.
*
* @param {T} x The left value.
* @param {T} y The right value.
*
* @return {number} The comparer value.
*/
export declare function compareValues<T>(x: T, y: T): number;
/**
* Compares two values for sort operations by using a selector.
*
* @param {T} x The left value.
* @param {T} y The right value.
* @param {Function} selector The selector to use.
*
* @return {number} The comparer value.
*/
export declare function compareValuesBy<T, U>(x: T, y: T, selector: (item: T) => U): number;
/**
* Removes duplicate entries from an array.
*
* @param {T[]} arr The input array.
*
* @return {T[]} The distincted array.
*/
export declare function distinctArray<T>(arr: T[]): T[];
/**
* Removes duplicate entries from an array by using a selector.
*
* @param {T[]} arr The input array.
* @param {Function} selector The selector.
*
* @return {T[]} The distincted array.
*/
export declare function distinctArrayBy<T, U>(arr: T[], selector: (item: T) => U): T[];
/**
* Promise version of 'Glob()' function.
*
* @param {string} pattern The pattern.
* @param {Glob.IOptions} [options] Custom options.
*
* @return {Promise<string[]>} The promise with the matches.
*/
export declare function glob(pattern: string, options?: Glob.IOptions): Promise<string[]>;
/**
* Promise version of 'FS.exists()' function.
*
* @param {FS.PathLike} path The path.
*
* @return {Promise<Buffer>} The promise that indicates if item exists or not.
*/
export declare function exists(path: FS.PathLike): Promise<boolean>;
/**
* s. 'Glob.sync()'
*
* @param {string} pattern The pattern.
* @param {Glob.IOptions} [options] Custom options.
*
* @return {string[]} The matches.
*/
export declare function globSync(pattern: string, options?: Glob.IOptions): string[];
/**
* Checks if a value is a boolean.
*
* @param {any} val The value to check.
*
* @return {boolean} Is boolean.
*/
export declare function isBool(val: any): val is boolean;
/**
* Checks if the string representation of a value is an empty string
* or contains whitespaces only.
*
* @param {any} val The value to check.
*
* @return {boolean} Is empty string or not.
*/
export declare function isEmptyString(val: any): boolean;
/**
* Checks if a value is a function.
*
* @param {any} val The value to check.
*
* @return {boolean} Is function.
*/
export declare function isFunc<TFunc extends Function = Function>(val: any): val is TFunc;
/**
* Checks if a value is (null) or (undefined).
*
* @param {any} val The value to check.
*
* @return {boolean} Is (null) or (undefined).
*/
export declare function isNullOrUndefined(val: any): val is (null | undefined);
/**
* Checks if a value is a number.
*
* @param {any} val The value to check.
*
* @return {boolean} Is number.
*/
export declare function isNumber(val: any): val is number;
/**
* Checks if a value is an object.
*
* @param {any} val The value to check.
*
* @return {boolean} Is object.
*/
export declare function isObj<TObj extends Object = Object>(val: any): val is TObj;
/**
* Checks if a value is a string.
*
* @param {any} val The value to check.
*
* @return {boolean} Is string.
*/
export declare function isString(val: any): val is string;
/**
* Checks if a value is a symbol.
*
* @param {any} val The value to check.
*
* @return {boolean} Is symbol.
*/
export declare function isSymbol<TSymbol extends Symbol = Symbol>(val: any): val is TSymbol;
/**
* Pushes a list of items to an array.
*
* @param {T[]} arr The array to push to.
* @param {T[]} items The items to push.
*/
export declare function pushMany<T>(arr: T[], items: T[]): void;
/**
* Normalizes a value to a string for comparison.
*
* @param {any} val The value to normalize.
*
* @return {string} The normalized value.
*/
export declare function normalizeString(val: any): string;
/**
* Promise version of 'FS.readFile()' function.
*
* @param {FS.PathLike|number} path The path or descriptor to the file.
*
* @return {Promise<Buffer>} The promise with the read data.
*/
export declare function readFile(path: FS.PathLike | number): Promise<Buffer>;
/**
* Handles a value as string and replaces all sub strings with another string.
*
* @param {any} val The input value.
* @param {any} searchFor The value to search for.
* @param {any} replaceWith The value to replace 'searchFor' with.
*
* @return {string} The new value.
*/
export declare function replaceAll(val: any, searchFor: any, replaceWith: any): string;
/**
* Converts a value to a boolean.
*
* @param {any} val The value to convert.
* @param {any} [defaultValue] The custom default value if 'val' is (null) or (undefined).
*
* @return {boolean} The converted value.
*/
export declare function toBooleanSafe(val: any, defaultValue?: any): boolean;
/**
* Converts a value to a string.
*
* @param {any} val The value to convert.
* @param {any} [defaultValue] The custom default value if 'val' is (null) or (undefined).
*
* @return {string} The converted value.
*/
export declare function toStringSafe(val: any, defaultValue?: any): string;
/**
* Writes a message to a stream.
*
* @param {any} msg The message to write.
* @param {NodeJS.WritableStream} [stream] The custom output stream. Default: stdout
*/
export declare function write(msg: any, stream?: NodeJS.WritableStream): void;
/**
* Writes a message to stderr.
*
* @param {any} msg The message to write.
*/
export declare function write_err(msg: any): void;
/**
* Writes an optional message to stderr and appends a new line.
*
* @param {any} [msg] The message to write.
*/
export declare function write_err_ln(msg?: any): void;
/**
* Writes an optional message to a stream and appends a new line.
*
* @param {any} [msg] The message to write.
* @param {NodeJS.WritableStream} [stream] The custom output stream. Default: stdout
*/
export declare function write_ln(msg?: any, stream?: NodeJS.WritableStream): void;
/**
* Promise version of 'FS.writeFile()' function.
*
* @param {FS.PathLike|number} path The path or descriptor to the file.
* @param {any} data The data to write.
* @param {string} [encoding] The encoding to use.
*
* @return {Promise<Buffer>} The promise with the read data.
*/
export declare function writeFile(path: FS.PathLike | number, data: any, encoding?: string): Promise<void>;