@creator.co/wapi 1.2.1-beta6 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/.eslintrc.cjs +29 -22
  2. package/.github/workflows/npmpublish.yml +11 -19
  3. package/.github/workflows/prs.yml +13 -0
  4. package/index.ts +12 -10
  5. package/jest.config.ts +39 -0
  6. package/package.json +15 -4
  7. package/src/API/Request.ts +136 -44
  8. package/src/API/Response.ts +256 -46
  9. package/src/API/Utils.ts +60 -7
  10. package/src/BaseEvent/EventProcessor.ts +93 -28
  11. package/src/BaseEvent/Process.ts +69 -13
  12. package/src/BaseEvent/Transaction.ts +29 -50
  13. package/src/Config/Configuration.ts +119 -19
  14. package/src/Config/EnvironmentVar.ts +100 -21
  15. package/src/Crypto/Crypto.ts +78 -19
  16. package/src/Crypto/JWT.ts +53 -13
  17. package/src/Globals.ts +159 -27
  18. package/src/Logger/Logger.ts +204 -65
  19. package/src/Mailer/Mailer.ts +114 -31
  20. package/src/Publisher/Publisher.ts +57 -16
  21. package/src/Server/RouteResolver.ts +141 -0
  22. package/src/Server/Router.ts +84 -12
  23. package/src/Server/lib/ContainerServer.ts +53 -6
  24. package/src/Server/lib/Server.ts +82 -54
  25. package/src/Server/lib/container/GenericHandler.ts +15 -18
  26. package/src/Server/lib/container/GenericHandlerEvent.ts +78 -50
  27. package/src/Server/lib/container/HealthHandler.ts +2 -2
  28. package/src/Server/lib/container/Proxy.ts +114 -45
  29. package/src/Server/lib/container/Utils.ts +18 -27
  30. package/src/Validation/Validator.ts +23 -7
  31. package/tests/API/Request.test.ts +259 -0
  32. package/tests/API/Response.test.ts +367 -0
  33. package/tests/API/Utils.test.ts +157 -0
  34. package/tests/BaseEvent/EventProcessor.test.ts +262 -0
  35. package/tests/BaseEvent/Process.test.ts +49 -0
  36. package/tests/BaseEvent/Transaction.test.ts +222 -0
  37. package/tests/Config/Config.test.ts +193 -0
  38. package/tests/Config/EnvironmentVar.test.ts +214 -0
  39. package/tests/Crypto/Crypto.test.ts +88 -0
  40. package/tests/Crypto/JWT.test.ts +92 -0
  41. package/tests/Logger/Logger.test.ts +96 -0
  42. package/tests/Mailer/Mailer.test.ts +59 -0
  43. package/tests/Publisher/Publisher.test.ts +60 -0
  44. package/tests/Server/RouteResolver.test.ts +103 -0
  45. package/tests/Server/Router.test.ts +38 -0
  46. package/tests/Server/lib/ContainerServer.test.ts +327 -0
  47. package/tests/Server/lib/Server.test.ts +12 -0
  48. package/tests/Server/lib/container/GenericHandler.test.ts +131 -0
  49. package/tests/Server/lib/container/GenericHandlerEvent.test.ts +102 -0
  50. package/tests/Server/lib/container/HealthHandler.test.ts +30 -0
  51. package/tests/Server/lib/container/Proxy.test.ts +265 -0
  52. package/tests/Server/lib/container/Utils.test.ts +47 -0
  53. package/tests/Test.utils.ts +95 -0
  54. package/tests/Validation/Validator.test.ts +76 -0
  55. package/tests/main.test.ts +15 -0
  56. package/tsconfig.json +1 -0
  57. package/dist/index.d.ts +0 -11
  58. package/dist/index.js +0 -24
  59. package/dist/index.js.map +0 -1
  60. package/dist/package.json +0 -53
  61. package/dist/src/API/Request.d.ts +0 -21
  62. package/dist/src/API/Request.js +0 -86
  63. package/dist/src/API/Request.js.map +0 -1
  64. package/dist/src/API/Response.d.ts +0 -39
  65. package/dist/src/API/Response.js +0 -232
  66. package/dist/src/API/Response.js.map +0 -1
  67. package/dist/src/API/Utils.d.ts +0 -8
  68. package/dist/src/API/Utils.js +0 -49
  69. package/dist/src/API/Utils.js.map +0 -1
  70. package/dist/src/BaseEvent/EventProcessor.d.ts +0 -13
  71. package/dist/src/BaseEvent/EventProcessor.js +0 -151
  72. package/dist/src/BaseEvent/EventProcessor.js.map +0 -1
  73. package/dist/src/BaseEvent/Process.d.ts +0 -12
  74. package/dist/src/BaseEvent/Process.js +0 -114
  75. package/dist/src/BaseEvent/Process.js.map +0 -1
  76. package/dist/src/BaseEvent/Transaction.d.ts +0 -29
  77. package/dist/src/BaseEvent/Transaction.js +0 -248
  78. package/dist/src/BaseEvent/Transaction.js.map +0 -1
  79. package/dist/src/Config/Configuration.d.ts +0 -34
  80. package/dist/src/Config/Configuration.js +0 -93
  81. package/dist/src/Config/Configuration.js.map +0 -1
  82. package/dist/src/Config/EnvironmentVar.d.ts +0 -17
  83. package/dist/src/Config/EnvironmentVar.js +0 -152
  84. package/dist/src/Config/EnvironmentVar.js.map +0 -1
  85. package/dist/src/Crypto/Crypto.d.ts +0 -8
  86. package/dist/src/Crypto/Crypto.js +0 -84
  87. package/dist/src/Crypto/Crypto.js.map +0 -1
  88. package/dist/src/Crypto/JWT.d.ts +0 -16
  89. package/dist/src/Crypto/JWT.js +0 -49
  90. package/dist/src/Crypto/JWT.js.map +0 -1
  91. package/dist/src/Globals.d.ts +0 -21
  92. package/dist/src/Globals.js +0 -35
  93. package/dist/src/Globals.js.map +0 -1
  94. package/dist/src/Logger/Logger.d.ts +0 -34
  95. package/dist/src/Logger/Logger.js +0 -345
  96. package/dist/src/Logger/Logger.js.map +0 -1
  97. package/dist/src/Mailer/Mailer.d.ts +0 -12
  98. package/dist/src/Mailer/Mailer.js +0 -234
  99. package/dist/src/Mailer/Mailer.js.map +0 -1
  100. package/dist/src/Publisher/Publisher.d.ts +0 -10
  101. package/dist/src/Publisher/Publisher.js +0 -109
  102. package/dist/src/Publisher/Publisher.js.map +0 -1
  103. package/dist/src/Server/Router.d.ts +0 -27
  104. package/dist/src/Server/Router.js +0 -22
  105. package/dist/src/Server/Router.js.map +0 -1
  106. package/dist/src/Server/lib/ContainerServer.d.ts +0 -11
  107. package/dist/src/Server/lib/ContainerServer.js +0 -103
  108. package/dist/src/Server/lib/ContainerServer.js.map +0 -1
  109. package/dist/src/Server/lib/Server.d.ts +0 -9
  110. package/dist/src/Server/lib/Server.js +0 -141
  111. package/dist/src/Server/lib/Server.js.map +0 -1
  112. package/dist/src/Server/lib/container/GenericHandler.d.ts +0 -4
  113. package/dist/src/Server/lib/container/GenericHandler.js +0 -136
  114. package/dist/src/Server/lib/container/GenericHandler.js.map +0 -1
  115. package/dist/src/Server/lib/container/GenericHandlerEvent.d.ts +0 -14
  116. package/dist/src/Server/lib/container/GenericHandlerEvent.js +0 -164
  117. package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +0 -1
  118. package/dist/src/Server/lib/container/HealthHandler.d.ts +0 -3
  119. package/dist/src/Server/lib/container/HealthHandler.js +0 -44
  120. package/dist/src/Server/lib/container/HealthHandler.js.map +0 -1
  121. package/dist/src/Server/lib/container/Proxy.d.ts +0 -15
  122. package/dist/src/Server/lib/container/Proxy.js +0 -157
  123. package/dist/src/Server/lib/container/Proxy.js.map +0 -1
  124. package/dist/src/Server/lib/container/Utils.d.ts +0 -6
  125. package/dist/src/Server/lib/container/Utils.js +0 -109
  126. package/dist/src/Server/lib/container/Utils.js.map +0 -1
  127. package/dist/src/Validation/Validator.d.ts +0 -5
  128. package/dist/src/Validation/Validator.js +0 -31
  129. package/dist/src/Validation/Validator.js.map +0 -1
@@ -1,31 +1,123 @@
1
- import type { Context } from "aws-lambda"
1
+ import type { Context } from 'aws-lambda'
2
2
 
3
- import Transaction from "../BaseEvent/Transaction"
4
- import Globals from "../Globals"
3
+ import Transaction from '../BaseEvent/Transaction'
4
+ import Globals from '../Globals'
5
5
  //
6
+ /**
7
+ * ${1:Description placeholder}
8
+ *
9
+ * @class CustomError
10
+ * @typedef {CustomError}
11
+ * @extends {Error}
12
+ */
6
13
  class CustomError extends Error {
14
+ /**
15
+ * Creates an instance of CustomError.
16
+ *
17
+ * @constructor
18
+ * @param {*} body
19
+ */
7
20
  constructor(body: any) {
8
- const msg = body && body.message ? body.message : "Unknown error!"
9
- super(msg)
10
- this.name = body && body.error ? body.error : "UnknownError"
21
+ super(body.message || 'Unknown error!')
22
+ this.name = body.error || 'UnknownError'
11
23
  }
12
24
  }
13
25
  //
26
+ /**
27
+ * ${1:Description placeholder}
28
+ *
29
+ * @export
30
+ * @typedef {ResponseErrorType}
31
+ */
14
32
  export type ResponseErrorType = {
15
33
  err: string
16
34
  errCode?: string
17
35
  }
18
36
  //
37
+ /**
38
+ * ${1:Description placeholder}
39
+ *
40
+ * @export
41
+ * @class Response
42
+ * @typedef {Response}
43
+ * @template [BodyType=null]
44
+ */
19
45
  export default class Response<BodyType = null> {
46
+ /**
47
+ * ${1:Description placeholder}
48
+ *
49
+ * @private
50
+ * @type {number}
51
+ */
20
52
  private _statusCode: number
53
+ /**
54
+ * ${1:Description placeholder}
55
+ *
56
+ * @private
57
+ * @type {*}
58
+ */
21
59
  private _body: any
60
+ /**
61
+ * ${1:Description placeholder}
62
+ *
63
+ * @private
64
+ * @type {boolean}
65
+ */
22
66
  private _isPipingOut: boolean
67
+ /**
68
+ * ${1:Description placeholder}
69
+ *
70
+ * @private
71
+ * @type {object}
72
+ */
23
73
  private _headers: object
74
+ /**
75
+ * ${1:Description placeholder}
76
+ *
77
+ * @public
78
+ * @readonly
79
+ * @type {boolean}
80
+ */
24
81
  public readonly shouldStream: boolean
82
+ /**
83
+ * ${1:Description placeholder}
84
+ *
85
+ * @public
86
+ * @readonly
87
+ * @type {boolean}
88
+ */
25
89
  public readonly rawBody: boolean
90
+ /**
91
+ * ${1:Description placeholder}
92
+ *
93
+ * @public
94
+ * @readonly
95
+ * @type {boolean}
96
+ */
26
97
  public readonly throwOnErrors: boolean
98
+ /**
99
+ * ${1:Description placeholder}
100
+ *
101
+ * @public
102
+ * @readonly
103
+ * @type {boolean}
104
+ */
27
105
  public readonly disableTransactionID: boolean
28
106
  //
107
+ /**
108
+ * Creates an instance of Response.
109
+ *
110
+ * @constructor
111
+ * @param {number} statusCode
112
+ * @param {BodyType} body
113
+ * @param {?(| {
114
+ * shouldStream?: boolean
115
+ * rawBody?: boolean
116
+ * throwOnErrors?: boolean
117
+ * disableTransactionID?: boolean
118
+ * }
119
+ * | undefined)\} [optBehaviour]
120
+ */
29
121
  constructor(
30
122
  statusCode: number,
31
123
  body: BodyType,
@@ -36,15 +128,15 @@ export default class Response<BodyType = null> {
36
128
  throwOnErrors?: boolean
37
129
  disableTransactionID?: boolean
38
130
  }
39
- | undefined,
131
+ | undefined
40
132
  ) {
41
133
  // response
42
134
  this._statusCode = statusCode
43
135
  this._body = body
44
136
  this._headers = {
45
- "Access-Control-Allow-Origin": "*",
46
- "Access-Control-Allow-Credentials": true,
47
- "Content-Type": "application/json",
137
+ 'Access-Control-Allow-Origin': '*',
138
+ 'Access-Control-Allow-Credentials': true,
139
+ 'Content-Type': 'application/json',
48
140
  }
49
141
  // behaviour
50
142
  this._isPipingOut = false //internal -- flag to indicate streaming out has started and avoid double stream call
@@ -54,34 +146,66 @@ export default class Response<BodyType = null> {
54
146
  this.throwOnErrors = !!optBehaviour?.throwOnErrors
55
147
  this.disableTransactionID = !!optBehaviour?.disableTransactionID
56
148
  }
149
+ /**
150
+ * ${1:Description placeholder}
151
+ *
152
+ * @public
153
+ * @returns {number}
154
+ */
57
155
  public getCode(): number {
58
156
  return this._statusCode
59
157
  }
158
+ /**
159
+ * ${1:Description placeholder}
160
+ *
161
+ * @public
162
+ * @returns {BodyType}
163
+ */
60
164
  public getBody(): BodyType {
61
165
  return this._body
62
166
  }
167
+ /**
168
+ * ${1:Description placeholder}
169
+ *
170
+ * @public
171
+ * @param {string} key
172
+ * @param {*} value
173
+ */
63
174
  public appendIntoBody(key: string, value: any): void {
64
175
  this._body[key] = value
65
176
  }
177
+ /**
178
+ * ${1:Description placeholder}
179
+ *
180
+ * @public
181
+ * @param {string} key
182
+ * @param {*} value
183
+ */
66
184
  public appendHeader(key: string, value: any): void {
67
185
  this._headers[key] = value
68
186
  }
187
+ /**
188
+ * ${1:Description placeholder}
189
+ *
190
+ * @public
191
+ * @async
192
+ * @param {Context} context
193
+ * @param {Transaction<any, any, any>} transaction
194
+ * @param {boolean} _optDoNotCallContext
195
+ * @returns {Promise<void>}
196
+ */
69
197
  public async build(
70
198
  context: Context,
71
199
  transaction: Transaction<any, any, any>,
72
- _optDoNotCallContext: boolean,
200
+ _optDoNotCallContext: boolean
73
201
  ): Promise<void> {
74
202
  //Stream support
75
203
  if (this._isPipingOut) return
76
204
  if (this.shouldStream) return this._pipe(context)
77
205
 
78
206
  //append default fields
79
- if (
80
- transaction.request.getRequestID() &&
81
- this._body &&
82
- !this.disableTransactionID
83
- )
84
- this.appendIntoBody("transactionID", transaction.request.getRequestID()) //append transaction ID
207
+ if (transaction.request.getRequestID() && this._body && !this.disableTransactionID)
208
+ this.appendIntoBody('transactionID', transaction.request.getRequestID()) //append transaction ID
85
209
  //Raw response support
86
210
  if (this.rawBody) return this._rawContext(context, transaction)
87
211
 
@@ -98,9 +222,14 @@ export default class Response<BodyType = null> {
98
222
  //Batch does not succeed directly just on upper transaction (which will should be a batch)
99
223
  if (!_optDoNotCallContext) context.succeed(b)
100
224
  }
225
+ /**
226
+ * ${1:Description placeholder}
227
+ *
228
+ * @private
229
+ * @param {Context} context
230
+ */
101
231
  private _pipe(context: Context): void {
102
232
  //Check if not streaming
103
- if (this._isPipingOut) return
104
233
  this._isPipingOut = true
105
234
  //build response
106
235
  const b = {
@@ -111,14 +240,17 @@ export default class Response<BodyType = null> {
111
240
  //log response and respond to context
112
241
  context.succeed(b)
113
242
  }
114
- private _rawContext(
115
- context: Context,
116
- transaction: Transaction<null, BodyType>,
117
- ): void {
243
+ /**
244
+ * ${1:Description placeholder}
245
+ *
246
+ * @private
247
+ * @param {Context} context
248
+ * @param {Transaction<null, BodyType>} transaction
249
+ */
250
+ private _rawContext(context: Context, transaction: Transaction<null, BodyType>): void {
118
251
  //log response and respond to context
119
252
  transaction.logger.debug(this._body)
120
- if (this.getCode() <= 200 && this.getCode() <= 299)
121
- context.succeed(this._body)
253
+ if (this.getCode() <= 200 && this.getCode() <= 299) context.succeed(this._body)
122
254
  else {
123
255
  if (!this.throwOnErrors) context.fail(new CustomError(this._body))
124
256
  else throw new CustomError(this._body)
@@ -126,28 +258,50 @@ export default class Response<BodyType = null> {
126
258
  }
127
259
 
128
260
  /* Shortcuts */
129
- public static MissingParamResponse(
130
- paramName: string,
131
- ): Response<ResponseErrorType> {
261
+ /**
262
+ * ${1:Description placeholder}
263
+ *
264
+ * @public
265
+ * @static
266
+ * @param {string} paramName
267
+ * @returns {Response<ResponseErrorType>}
268
+ */
269
+ public static MissingParamResponse(paramName: string): Response<ResponseErrorType> {
132
270
  console.warn(`Invalid request - Path parameter ${paramName} is missing.`)
133
271
  return new Response<ResponseErrorType>(400, {
134
272
  err: `Invalid request. Path parameter ${paramName} is missing.`,
135
273
  errCode: Globals.ErrorCode_MissingParam,
136
274
  })
137
275
  }
138
- public static MissingQueryResponse(
139
- paramName: string,
140
- ): Response<ResponseErrorType> {
276
+ /**
277
+ * ${1:Description placeholder}
278
+ *
279
+ * @public
280
+ * @static
281
+ * @param {string} paramName
282
+ * @returns {Response<ResponseErrorType>}
283
+ */
284
+ public static MissingQueryResponse(paramName: string): Response<ResponseErrorType> {
141
285
  console.warn(`Invalid request - Query parameter ${paramName} is missing.`)
142
286
  return new Response<ResponseErrorType>(400, {
143
287
  err: `Invalid request. Query parameter ${paramName} is missing.`,
144
288
  errCode: Globals.ErrorCode_MissingParam,
145
289
  })
146
290
  }
291
+ /**
292
+ * ${1:Description placeholder}
293
+ *
294
+ * @public
295
+ * @static
296
+ * @param {?string} [msg]
297
+ * @param {?string} [errCode]
298
+ * @param {?*} [optBody]
299
+ * @returns {Response<ResponseErrorType>}
300
+ */
147
301
  public static BadRequestResponse(
148
302
  msg?: string,
149
303
  errCode?: string,
150
- optBody?: any,
304
+ optBody?: any
151
305
  ): Response<ResponseErrorType> {
152
306
  console.warn(`Bad request - ${msg}`)
153
307
  return new Response<ResponseErrorType>(400, {
@@ -156,10 +310,20 @@ export default class Response<BodyType = null> {
156
310
  ...(optBody || {}),
157
311
  })
158
312
  }
313
+ /**
314
+ * ${1:Description placeholder}
315
+ *
316
+ * @public
317
+ * @static
318
+ * @param {string} msg
319
+ * @param {?string} [errCode]
320
+ * @param {?*} [optBody]
321
+ * @returns {Response<ResponseErrorType>}
322
+ */
159
323
  public static BadRequestResponseWithRollback(
160
324
  msg: string,
161
- errCode: string,
162
- optBody?: any,
325
+ errCode?: string,
326
+ optBody?: any
163
327
  ): Response<ResponseErrorType> {
164
328
  console.warn(`Bad request - ${msg}`)
165
329
  return new Response<ResponseErrorType>(400, {
@@ -169,41 +333,87 @@ export default class Response<BodyType = null> {
169
333
  ...(optBody || {}),
170
334
  })
171
335
  }
172
- public static UnauthorizedResponse(
173
- msg: string,
174
- errCode: string,
175
- ): Response<ResponseErrorType> {
336
+ /**
337
+ * ${1:Description placeholder}
338
+ *
339
+ * @public
340
+ * @static
341
+ * @param {string} msg
342
+ * @param {?string} [errCode]
343
+ * @returns {Response<ResponseErrorType>}
344
+ */
345
+ public static UnauthorizedResponse(msg: string, errCode?: string): Response<ResponseErrorType> {
176
346
  console.warn(`Denying request - ${msg}`)
177
347
  return new Response<ResponseErrorType>(401, {
178
348
  err: msg,
179
349
  ...(errCode ? { errCode: errCode } : {}),
180
350
  })
181
351
  }
352
+ /**
353
+ * ${1:Description placeholder}
354
+ *
355
+ * @public
356
+ * @static
357
+ * @template BodyType
358
+ * @param {BodyType} body
359
+ * @returns {Response<BodyType>}
360
+ */
182
361
  public static SuccessResponse<BodyType>(body: BodyType): Response<BodyType> {
183
362
  return new Response<BodyType>(200, (body ? body : {}) as BodyType)
184
363
  }
364
+ /**
365
+ * ${1:Description placeholder}
366
+ *
367
+ * @public
368
+ * @static
369
+ * @param {string} url
370
+ * @returns {Response<null>}
371
+ */
185
372
  public static RedirectResponse(url: string): Response<null> {
186
373
  const resp = new Response<null>(302, null)
187
- resp.appendHeader("Location", url)
374
+ resp.appendHeader('Location', url)
188
375
  return resp
189
376
  }
377
+ /**
378
+ * ${1:Description placeholder}
379
+ *
380
+ * @public
381
+ * @static
382
+ * @returns {Response<null>}
383
+ */
190
384
  public static SuccessNoContentResponse(): Response<null> {
191
385
  return new Response<null>(204, null)
192
386
  }
193
- public static SuccessStreamResponse(
194
- stream: any,
195
- contentType: string,
196
- ): Response {
197
- const resp = new Response(200, stream ? stream : {}, {
387
+ /**
388
+ * ${1:Description placeholder}
389
+ *
390
+ * @public
391
+ * @static
392
+ * @param {*} stream
393
+ * @param {string} contentType
394
+ * @returns {Response}
395
+ */
396
+ public static SuccessStreamResponse(stream: any, contentType: string): Response {
397
+ const resp = new Response(200, stream, {
198
398
  shouldStream: true,
199
399
  })
200
- resp.appendHeader("Connection", "keep-alive")
201
- if (contentType) resp.appendHeader("Content-type", contentType)
400
+ resp.appendHeader('Connection', 'keep-alive')
401
+ if (contentType) resp.appendHeader('Content-Type', contentType)
202
402
  return resp
203
403
  }
404
+ /**
405
+ * ${1:Description placeholder}
406
+ *
407
+ * @public
408
+ * @static
409
+ * @template BodyType
410
+ * @param {BodyType} body
411
+ * @param {?number} [optionalCode]
412
+ * @returns {Response<BodyType>}
413
+ */
204
414
  public static SimpleResponse<BodyType>(
205
415
  body: BodyType,
206
- optionalCode?: number,
416
+ optionalCode?: number
207
417
  ): Response<BodyType> {
208
418
  const resp = new Response<BodyType>(optionalCode || 200, body)
209
419
  return resp
package/src/API/Utils.ts CHANGED
@@ -1,14 +1,52 @@
1
+ /**
2
+ * ${1:Description placeholder}
3
+ *
4
+ * @export
5
+ * @class Utils
6
+ * @typedef {Utils}
7
+ */
1
8
  export default class Utils {
9
+ /**
10
+ * ${1:Description placeholder}
11
+ *
12
+ * @public
13
+ * @static
14
+ * @returns {boolean}
15
+ */
2
16
  public static isHybridlessContainer(): boolean {
3
- return !!process.env.HYBRIDLESS_RUNTIME
17
+ return process.env.HYBRIDLESS_RUNTIME == 'true'
4
18
  }
19
+ /**
20
+ * ${1:Description placeholder}
21
+ *
22
+ * @public
23
+ * @static
24
+ * @param {string} string
25
+ * @returns {boolean}
26
+ */
5
27
  public static isValidString(string: string): boolean {
6
28
  return string?.length > 0 && !Array.isArray(string)
7
29
  }
30
+ /**
31
+ * ${1:Description placeholder}
32
+ *
33
+ * @public
34
+ * @static
35
+ * @param {string} string
36
+ * @returns {(number | null)}
37
+ */
8
38
  public static parseIntNullIfNaN(string: string): number | null {
9
39
  const n = parseInt(string)
10
40
  return isNaN(n) ? null : n
11
41
  }
42
+ /**
43
+ * ${1:Description placeholder}
44
+ *
45
+ * @public
46
+ * @static
47
+ * @param {string} string
48
+ * @returns {(any | null)}
49
+ */
12
50
  public static parseObjectNullIfEmpty(string: string): any | null {
13
51
  let o = null
14
52
  try {
@@ -19,21 +57,36 @@ export default class Utils {
19
57
  }
20
58
  return o
21
59
  }
60
+ /**
61
+ * ${1:Description placeholder}
62
+ *
63
+ * @public
64
+ * @static
65
+ * @param {string} number
66
+ * @returns {boolean}
67
+ */
22
68
  public static isValidNumber(number: string): boolean {
23
69
  let validNumb = NaN
24
70
  try {
25
- validNumb = parseInt(number + "")
71
+ validNumb = parseInt(number + '')
26
72
  } catch (e) {
27
- console.error("Error while validating number", e)
73
+ console.error('Error while validating number', e)
28
74
  }
29
75
  return !isNaN(validNumb) && !Array.isArray(number)
30
76
  }
77
+ /**
78
+ * ${1:Description placeholder}
79
+ *
80
+ * @public
81
+ * @static
82
+ * @param {*} obj
83
+ * @param {string} key
84
+ * @returns {(any | null)}
85
+ */
31
86
  public static caseInsensitiveObjectForKey(obj: any, key: string): any | null {
32
87
  if (!obj) return null
33
- const insensitiveKey = Object.keys(obj).find(
34
- (k) => k.toLowerCase() === key.toLowerCase(),
35
- )
36
- if (insensitiveKey && insensitiveKey != "") return obj[insensitiveKey]
88
+ const insensitiveKey = Object.keys(obj).find(k => k.toLowerCase() === key.toLowerCase())
89
+ if (insensitiveKey && insensitiveKey != '') return obj[insensitiveKey]
37
90
  return null
38
91
  }
39
92
  }