-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhelpers.d.ts
80 lines (80 loc) · 2.65 KB
/
helpers.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/// <reference types="node" />
import * as Net from 'net';
/**
* Describes a simple 'completed' action.
*
* @param {any} [err] The occurred error.
* @param {TResult} [result] The result.
*/
export declare type SimpleCompletedAction<TResult> = (err?: any, result?: TResult) => void;
/**
* Returns data as buffer.
*
* @param {any} data The input data.
* @param {string} [encoding] The custom encoding to use if 'data' is NOT a buffer.
*
* @return {Buffer} The output data.
*/
export declare function asBuffer(data: any, encoding?: string): Buffer;
/**
* Creates a simple 'completed' callback for a promise.
*
* @param {Function} resolve The 'succeeded' callback.
* @param {Function} reject The 'error' callback.
*
* @return {SimpleCompletedAction<TResult>} The created action.
*/
export declare function createSimplePromiseCompletedAction<TResult>(resolve: (value?: TResult | PromiseLike<TResult>) => void, reject?: (reason: any) => void): SimpleCompletedAction<TResult>;
/**
* Checks if the string representation of a value is empty
* or contains whitespaces only.
*
* @param {any} val The value to check.
*
* @return {boolean} Is empty or not.
*/
export declare function isEmptyString(val: any): boolean;
/**
* Checks if a value is (null) or (undefined).
*
* @param {any} val The value to check.
*
* @return {boolean} Is (null)/(undefined) or not.
*/
export declare function isNullOrUndefined(val: any): boolean;
/**
* Normalizes a value as string so that is comparable.
*
* @param {any} val The value to convert.
* @param {(str: string) => string} [normalizer] The custom normalizer.
*
* @return {string} The normalized value.
*/
export declare function normalizeString(val: any, normalizer?: (str: string) => string): string;
/**
* Reads a number of bytes from a socket.
*
* @param {net.Socket} socket The socket.
* @param {Number} [numberOfBytes] The amount of bytes to read.
*
* @return {Promise<Buffer>} The promise.
*/
export declare function readSocket(socket: Net.Socket, numberOfBytes?: number): Promise<Buffer>;
/**
* Converts a value to a boolean.
*
* @param {any} val The value to convert.
* @param {any} defaultValue The value to return 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 that is NOT (null) or (undefined).
*
* @param {any} str The input value.
* @param {any} defValue The default value.
*
* @return {string} The output value.
*/
export declare function toStringSafe(str: any, defValue?: any): string;