@@ -5,44 +5,15 @@ import Debug from "./debug";
5
5
6
6
import TLSProfiles from "../constants/TLSProfiles" ;
7
7
8
- /**
9
- * Test if two buffers are equal
10
- *
11
- * @export
12
- * @param {Buffer } a
13
- * @param {Buffer } b
14
- * @returns {boolean } Whether the two buffers are equal
15
- */
16
- export function bufferEqual ( a : Buffer , b : Buffer ) : boolean {
17
- if ( typeof a . equals === "function" ) {
18
- return a . equals ( b ) ;
19
- }
20
-
21
- if ( a . length !== b . length ) {
22
- return false ;
23
- }
24
-
25
- for ( let i = 0 ; i < a . length ; ++ i ) {
26
- if ( a [ i ] !== b [ i ] ) {
27
- return false ;
28
- }
29
- }
30
- return true ;
31
- }
32
-
33
8
/**
34
9
* Convert a buffer to string, supports buffer array
35
10
*
36
- * @param {* } value - The input value
37
- * @param {string } encoding - string encoding
38
- * @return {* } The result
39
11
* @example
40
12
* ```js
41
- * var input = [Buffer.from('foo'), [Buffer.from('bar')]]
42
- * var res = convertBufferToString(input, 'utf8')
13
+ * const input = [Buffer.from('foo'), [Buffer.from('bar')]]
14
+ * const res = convertBufferToString(input, 'utf8')
43
15
* expect(res).to.eql(['foo', ['bar']])
44
16
* ```
45
- * @private
46
17
*/
47
18
export function convertBufferToString ( value : any , encoding ?: string ) {
48
19
if ( value instanceof Buffer ) {
@@ -65,17 +36,14 @@ export function convertBufferToString(value: any, encoding?: string) {
65
36
/**
66
37
* Convert a list of results to node-style
67
38
*
68
- * @param {Array } arr - The input value
69
- * @return {Array } The output value
70
39
* @example
71
40
* ```js
72
- * var input = ['a', 'b', new Error('c'), 'd']
73
- * var output = exports.wrapMultiResult(input)
41
+ * const input = ['a', 'b', new Error('c'), 'd']
42
+ * const output = exports.wrapMultiResult(input)
74
43
* expect(output).to.eql([[null, 'a'], [null, 'b'], [new Error('c')], [null, 'd'])
75
44
* ```
76
- * @private
77
45
*/
78
- export function wrapMultiResult ( arr : any [ ] | null ) : any [ ] [ ] {
46
+ export function wrapMultiResult ( arr : unknown [ ] | null ) : unknown [ ] [ ] {
79
47
// When using WATCH/EXEC transactions, the EXEC will return
80
48
// a null instead of an array
81
49
if ( ! arr ) {
@@ -96,9 +64,6 @@ export function wrapMultiResult(arr: any[] | null): any[][] {
96
64
97
65
/**
98
66
* Detect if the argument is a int
99
- *
100
- * @param {string } value
101
- * @return {boolean } Whether the value is a int
102
67
* @example
103
68
* ```js
104
69
* > isInt('123')
@@ -122,8 +87,6 @@ export function isInt(value: any): value is string {
122
87
/**
123
88
* Pack an array to an Object
124
89
*
125
- * @param {array } array
126
- * @return {object }
127
90
* @example
128
91
* ```js
129
92
* > packObject(['a', 'b', 'c', 'd'])
@@ -143,10 +106,6 @@ export function packObject(array: any[]): Record<string, any> {
143
106
144
107
/**
145
108
* Return a callback with timeout
146
- *
147
- * @param {function } callback
148
- * @param {number } timeout
149
- * @return {function }
150
109
*/
151
110
export function timeout ( callback : CallbackFunction , timeout : number ) {
152
111
let timer : NodeJS . Timeout ;
@@ -163,9 +122,6 @@ export function timeout(callback: CallbackFunction, timeout: number) {
163
122
164
123
/**
165
124
* Convert an object to an array
166
- *
167
- * @param {object } obj
168
- * @return {array }
169
125
* @example
170
126
* ```js
171
127
* > convertObjectToArray({ a: '1' })
@@ -174,7 +130,7 @@ export function timeout(callback: CallbackFunction, timeout: number) {
174
130
*/
175
131
export function convertObjectToArray < T > (
176
132
obj : Record < string , T >
177
- ) : Array < string | T > {
133
+ ) : ( string | T ) [ ] {
178
134
const result = [ ] ;
179
135
const keys = Object . keys ( obj ) ; // Object.entries requires node 7+
180
136
@@ -186,16 +142,13 @@ export function convertObjectToArray<T>(
186
142
187
143
/**
188
144
* Convert a map to an array
189
- *
190
- * @param {Map } map
191
- * @return {array }
192
145
* @example
193
146
* ```js
194
147
* > convertMapToArray(new Map([[1, '2']]))
195
148
* [1, '2']
196
149
* ```
197
150
*/
198
- export function convertMapToArray < K , V > ( map : Map < K , V > ) : Array < K | V > {
151
+ export function convertMapToArray < K , V > ( map : Map < K , V > ) : ( K | V ) [ ] {
199
152
const result : Array < K | V > = [ ] ;
200
153
let pos = 0 ;
201
154
map . forEach ( function ( value , key ) {
@@ -208,9 +161,6 @@ export function convertMapToArray<K, V>(map: Map<K, V>): Array<K | V> {
208
161
209
162
/**
210
163
* Convert a non-string arg to a string
211
- *
212
- * @param {* } arg
213
- * @return {string }
214
164
*/
215
165
export function toArg ( arg : any ) : string {
216
166
if ( arg === null || typeof arg === "undefined" ) {
@@ -298,7 +248,7 @@ export function parseURL(url: string) {
298
248
return result ;
299
249
}
300
250
301
- interface ITLSOptions {
251
+ interface TLSOptions {
302
252
port : number ;
303
253
host : string ;
304
254
[ key : string ] : any ;
@@ -310,7 +260,7 @@ interface ITLSOptions {
310
260
* @param {Object } options - the redis connection options
311
261
* @return {Object }
312
262
*/
313
- export function resolveTLSProfile ( options : ITLSOptions ) : ITLSOptions {
263
+ export function resolveTLSProfile ( options : TLSOptions ) : TLSOptions {
314
264
let tls = options ?. tls ;
315
265
316
266
if ( typeof tls === "string" ) tls = { profile : tls } ;
0 commit comments