UNPKG

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