UNPKG

9.21 kBTypeScriptView Raw
1/**
2 * This file is part of the @egodigital/egoose distribution.
3 * Copyright (c) e.GO Digital GmbH, Aachen, Germany (https://www.e-go-digital.com/)
4 *
5 * @egodigital/egoose is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as
7 * published by the Free Software Foundation, version 3.
8 *
9 * @egodigital/egoose is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17import * as Enumerable from 'node-enumerable';
18import * as moment from 'moment-timezone';
19import * as yargs from 'yargs-parser';
20/**
21 * Stores version information about the app.
22 */
23export interface AppVersion {
24 /**
25 * The last commit date. Contains (false), if failed.
26 */
27 date?: moment.Moment | false;
28 /**
29 * The last commit hash. Contains (false), if failed.
30 */
31 hash?: string | false;
32}
33/**
34 * Describes a simple 'completed' action.
35 *
36 * @param {any} err The occurred error.
37 * @param {TResult} [result] The result.
38 */
39export declare type CompletedAction<TResult> = (err: any, result?: TResult) => void;
40/**
41 * Result of 'exec()' function.
42 */
43export interface ExecResult {
44 /**
45 * The error stream.
46 */
47 stderr: string;
48 /**
49 * The standard stream.
50 */
51 stdout: string;
52}
53/**
54 * An action for an async 'forEach'.
55 *
56 * @param {T} item The current item.
57 * @param {number} index The zero-based index.
58 */
59export declare type ForEachAsyncAction<T> = (item: T, index: number) => void | Promise<void>;
60/**
61 * Options for 'getAppVersion()' function(s).
62 */
63export interface GetAppVersionOptions {
64 /**
65 * The custom working directory.
66 */
67 cwd?: string;
68}
69/**
70 * A result of 'parseCommandLine()' function.
71 */
72export interface ParsedCommandLine {
73 /**
74 * The arguments.
75 */
76 arguments: yargs.Arguments;
77 /**
78 * The command.
79 */
80 command?: string;
81}
82/**
83 * A predciate.
84 *
85 * @param {TValue} value The value to check.
86 *
87 * @return {boolean} Value matches predicate or not.
88 */
89export declare type Predicate<TValue = any> = (value: TValue) => boolean;
90/**
91 * Applies an object or value to a function.
92 *
93 * @param {TFunc} func The function to apply 'thisArg' to.
94 * @param {any} thisArg The object or value to apply to 'func'.
95 *
96 * @return {TFunc} The new function.
97 */
98export declare function applyFuncFor<TFunc extends Function = Function>(func: TFunc, thisArg: any): TFunc;
99/**
100 * Returns an input value as array.
101 *
102 * @param {T|T[]} val The input value.
103 * @param {boolean} [noEmpty] Remove values, which are (null) or (undefined).
104 *
105 * @return {T[]} The input value as array.
106 */
107export declare function asArray<T>(val: T | T[], noEmpty?: boolean): T[];
108/**
109 * Keeps sure that a value is a Moment instance (local timezone).
110 *
111 * @param {any} time The input value.
112 *
113 * @return {moment.Moment} The Moment instance.
114 */
115export declare function asLocal(time: any): moment.Moment;
116/**
117 * Keeps sure that a value is a Moment instance.
118 *
119 * @param {any} val The input value.
120 *
121 * @return {moment.Moment} The Moment instance.
122 */
123export declare function asMoment(val: any): moment.Moment;
124/**
125 * Keeps sure that a value is a Moment instance (UTC timezone).
126 *
127 * @param {any} time The input value.
128 *
129 * @return {moment.Moment} The Moment instance.
130 */
131export declare function asUTC(time: any): moment.Moment;
132/**
133 * Clones an object / value.
134 *
135 * @param {T} obj The value to clone.
136 *
137 * @return {T} The cloned value.
138 */
139export declare function cloneObj<T>(obj: T): T;
140/**
141 * Compare to values for sorting.
142 *
143 * @param {any} x The "left" value.
144 * @param {any} y The "right" value.
145 *
146 * @return {number} The sort value.
147 */
148export declare function compareValues<T = any>(x: T, y: T): number;
149/**
150 * Compare to values for sorting by using a selector.
151 *
152 * @param {any} x The "left" value.
153 * @param {any} y The "right" value.
154 * @param {Function} selector The selector.
155 *
156 * @return {number} The sort value.
157 */
158export declare function compareValuesBy<T = any, U = T>(x: T, y: T, selector: (val: T) => U): number;
159/**
160 * Creates a simple 'completed' callback for a promise.
161 *
162 * @param {Function} resolve The 'succeeded' callback.
163 * @param {Function} reject The 'error' callback.
164 *
165 * @return {CompletedAction<TResult>} The created action.
166 */
167export declare function createCompletedAction<TResult = any>(resolve: (value?: TResult | PromiseLike<TResult>) => void, reject?: (reason: any) => void): CompletedAction<TResult>;
168/**
169 * Promise version of `child_process.exec()` function.
170 *
171 * @param {string} command The command to execute.
172 *
173 * @return {Promise<ExecResult>} The promise with the result.
174 */
175export declare function exec(command: string): Promise<ExecResult>;
176/**
177 * An async 'forEach'.
178 *
179 * @param {Enumerable.Sequence<T>} seq The sequence or array to iterate.
180 * @param {ForEachAsyncAction<T>} action The action to invoke.
181 */
182export declare function forEachAsync<T>(seq: Enumerable.Sequence<T>, action: ForEachAsyncAction<T>): Promise<void>;
183/**
184 * Detects version information about the current app via Git (synchronous).
185 *
186 * @param {GetAppVersionOptions} [opts] Custom options.
187 *
188 * @return {AppVersion} Version information.
189 */
190export declare function getAppVersionSync(opts?: GetAppVersionOptions): AppVersion;
191/**
192 * Alias of 'uuid()' function.
193 */
194export declare function guid(version?: string): string;
195/**
196 * Checks if the string representation of a value is an empty string or not.
197 *
198 * @param {any} val The value to check.
199 *
200 * @return {boolean} If empty string or not.
201 */
202export declare function isEmptyString(val: any): boolean;
203/**
204 * Normalizes a value to a string, which is comparable.
205 *
206 * @param {any} val The value to normalize.
207 *
208 * @return {string} The normalized string.
209 */
210export declare function normalizeString(val: any): string;
211/**
212 * Returns the current time.
213 *
214 * @param {string} [timezone] The custom timezone to use.
215 *
216 * @return {Moment.Moment} The current time.
217 */
218export declare function now(timezone?: string): moment.Moment;
219/**
220 * Parses a value as string of a command line input.
221 *
222 * @param {any} cmd The command line input.
223 *
224 * @return {ParsedCommandLine} The parsed data.
225 */
226export declare function parseCommandLine(cmd: any): ParsedCommandLine;
227/**
228 * Generates a random string.
229 *
230 * @param {number} size The size of the result string.
231 * @param {string} [chars] The custom list of characters.
232 *
233 * @return {Promise<string>} The promise with the random string.
234 */
235export declare function randChars(size: number, chars?: string): Promise<string>;
236/**
237 * Generates a random string.
238 *
239 * @param {number} size The size of the result string.
240 * @param {string} [chars] The custom list of characters.
241 *
242 * @return {string} The random string.
243 */
244export declare function randCharsSync(size: number, chars?: string): string;
245/**
246 * Returns a value as "real" boolean.
247 *
248 * @param {any} val The input value.
249 * @param {boolean} [defaultValue] The value to return if 'val' is (null) or (undefined).
250 *
251 * @return {boolean} The output value.
252 */
253export declare function toBooleanSafe(val: any, defaultValue?: boolean): boolean;
254/**
255 * Converts a value to a string (if needed), which is not (null) and not (undefined).
256 *
257 * @param {any} val The value to convert.
258 * @param {string} [defaultValue] The custom default value if 'val' is (null) or (undefined).
259 *
260 * @return {string} 'val' as string.
261 */
262export declare function toStringSafe(val: any, defaultValue?: string): string;
263/**
264 * Returns the current time in UTC.
265 *
266 * @return {moment.Moment} The current UTC time.
267 */
268export declare function utc(): moment.Moment;
269/**
270 * Generates an unique ID.
271 *
272 * @param {string} [version] The custom version to use. Default: 4
273 * @param {any[]} []
274 *
275 * @return {string} The new GUID / unique ID.
276 */
277export declare function uuid(version?: string, ...args: any[]): string;
278export * from './apis/host';
279export * from './apis/index';
280export * from './apis/statistics';
281export * from './apis/validation';
282export * from './azure/storage';
283export * from './cache';
284export * from './cache/redis';
285export * from './dev';
286export * from './diagnostics/logger';
287export * from './diagnostics/stopwatch';
288export * from './env';
289export * from './events';
290export * from './fs';
291export * from './geo';
292export * from './http';
293export * from './http/websockets';
294export * from './mail';
295export * from './mongo/index';
296export * from './mongo/statistics';
297export * from './oauth/microsoft';
298export * from './queues/index';
299export * from './schemas';
300export * from './statistics';
301export * from './streams';
302export * from './strings';
303export * from './system';
304export * from './zip/builder';
305export { asEnumerable, from, isEnumerable, isSequence, popFrom, random, range, repeat, shiftFrom } from 'node-enumerable';
306export { setupSwaggerUIFromSourceFiles } from 'swagger-jsdoc-express';