topkat-utils 1.3.24 → 1.3.26

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 (66) hide show
  1. package/README.md +1 -1
  2. package/backend.ts +3 -4
  3. package/dist/backend.js +3 -4
  4. package/dist/backend.js.map +1 -1
  5. package/dist/src/array-utils.d.ts +1 -1
  6. package/dist/src/array-utils.js +2 -2
  7. package/dist/src/array-utils.js.map +1 -1
  8. package/dist/src/clean-stack-trace.js.map +1 -1
  9. package/dist/src/date-utils.d.ts +25 -20
  10. package/dist/src/date-utils.js +1 -0
  11. package/dist/src/date-utils.js.map +1 -1
  12. package/dist/src/env-utils.d.ts +1 -1
  13. package/dist/src/env-utils.js.map +1 -1
  14. package/dist/src/error-utils.d.ts +6 -6
  15. package/dist/src/error-utils.js.map +1 -1
  16. package/dist/src/isset.js.map +1 -1
  17. package/dist/src/logger-utils.d.ts +33 -30
  18. package/dist/src/logger-utils.js +10 -29
  19. package/dist/src/logger-utils.js.map +1 -1
  20. package/dist/src/loop-utils.d.ts +4 -4
  21. package/dist/src/loop-utils.js.map +1 -1
  22. package/dist/src/mongo-utils.js.map +1 -1
  23. package/dist/src/object-utils.d.ts +4 -4
  24. package/dist/src/object-utils.js +1 -1
  25. package/dist/src/object-utils.js.map +1 -1
  26. package/dist/src/regexp-utils.d.ts +1 -1
  27. package/dist/src/regexp-utils.js.map +1 -1
  28. package/dist/src/remove-circular-json-stringify.js.map +1 -1
  29. package/dist/src/string-utils.d.ts +4 -4
  30. package/dist/src/string-utils.js +1 -1
  31. package/dist/src/string-utils.js.map +1 -1
  32. package/dist/src/tests-utils.js.map +1 -1
  33. package/dist/src/timer-utils.d.ts +4 -4
  34. package/dist/src/timer-utils.js +1 -1
  35. package/dist/src/timer-utils.js.map +1 -1
  36. package/dist/src/transaction-utils.d.ts +3 -3
  37. package/dist/src/transaction-utils.js.map +1 -1
  38. package/dist/src/transaction-utils.spec.js +1 -1
  39. package/dist/src/transaction-utils.spec.js.map +1 -1
  40. package/dist/src/validation-utils.d.ts +3 -3
  41. package/dist/src/validation-utils.js +17 -16
  42. package/dist/src/validation-utils.js.map +1 -1
  43. package/dist/src/wtf-utils.d.ts +3 -3
  44. package/dist/src/wtf-utils.js +1 -1
  45. package/dist/src/wtf-utils.js.map +1 -1
  46. package/package.json +1 -1
  47. package/src/array-utils.ts +3 -3
  48. package/src/clean-stack-trace.ts +1 -1
  49. package/src/date-utils.ts +45 -41
  50. package/src/env-utils.ts +1 -1
  51. package/src/error-utils.ts +8 -8
  52. package/src/isset.ts +1 -1
  53. package/src/logger-utils.ts +40 -52
  54. package/src/loop-utils.ts +5 -5
  55. package/src/mongo-utils.ts +1 -1
  56. package/src/object-utils.ts +22 -22
  57. package/src/regexp-utils.ts +3 -3
  58. package/src/remove-circular-json-stringify.ts +2 -2
  59. package/src/string-utils.ts +3 -3
  60. package/src/tests-utils.ts +1 -1
  61. package/src/timer-utils.ts +4 -4
  62. package/src/transaction-utils.spec.ts +1 -1
  63. package/src/transaction-utils.ts +5 -5
  64. package/src/validation-utils.ts +28 -26
  65. package/src/wtf-utils.ts +6 -6
  66. package/tsconfig.json +1 -1
@@ -26,7 +26,7 @@ function compAuto(str) {
26
26
  const utf8Chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ:;<=>%?@"#$&\'()*+,-./[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\u007f€\u0081‚ƒ„…†‡ˆ‰Š‹ŒŽ\u008f‘’“”•–—˜™š›œžŸ ¡¢£¤¥¦¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋŌōŎŏŐőŔŕŖŗŘřŚśŜŝŞşŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŹźŻżſƀƁƂƃƄƅƆƇƈƉƊƋƌƍƎƏƐƑƓƔƕƖƗƘƙƚƛƜƝƞƟ'.split('');
27
27
  const unusedChars = utf8Chars.filter(c => !str.includes(c));
28
28
  const charMap = [];
29
- const mostFreqStr = str2 => {
29
+ const mostFreqStr = (str2) => {
30
30
  const o = {};
31
31
  // recherche la meilleure optim selon le nb de char
32
32
  for (let strLength = 2; strLength < 16; strLength++) {
@@ -1 +1 @@
1
- {"version":3,"file":"wtf-utils.js","sourceRoot":"","sources":["../../src/wtf-utils.ts"],"names":[],"mappings":";AAAA,0CAA0C;AAC1C,YAAY;AACZ,0CAA0C;;;AAE1C,iDAA6C;AAC7C,iDAAkC;AAClC,mCAA+B;AAE/B,SAAgB,cAAc;IAC1B,eAAe;IACf,MAAM,GAAG,GAAG,0kBAA0kB,CAAA;IACtlB,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,CAAA;AAClJ,CAAC;AAJD,wCAIC;AAED,SAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,EAAE;IACxC,MAAM,CAAC,GAAG,u4IAAu4I,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG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C,CAAA;IACjG,OAAO,GAAG,CAAA;AACd,CAAC;AA5CD,4BA4CC;AAED,SAAgB,MAAM,CAAC,GAAW;IAC9B,MAAM,OAAO,GAAiB,EAAE,CAAA;IAChC,MAAM,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAC1B,GAAG,GAAG,GAAG,CAAC,GAAG,EAAY,CAAA;IACzB,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;QACZ,MAAM,IAAI,GAAW,CAAC,CAAC,CAAC,CAAC,CAAA;QACzB,IAAI,WAAW,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;QACrC,IAAI,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;YAC3B,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,CAAqB,CAAA;YAC7D,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAA;SAC1C;QACD,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CAAA;IACvC,CAAC,CAAC,CAAA;IAEF,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,EAAE,CACtC,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,IAAA,2BAAY,EAAC,IAAI,CAAC,EAAE,GAAG,CAAC,EAAE,WAAW,CAAC,CAAC,gBAAgB;KACvF,CAAA;IAED,OAAO,GAAG,CAAA;AACd,CAAC;AAnBD,wBAmBC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "topkat-utils",
3
- "version": "1.3.24",
3
+ "version": "1.3.26",
4
4
  "type": "commonjs",
5
5
  "types": "index.ts",
6
6
  "main": "dist",
@@ -23,10 +23,10 @@ export function shuffleArray<EntryArray extends any[]>(array: EntryArray): Entry
23
23
  * @return obj[addr] eventually processed by the callback
24
24
  */
25
25
  export function ensureIsArrayAndPush(obj: object, addr: string, valToPush: any, onlyUniqueValues?: Function) {
26
- return ensureObjectProp(obj, addr, [], objValue => {
26
+ return ensureObjectProp(obj, addr, [], (objValue: any) => {
27
27
  if (isset(onlyUniqueValues)) {
28
28
  let duplicateFound = false
29
- if (typeof onlyUniqueValues === 'function') duplicateFound = objValue.some(a => onlyUniqueValues(a, valToPush))
29
+ if (typeof onlyUniqueValues === 'function') duplicateFound = objValue.some((a: any) => onlyUniqueValues(a, valToPush))
30
30
  else duplicateFound = objValue.includes(valToPush)
31
31
  if (!duplicateFound) objValue.push(valToPush)
32
32
  } else objValue.push(valToPush)
@@ -102,7 +102,7 @@ export function pushIfNotExist<T>(arrayToPushInto: T[], valueOrArrayOfValuesToBe
102
102
  return arrayToPushInto
103
103
  }
104
104
 
105
- export function isNotEmptyArray(arr): boolean {
105
+ export function isNotEmptyArray(arr: any[]): boolean {
106
106
  return Array.isArray(arr) && !!arr.length
107
107
  }
108
108
 
@@ -1,5 +1,5 @@
1
1
 
2
- export function cleanStackTrace(stack) {
2
+ export function cleanStackTrace(stack: any) {
3
3
  if (typeof stack !== 'string') return ''
4
4
  stack.replace(/home\/[^/]+\/[^/]+\//g, '')
5
5
  const lines = stack.split('\n')
package/src/date-utils.ts CHANGED
@@ -8,17 +8,19 @@ import { err422IfNotSet } from './error-utils'
8
8
 
9
9
  const int = parseInt
10
10
 
11
- export function getDateAsInt12(dateAllFormat?: Date | string | number, errIfNotValid?): string { return getDateAsInt(dateAllFormat, errIfNotValid, true) } // alias
11
+ export function getDateAsInt12(dateAllFormat?: Date | string | number, errIfNotValid?: any): string { return getDateAsInt(dateAllFormat, errIfNotValid, true) } // alias
12
12
 
13
- export function humanReadableTimestamp(dateAllFormat: any): number {
13
+ export function humanReadableTimestamp(dateAllFormat: DateAllFormat): number {
14
14
  if (isset(dateAllFormat)) dateAllFormat = getDateAsObject(dateAllFormat)
15
- return parseInt(getDateAsInt12(dateAllFormat) + pad((dateAllFormat || new Date()).getUTCSeconds()) + pad((dateAllFormat || new Date()).getUTCMilliseconds(), 3))
15
+ return parseInt(getDateAsInt12(dateAllFormat) + pad(((dateAllFormat as Date) || new Date()).getUTCSeconds()) + pad(((dateAllFormat as Date) || new Date()).getUTCMilliseconds(), 3))
16
16
  }
17
17
 
18
+ // type DateAllFormat = Date | string | number
19
+
18
20
  /** format for 6/8/2018 => 20180806
19
21
  * @param dateAllFormat multiple format allowed 2012, 20120101, 201201011200, new Date(), "2019-12-08T16:19:10.341Z" and all string that new Date() can parse
20
22
  */
21
- export function getDateAsInt(dateAllFormat: Date | string | number = new Date(), errIfNotValid$ = false, withHoursAndMinutes$ = false): string { // optional
23
+ export function getDateAsInt(dateAllFormat: DateAllFormat = new Date(), errIfNotValid$ = false, withHoursAndMinutes$ = false): string { // optional
22
24
  let dateInt
23
25
  if (typeof dateAllFormat === 'string' && dateAllFormat.includes('/')) {
24
26
  // 01/01/2020 format
@@ -39,7 +41,7 @@ export function getDateAsInt(dateAllFormat: Date | string | number = new Date(),
39
41
  }
40
42
 
41
43
 
42
- export function getMonthAsInt(dateAllFormat: Date | string | number = new Date()): number {
44
+ export function getMonthAsInt(dateAllFormat: DateAllFormat = new Date()): number {
43
45
  let dateInt
44
46
  if (isDateIntOrStringValid(dateAllFormat)) {
45
47
  // we can pass an int or string format (20180106)
@@ -55,22 +57,22 @@ export function getMonthAsInt(dateAllFormat: Date | string | number = new Date()
55
57
  /**
56
58
  * @param dateAllFormat multiple format allowed 2012, 20120101, 201201011200, new Date(), "2019-12-08T16:19:10.341Z" and all string that new Date() can parse
57
59
  */
58
- export function getDateAsObject(dateAllFormat: any = new Date(), errIfNotValid$ = true): Date {
60
+ export function getDateAsObject(dateAllFormat: DateAllFormat = new Date(), errIfNotValid$ = true): Date {
59
61
  let dateObj = dateAllFormat
60
62
  if (isDateIntOrStringValid(dateAllFormat)) {
61
- const [y, M, d, h, m] = dateStringToArray(dateAllFormat)
63
+ const [y, M, d, h, m] = dateStringToArray(dateAllFormat as string)
62
64
  dateObj = new Date(`${y}-${M}-${d}T${h}:${m}`)
63
65
  } else if (typeof dateAllFormat === 'string') {
64
66
  dateObj = new Date(dateAllFormat)
65
67
  } else {
66
- dateObj = new Date(dateAllFormat.getTime()) // clone
68
+ dateObj = new Date((dateAllFormat as Date).getTime()) // clone
67
69
  }
68
70
  isDateIsoOrObjectValid(dateObj, errIfNotValid$)
69
71
  return dateObj
70
72
  }
71
73
 
72
74
  /** [2018,01,06] */
73
- export function dateStringToArray(strOrInt) {
75
+ export function dateStringToArray(strOrInt: string | number) {
74
76
  err422IfNotSet({ strOrInt })
75
77
 
76
78
  const dateStr = strOrInt.toString()
@@ -88,7 +90,7 @@ export function dateStringToArray(strOrInt) {
88
90
  /**
89
91
  * @param dateAllFormat default: actualDate
90
92
  * @returns ['01', '01', '2019'] OR **string** if separator is provided */
91
- export function dateArray(dateAllFormat: Date | string | number = getDateAsInt()): [string, string, string] {
93
+ export function dateArray(dateAllFormat: DateAllFormat = getDateAsInt()): [string, string, string] {
92
94
  const dateStr = getDateAsInt(dateAllFormat).toString()
93
95
  return [
94
96
  dateStr.substr(6, 2), // D
@@ -100,7 +102,7 @@ export function dateArray(dateAllFormat: Date | string | number = getDateAsInt()
100
102
  /**
101
103
  * @param dateAllFormat default: actualDate
102
104
  * @returns ['01', '01', '2019'] OR **string** if separator is provided */
103
- export function dateArrayInt(dateAllFormat: Date | string | number = getDateAsInt()): [number, number, number] {
105
+ export function dateArrayInt(dateAllFormat: DateAllFormat = getDateAsInt()): [number, number, number] {
104
106
  const dateStr = getDateAsInt(dateAllFormat).toString()
105
107
  return [
106
108
  int(dateStr.substr(6, 2)), // D
@@ -113,10 +115,10 @@ export function dateArrayInt(dateAllFormat: Date | string | number = getDateAsIn
113
115
  /**
114
116
  * @return 01/01/2012 (alias of dateArrayFormatted(date, '/'))
115
117
  */
116
- export function dateFormatted(dateAllFormat: Date | string | number, separator = '/') { return dateArray(dateAllFormat).join(separator) }
118
+ export function dateFormatted(dateAllFormat: DateAllFormat, separator = '/') { return dateArray(dateAllFormat).join(separator) }
117
119
 
118
120
  /** Date with custom offset (Ex: +2 for France) */
119
- export function dateOffset(offsetHours, dateObj = new Date()) {
121
+ export function dateOffset(offsetHours: number, dateObj = new Date()) {
120
122
 
121
123
  const utc = Date.UTC(dateObj.getUTCFullYear(), dateObj.getUTCMonth(), dateObj.getUTCDate(),
122
124
  dateObj.getUTCHours(), dateObj.getUTCMinutes(), dateObj.getUTCSeconds())
@@ -148,7 +150,7 @@ export function getIntAsTime(intOrDateTimeInt = getDateAsInt12(), separator = ':
148
150
  return time.substring(tl - 4, tl - 2) + separator + time.substring(tl - 2, tl)
149
151
  }
150
152
 
151
- export function isTimeStringValid(timeStr, outputAnError$ = false) {
153
+ export function isTimeStringValid(timeStr: string, outputAnError$ = false) {
152
154
  const timeArr = timeStr.split(':')
153
155
  const h = int(timeArr[0])
154
156
  const m = int(timeArr[1])
@@ -162,7 +164,7 @@ export function isTimeStringValid(timeStr, outputAnError$ = false) {
162
164
  // DURATIONS
163
165
  //----------------------------------------
164
166
 
165
- export function getDuration(startDate, endDate, inMinutes = false) {
167
+ export function getDuration(startDate: any, endDate: any, inMinutes = false) {
166
168
  const startDateO = getDateAsObject(startDate)
167
169
  const endDateO = getDateAsObject(endDate)
168
170
  const diffInSec = Math.floor(endDateO.getTime() / 1000) - Math.floor(startDateO.getTime() / 1000)
@@ -175,6 +177,7 @@ export function getDuration(startDate, endDate, inMinutes = false) {
175
177
  ]
176
178
  }
177
179
 
180
+ type DateEvent = { startDate: any, endDate: any }
178
181
  /** compare two object with DATE INT, if they overlap return true
179
182
  * @param {Object} event1 {startDate, endDate}
180
183
  * @param {Object} event2 {startDate, endDate}
@@ -183,7 +186,7 @@ export function getDuration(startDate, endDate, inMinutes = false) {
183
186
  * @param {Boolean} allowNull$ if false, retrun false if any of the startdates or enddates are not set
184
187
  * @param {Boolean} strict$ if true,
185
188
  */
186
- export function doDateOverlap(event1, event2, fieldNameForStartDate$ = 'startDate', fieldNameForEndDate$ = 'endDate', allowNull$ = true, strict$ = false) {
189
+ export function doDateOverlap(event1: DateEvent, event2: DateEvent, fieldNameForStartDate$ = 'startDate' as const, fieldNameForEndDate$ = 'endDate' as const, allowNull$ = true, strict$ = false) {
187
190
  if (!allowNull$ && !isset(event1[fieldNameForStartDate$], event1[fieldNameForEndDate$], event2[fieldNameForStartDate$], event2[fieldNameForEndDate$])) return false
188
191
 
189
192
  if (strict$)
@@ -192,13 +195,14 @@ export function doDateOverlap(event1, event2, fieldNameForStartDate$ = 'startDat
192
195
  return (!event2[fieldNameForEndDate$] || event1[fieldNameForStartDate$] <= event2[fieldNameForEndDate$]) && (!event1[fieldNameForEndDate$] || event1[fieldNameForEndDate$] >= event2[fieldNameForStartDate$])
193
196
  }
194
197
 
195
- type DateAllFormat = DateObjectFormat | DateStringFormats
198
+ type DateAllFormat = Date | string | number
199
+ type DateAllFormatString = DateObjectFormat | DateStringFormats
196
200
  type DateStringFormats = 'dateInt8' | 'dateInt12' | 'humanReadableTimestamp'
197
201
  type DateObjectFormat = 'date'
198
202
 
199
- export function nextWeekDay(fromDate, weekDayInt?: 0 | 1 | 2 | 3 | 4 | 5 | 6, outputFormat?: DateStringFormats, sameDayAllowed?: boolean): number
200
- export function nextWeekDay(fromDate, weekDayInt?: 0 | 1 | 2 | 3 | 4 | 5 | 6, outputFormat?: DateObjectFormat, sameDayAllowed?: boolean): Date
201
- export function nextWeekDay(fromDate, weekDayInt?: 0 | 1 | 2 | 3 | 4 | 5 | 6, outputFormat = 'date', sameDayAllowed = false): any {
203
+ export function nextWeekDay(fromDate: any, weekDayInt?: 0 | 1 | 2 | 3 | 4 | 5 | 6, outputFormat?: DateStringFormats, sameDayAllowed?: boolean): number
204
+ export function nextWeekDay(fromDate: any, weekDayInt?: 0 | 1 | 2 | 3 | 4 | 5 | 6, outputFormat?: DateObjectFormat, sameDayAllowed?: boolean): Date
205
+ export function nextWeekDay(fromDate: any, weekDayInt?: 0 | 1 | 2 | 3 | 4 | 5 | 6, outputFormat = 'date', sameDayAllowed = false): any {
202
206
  const date = getDateAsObject(fromDate)
203
207
  if (typeof weekDayInt === 'undefined') weekDayInt = (date.getDay() as 0 | 1 | 2 | 3 | 4 | 5 | 6)
204
208
  const toAdd = !sameDayAllowed && date.getDay() === weekDayInt ? 7 : 0
@@ -211,7 +215,7 @@ export function nextWeekDay(fromDate, weekDayInt?: 0 | 1 | 2 | 3 | 4 | 5 | 6, ou
211
215
  */
212
216
  export function addDays(dateAllFormat?: Date | string | number, numberOfDays?: number, outputFormat?: 'dateInt8' | 'dateInt12' | 'humanReadableTimestamp'): string
213
217
  export function addDays(dateAllFormat?: Date | string | number, numberOfDays?: number, outputFormat?: 'date'): Date
214
- export function addDays(dateAllFormat: Date | string | number = getDateAsInt(), numberOfDays = 1, outputFormat: DateAllFormat = 'date'): any {
218
+ export function addDays(dateAllFormat: DateAllFormat = getDateAsInt(), numberOfDays = 1, outputFormat: DateAllFormatString = 'date'): any {
215
219
  const date = getDateAsObject(dateAllFormat)
216
220
  date.setTime(date.getTime() + numberOfDays * 24 * 60 * 60 * 1000)
217
221
  return getDateAs(date, outputFormat as any)
@@ -222,7 +226,7 @@ export function addDays(dateAllFormat: Date | string | number = getDateAsInt(),
222
226
  */
223
227
  export function addMinutes(dateAllFormat?: Date | string | number, numberOfMinutes?: number, outputFormat?: DateStringFormats): string
224
228
  export function addMinutes(dateAllFormat?: Date | string | number, numberOfMinutes?: number, outputFormat?: DateObjectFormat): Date
225
- export function addMinutes(dateAllFormat: Date | string | number = getDateAsInt(), numberOfMinutes = 1, outputFormat: DateAllFormat = 'date'): any {
229
+ export function addMinutes(dateAllFormat: DateAllFormat = getDateAsInt(), numberOfMinutes = 1, outputFormat: DateAllFormatString = 'date'): any {
226
230
  const date = getDateAsObject(dateAllFormat)
227
231
  date.setTime(date.getTime() + 1 * numberOfMinutes * 60 * 1000)
228
232
  return getDateAs(date, outputFormat as any)
@@ -232,7 +236,7 @@ export function addMinutes(dateAllFormat: Date | string | number = getDateAsInt(
232
236
  */
233
237
  export function addHours(dateAllFormat?: Date | string | number, numberOfHours?: number, outputFormat?: 'dateInt8' | 'dateInt12' | 'humanReadableTimestamp'): string
234
238
  export function addHours(dateAllFormat?: Date | string | number, numberOfHours?: number, outputFormat?: 'date'): Date
235
- export function addHours(dateAllFormat: Date | string | number = getDateAsInt(), numberOfHours = 1, outputFormat: DateAllFormat = 'date'): any {
239
+ export function addHours(dateAllFormat: DateAllFormat = getDateAsInt(), numberOfHours = 1, outputFormat: DateAllFormatString = 'date'): any {
236
240
  const date = getDateAsObject(dateAllFormat)
237
241
  date.setTime(date.getTime() + 1 * numberOfHours * 60 * 60 * 1000)
238
242
  return getDateAs(date, outputFormat as any)
@@ -242,7 +246,7 @@ export function addHours(dateAllFormat: Date | string | number = getDateAsInt(),
242
246
  */
243
247
  export function addMonths(dateAllFormat?: Date | string | number, numberOfMonths?: number, outputFormat?: 'dateInt8' | 'dateInt12' | 'humanReadableTimestamp'): string
244
248
  export function addMonths(dateAllFormat?: Date | string | number, numberOfMonths?: number, outputFormat?: 'date'): Date
245
- export function addMonths(dateAllFormat: Date | string | number = getDateAsInt(), numberOfMonths = 1, outputFormat: DateAllFormat = 'date'): any {
249
+ export function addMonths(dateAllFormat: DateAllFormat = getDateAsInt(), numberOfMonths = 1, outputFormat: DateAllFormatString = 'date'): any {
246
250
  const date = getDateAsObject(dateAllFormat)
247
251
  date.setUTCMonth(date.getUTCMonth() + numberOfMonths)
248
252
  return getDateAs(date, outputFormat as any)
@@ -250,32 +254,32 @@ export function addMonths(dateAllFormat: Date | string | number = getDateAsInt()
250
254
  /**
251
255
  * @param {String} outputFormat dateInt, dateInt8, dateInt12, date, humanReadableTimestamp, int (dateInt8)
252
256
  */
253
- export function addYears(dateAllFormat: Date | string | number = getDateAsInt(), numberOfYears = 1, outputFormat: DateAllFormat = 'date') {
257
+ export function addYears(dateAllFormat: DateAllFormat = getDateAsInt(), numberOfYears = 1, outputFormat: DateAllFormatString = 'date') {
254
258
  const date = getDateAsObject(dateAllFormat)
255
259
  date.setUTCFullYear(date.getUTCFullYear() + numberOfYears)
256
260
  return getDateAs(date, outputFormat as any)
257
261
  }
258
262
 
259
- export function getDayOfMonth(dateAllFormat: Date | string | number = getDateAsInt()) {
263
+ export function getDayOfMonth(dateAllFormat: DateAllFormat = getDateAsInt()) {
260
264
  const dateAsInt = getDateAsInt(dateAllFormat)
261
265
  const [, , d] = dateStringToArray(dateAsInt)
262
266
  return d
263
267
  }
264
268
 
265
- export function getYear(dateAllFormat: Date | string | number = getDateAsInt()) {
269
+ export function getYear(dateAllFormat: DateAllFormat = getDateAsInt()) {
266
270
  const dateAsInt = getDateAsInt(dateAllFormat)
267
271
  const [y] = dateStringToArray(dateAsInt)
268
272
  return y
269
273
  }
270
274
 
271
275
 
272
- export function getHours(dateAllFormat: Date | string | number = getDateAsInt()) {
276
+ export function getHours(dateAllFormat: DateAllFormat = getDateAsInt()) {
273
277
  const dateAsInt = getDateAsInt(dateAllFormat)
274
278
  const [, , , h] = dateStringToArray(dateAsInt)
275
279
  return h
276
280
  }
277
281
 
278
- export function getMinutes(dateAllFormat: Date | string | number = getDateAsInt()) {
282
+ export function getMinutes(dateAllFormat: DateAllFormat = getDateAsInt()) {
279
283
  const dateAsInt = getDateAsInt(dateAllFormat)
280
284
  const [, , , , m] = dateStringToArray(dateAsInt)
281
285
  return m
@@ -284,7 +288,7 @@ export function getMinutes(dateAllFormat: Date | string | number = getDateAsInt(
284
288
  /**
285
289
  * @param {String} outputFormat dateInt, dateInt8, dateInt12, date, humanReadableTimestamp, int (dateInt8)
286
290
  */
287
- export function lastDayOfMonth(dateAllFormat: Date | string | number = getDateAsInt(), outputFormat: DateAllFormat = 'date') {
291
+ export function lastDayOfMonth(dateAllFormat: DateAllFormat = getDateAsInt(), outputFormat: DateAllFormatString = 'date') {
288
292
  const date = getDateAsObject(dateAllFormat)
289
293
  const lastDay = new Date(date.getUTCFullYear(), date.getUTCMonth() + 1, 0)
290
294
  lastDay.setUTCHours(date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds(), date.getUTCMilliseconds())
@@ -294,36 +298,36 @@ export function lastDayOfMonth(dateAllFormat: Date | string | number = getDateAs
294
298
  /**
295
299
  * @param {String} outputFormat dateInt, dateInt8, dateInt12, date, humanReadableTimestamp, int (dateInt8)
296
300
  */
297
- export function firstDayOfMonth(dateAllFormat: Date | string | number = getDateAsInt(), outputFormat: DateAllFormat = 'date') {
301
+ export function firstDayOfMonth(dateAllFormat: DateAllFormat = getDateAsInt(), outputFormat: DateAllFormatString = 'date') {
298
302
  const date = getDateAsObject(dateAllFormat)
299
303
  const firstDay = new Date(date.getUTCFullYear(), date.getUTCMonth(), 1)
300
304
  firstDay.setUTCHours(date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds(), date.getUTCMilliseconds())
301
305
  return getDateAs(firstDay, outputFormat as any)
302
306
  }
303
307
 
304
- export function differenceInMilliseconds(startDateAllFormat, endDateAllFormat) {
308
+ export function differenceInMilliseconds(startDateAllFormat: any, endDateAllFormat: any) {
305
309
  const startDate = getDateAsObject(startDateAllFormat)
306
310
  const endDate = getDateAsObject(endDateAllFormat)
307
311
  return endDate.getTime() - startDate.getTime()
308
312
  }
309
313
 
310
- export function differenceInSeconds(startDateAllFormat, endDateAllFormat) {
314
+ export function differenceInSeconds(startDateAllFormat: any, endDateAllFormat: any) {
311
315
  return differenceInMilliseconds(startDateAllFormat, endDateAllFormat) / 1000
312
316
  }
313
317
 
314
- export function differenceInMinutes(startDateAllFormat, endDateAllFormat) {
318
+ export function differenceInMinutes(startDateAllFormat: any, endDateAllFormat: any) {
315
319
  return differenceInSeconds(startDateAllFormat, endDateAllFormat) / 60
316
320
  }
317
321
 
318
- export function differenceInHours(startDateAllFormat, endDateAllFormat) {
322
+ export function differenceInHours(startDateAllFormat: any, endDateAllFormat: any) {
319
323
  return differenceInMinutes(startDateAllFormat, endDateAllFormat) / 60
320
324
  }
321
325
 
322
- export function differenceInDays(startDateAllFormat, endDateAllFormat) {
326
+ export function differenceInDays(startDateAllFormat: any, endDateAllFormat: any) {
323
327
  return differenceInHours(startDateAllFormat, endDateAllFormat) / 24
324
328
  }
325
329
 
326
- export function differenceInWeeks(startDateAllFormat, endDateAllFormat) {
330
+ export function differenceInWeeks(startDateAllFormat: any, endDateAllFormat: any) {
327
331
  return differenceInDays(startDateAllFormat, endDateAllFormat) / 7
328
332
  }
329
333
 
@@ -332,7 +336,7 @@ export function differenceInWeeks(startDateAllFormat, endDateAllFormat) {
332
336
  */
333
337
  export function getDateAs(dateAllFormat?: Date | string | number, outputFormat?: 'dateInt8' | 'dateInt12' | 'humanReadableTimestamp'): string
334
338
  export function getDateAs(dateAllFormat?: Date | string | number, outputFormat?: 'date'): Date
335
- export function getDateAs(dateAllFormat: Date | string | number = new Date(), outputDateFormat: DateAllFormat = 'date') {
339
+ export function getDateAs(dateAllFormat: DateAllFormat = new Date(), outputDateFormat: DateAllFormatString = 'date') {
336
340
  switch (outputDateFormat) {
337
341
  case 'dateInt8':
338
342
  return getDateAsInt(dateAllFormat)
@@ -347,7 +351,7 @@ export function getDateAs(dateAllFormat: Date | string | number = new Date(), ou
347
351
  }
348
352
 
349
353
 
350
- export function isDateIntOrStringValid(dateStringOrInt, outputAnError = false, length?): boolean {
354
+ export function isDateIntOrStringValid(dateStringOrInt: DateAllFormat, outputAnError = false, length?: number): boolean {
351
355
  if (!isset(dateStringOrInt)) return false
352
356
  const dateStr = dateStringOrInt.toString()
353
357
 
@@ -355,7 +359,7 @@ export function isDateIntOrStringValid(dateStringOrInt, outputAnError = false, l
355
359
 
356
360
  if ((typeof dateStringOrInt === 'object' && isNaN(int(dateStr))) || ![4, 6, 8, 10, 12, 17].includes(dateStr.length)) return false
357
361
 
358
- const dateArr = dateStringToArray(dateStringOrInt)
362
+ const dateArr = dateStringToArray(dateStringOrInt as string)
359
363
  const [y, M, d, h, m] = dateArr
360
364
 
361
365
  const test1 = dateArr.length >= 3 && int(y) >= 1000 // Y
@@ -368,7 +372,7 @@ export function isDateIntOrStringValid(dateStringOrInt, outputAnError = false, l
368
372
  return true
369
373
  }
370
374
 
371
- export function isDateIsoOrObjectValid(dateIsoOrObj, outputAnError = false) {
375
+ export function isDateIsoOrObjectValid(dateIsoOrObj: any, outputAnError = false) {
372
376
  let dateObj: Date | number | string = dateIsoOrObj
373
377
  if (typeof dateIsoOrObj === 'string') dateObj = new Date(dateIsoOrObj)
374
378
  const valid = dateObj instanceof Date
package/src/env-utils.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  //----------------------------------------
4
4
 
5
5
  /** Parse one dimention object undefined, true, false, null represented as string will be converted to primitives */
6
- export function parseEnv(env) {
6
+ export function parseEnv(env: Record<string, any>) {
7
7
  const newEnv = {} as Record<string, undefined | null | number | boolean | string>
8
8
  for (const k in env) {
9
9
  const val = env[k]
@@ -12,15 +12,15 @@ import { removeCircularJSONstringify } from './remove-circular-json-stringify'
12
12
  import { generateToken } from './string-utils'
13
13
  import { isObject } from './is-object'
14
14
 
15
- export function errIfNotSet(objOfVarNamesWithValues) { return errXXXIfNotSet(422, false, objOfVarNamesWithValues) }
15
+ export function errIfNotSet(objOfVarNamesWithValues: Record<string, any>) { return errXXXIfNotSet(422, false, objOfVarNamesWithValues) }
16
16
 
17
- export function err500IfNotSet(objOfVarNamesWithValues) { return errXXXIfNotSet(500, false, objOfVarNamesWithValues) }
17
+ export function err500IfNotSet(objOfVarNamesWithValues: Record<string, any>) { return errXXXIfNotSet(500, false, objOfVarNamesWithValues) }
18
18
 
19
- export function errIfEmptyOrNotSet(objOfVarNamesWithValues) { return errXXXIfNotSet(422, true, objOfVarNamesWithValues) }
19
+ export function errIfEmptyOrNotSet(objOfVarNamesWithValues: Record<string, any>) { return errXXXIfNotSet(422, true, objOfVarNamesWithValues) }
20
20
 
21
- export function err500IfEmptyOrNotSet(objOfVarNamesWithValues) { return errXXXIfNotSet(500, true, objOfVarNamesWithValues) }
21
+ export function err500IfEmptyOrNotSet(objOfVarNamesWithValues: Record<string, any>) { return errXXXIfNotSet(500, true, objOfVarNamesWithValues) }
22
22
 
23
- export function errXXXIfNotSet(errCode, checkEmpty, objOfVarNamesWithValues) {
23
+ export function errXXXIfNotSet(errCode: number, checkEmpty: boolean, objOfVarNamesWithValues: Record<string, any>) {
24
24
  const missingVars: string[] = []
25
25
  for (const prop in objOfVarNamesWithValues) {
26
26
  if (!isset(objOfVarNamesWithValues[prop]) || (checkEmpty && isEmpty(objOfVarNamesWithValues[prop]))) missingVars.push(prop)
@@ -29,7 +29,7 @@ export function errXXXIfNotSet(errCode, checkEmpty, objOfVarNamesWithValues) {
29
29
  }
30
30
 
31
31
 
32
- export function err422IfNotSet(o) {
32
+ export function err422IfNotSet(o: Record<string, any>) {
33
33
  const m: any[] = []
34
34
  for (const p in o) if (!isset(o[p])) m.push(p)
35
35
  if (m.length) throw new DescriptiveError(`requiredVariableEmptyOrNotSet`, { code: 422, origin: 'Validator', varNames: m.join(', ') })
@@ -48,7 +48,7 @@ export function tryCatch<T>(callback: () => T, onErr: Function = () => { /** */
48
48
 
49
49
  export const failSafe = tryCatch // ALIAS
50
50
 
51
- function extraInfosRendererDefault(extraInfos) {
51
+ function extraInfosRendererDefault(extraInfos: Record<string, any>) {
52
52
  return [
53
53
  '== EXTRA INFOS ==',
54
54
  removeCircularJSONstringify({ ...extraInfos, message: undefined, stack: undefined, originalError: undefined, hasBeenLogged: undefined, logs: undefined }, 2)
@@ -224,6 +224,6 @@ export class DescriptiveError<ExpectedOriginalError = any> extends Error {
224
224
  }
225
225
  }
226
226
 
227
- function computeErrorMessage(err) {
227
+ function computeErrorMessage(err: any) {
228
228
  return (err.code ? err.code + ' ' : '') + (err.msg || err.message)
229
229
  }
package/src/isset.ts CHANGED
@@ -1,3 +1,3 @@
1
- export function isset(...elms) {
1
+ export function isset(...elms: any[]) {
2
2
  return elms.every(elm => typeof elm !== 'undefined' && elm !== null)
3
3
  }
@@ -27,9 +27,9 @@ export const logger = {
27
27
  /**
28
28
  * @param {String[]|String} inputLogs
29
29
  */
30
- toHtml(inputLogs = [...logger.raw]) {
30
+ toHtml(inputLogs = [...logger.raw] as string[]) {
31
31
  if (!Array.isArray(inputLogs)) inputLogs = [inputLogs]
32
- const code2css = {
32
+ const code2css: Record<string, any> = {
33
33
  2: `opacity:.5`, // dim
34
34
  32: `color:#679933`, // green
35
35
  31: `color:#A8383B`, // red
@@ -54,12 +54,18 @@ export const logger = {
54
54
  })
55
55
  return `<div style='color:#ccc'>${htmlLogs}<br></div>`
56
56
  },
57
- toText(inputLogs = [...logger.raw]) {
57
+ toText(inputLogs = [...logger.raw] as string[]) {
58
58
  const str = Array.isArray(inputLogs) ? inputLogs.join('\n') : inputLogs
59
59
  return str.replace(/\x1b\[.*?m/g, '')
60
60
  },
61
61
  raw: [] as string[],
62
62
  json: [] as string[],
63
+ } as {
64
+ log(str: string, level?: LogLevels): void
65
+ toHtml(inputLogs?: string[]): string
66
+ toText(inputLogs?: string[]): string
67
+ raw: string[]
68
+ json: string[]
63
69
  }
64
70
 
65
71
  /**
@@ -70,23 +76,23 @@ export const logger = {
70
76
  // * or C.gradientize(myLongString)
71
77
  */
72
78
  export const C = {
73
- dim: str => C.output(2, str), // opacity 0.5
74
- green: str => C.output(32, str),
75
- red: str => C.output(31, str),
76
- yellow: str => C.output(33, str),
77
- grey: str => C.output(2, str),
78
- magenta: str => C.output(35, str),
79
- cyan: str => C.output(36, str),
80
- blue: str => C.output(34, str),
81
- primary: str => {
79
+ dim: (str: string) => C.output(2, str), // opacity 0.5
80
+ green: (str: string) => C.output(32, str),
81
+ red: (str: string) => C.output(31, str),
82
+ yellow: (str: string) => C.output(33, str),
83
+ grey: (str: string) => C.output(2, str),
84
+ magenta: (str: string) => C.output(35, str),
85
+ cyan: (str: string) => C.output(36, str),
86
+ blue: (str: string) => C.output(34, str),
87
+ primary: (str: string) => {
82
88
  const primary: Color = configFn()?.terminal?.theme?.primary
83
89
  return C.rgb(...primary) + str + C.reset
84
90
  },
85
91
  reset: '\x1b[0m',
86
- output: (code, str = '') => configFn()?.terminal?.noColor ? str : `\x1b[${code}m${str}\x1b[0m`,
92
+ output: (code: number, str = '') => configFn()?.terminal?.noColor ? str : `\x1b[${code}m${str}\x1b[0m`,
87
93
  // true RGB colors B-*
88
- rgb: (r, g = 0, b = 0) => configFn()?.terminal?.noColor || !isset(r, g, b) ? '' : `\x1b[38;2;${r};${g};${b}m`,
89
- bg: (r?, g?, b?) => configFn()?.terminal?.noColor || !isset(r, g, b) ? '' : `${'\x1b['}48;2;${r};${g};${b}m`,
94
+ rgb: (r: number, g = 0, b = 0) => configFn()?.terminal?.noColor || !isset(r, g, b) ? '' : `\x1b[38;2;${r};${g};${b}m`,
95
+ bg: (r?: number, g?: number, b?: number) => configFn()?.terminal?.noColor || !isset(r, g, b) ? '' : `${'\x1b['}48;2;${r};${g};${b}m`,
90
96
  /** Output a line of title */
91
97
  line(title = '', length = configFn()?.terminal?.theme?.pageWidth, clr = configFn()?.terminal?.theme?.primary, char = '=') {
92
98
  this.log('\u00A0\n' + this.rgb(...clr) + (title + ' ').padEnd(length || 0, char) + this.reset + '\u00A0\n')
@@ -94,7 +100,7 @@ export const C = {
94
100
  /** Eg: ['cell1', 'cell2', 'cell3'], [25, 15] will start cell2 at 25 and cell 3 at 25 + 15
95
101
  * @param {Array} limits default divide the viewport
96
102
  */
97
- cols(strings, limits: number[] = [], clr = configFn()?.terminal?.theme?.fontColor) {
103
+ cols(strings: string[], limits: number[] = [], clr = configFn()?.terminal?.theme?.fontColor) {
98
104
 
99
105
  if (!limits.length) {
100
106
  const colWidth = Math.round(configFn()?.terminal?.theme.pageWidth / strings.length)
@@ -109,58 +115,40 @@ export const C = {
109
115
  this.logClr(str, clr)
110
116
  },
111
117
  /** Console log alias */
112
- log(...stringsCtxMayBeFirstParam) {
113
- stringsCtxMayBeFirstParam.forEach(str => this.logClr(str))
118
+ log(...stringsCtxMayBeFirstParam: any[]) {
119
+ stringsCtxMayBeFirstParam.forEach((str: string) => this.logClr(str))
114
120
  },
115
- logClr(str, clr = configFn()?.terminal?.theme?.fontColor) {
121
+ logClr(str: string, clr = configFn()?.terminal?.theme?.fontColor) {
116
122
  if (!isset(str)) return
117
123
  str = (typeof clr !== 'undefined' ? this.rgb(...clr) : '') + str.toString().replace(/\n/g, '\n' + (typeof clr !== 'undefined' ? this.rgb(...clr) : ''))
118
124
  logger.log(str + this.reset, 'info')
119
125
  },
120
- info(...str) {
126
+ info(...str: string[]) {
121
127
  str.forEach((s, i) => {
122
128
  if (i === 0) this.logClr('ⓘ ' + s, configFn()?.terminal?.theme?.primary)
123
129
  else this.log(this.dimStrSplit(s))
124
130
  })
125
131
  this.log(' ')
126
132
  },
127
- success(...str) {
133
+ success(...str: string[]) {
128
134
  str.forEach((s, i) => {
129
135
  if (i === 0) this.log(this.green('✓ ' + s))
130
136
  else this.log(this.dimStrSplit(s))
131
137
  })
132
138
  },
133
139
  /** First param **false** to avoid logging stack trace */
134
- error: (...errors) => logErrPrivate('error', [255, 0, 0], ...errors),
140
+ error: (...errors: any[]) => logErrPrivate('error', [255, 0, 0], ...errors),
135
141
  /** First param **false** to avoid logging stack trace */
136
- warning: (...str) => logErrPrivate('warn', [255, 122, 0], ...str),
137
- customError: (color, ...str) => logErrPrivate('error', color, ...str),
138
- customWarning: (color, ...str) => logErrPrivate('warn', color, ...str),
139
- applicationError: (color, ...str) => logErrPrivate('warn', color, ...str),
140
- warningLight: (_, ...str) => logErrPrivate('warn', [196, 120, 52], ...str),
141
- dimStrSplit(...logs) {
142
+ warning: (...str: string[]) => logErrPrivate('warn', [255, 122, 0], ...str),
143
+ customError: (color: Color, ...str: string[]) => logErrPrivate('error', color, ...str),
144
+ customWarning: (color: Color, ...str: string[]) => logErrPrivate('warn', color, ...str),
145
+ applicationError: (color: Color, ...str: string[]) => logErrPrivate('warn', color, ...str),
146
+ warningLight: (_: any, ...str: string[]) => logErrPrivate('warn', [196, 120, 52], ...str),
147
+ dimStrSplit(...logs: string[]) {
142
148
  const logsStr: string[] = []
143
149
  logs.filter(isset).forEach(log => log.toString().split('\n').forEach(line => line && logsStr.push(this.dim(` ${line}`))))
144
150
  return logsStr.join('\n')
145
151
  },
146
- notifShow() {
147
- console.log('\n\u00A0')
148
- this.notifications.forEach(fn => fn())
149
- this.notifications = []
150
- console.log('\n\u00A0')
151
- },
152
- /** Keep in memory the logs to show when needed with C.notifShow()
153
- * Ex: C.notification('info', str); */
154
- notification(type, ...messages) {
155
- this.notifications.push(() => {
156
- if (isset(this[type])) {
157
- this[type](...messages)
158
- } else {
159
- this.warning('Wrong param for C.notification')
160
- }
161
- })
162
- },
163
- notifications: [] as any[], // fn array
164
152
  /** Gratientize lines of text (separated by \n) */
165
153
  gradientize(str = '', rgb1 = configFn()?.terminal?.theme?.shade1, rgb2 = configFn()?.terminal?.theme?.shade2, bgRgb = configFn()?.terminal?.theme?.bgColor, paddingY = 2) {
166
154
 
@@ -177,7 +165,7 @@ export const C = {
177
165
  }, '') +
178
166
  padLine.repeat(paddingY))
179
167
  },
180
- debugModeLog(title, ...string) {
168
+ debugModeLog(title: string, ...string: string[]) {
181
169
  this.logClr('🐞 ' + title, configFn()?.terminal?.theme?.debugModeColor)
182
170
  this.log(this.dimStrSplit(...string))
183
171
  },
@@ -191,7 +179,7 @@ export const C = {
191
179
  }
192
180
  }
193
181
 
194
- function logErrPrivate(level: NotInfoLogLevel, color: Color, ...errors) {
182
+ function logErrPrivate(level: NotInfoLogLevel, color: Color, ...errors: any[]) {
195
183
  const { isProd } = configFn()
196
184
 
197
185
  if (errors.length === 1 && typeof errors[0]?.log === 'function') return errors[0].log()
@@ -201,7 +189,7 @@ function logErrPrivate(level: NotInfoLogLevel, color: Color, ...errors) {
201
189
  const symbol = level === 'error' ? '✘ ' : '⚠ '
202
190
  if (errors.length > 1 && !isset(errors[0])) errors.shift() // remove first empty object
203
191
 
204
- const getStringFromErr = (err, i) => {
192
+ const getStringFromErr = (err: any, i: number) => {
205
193
  if (!isset(err)) return ''
206
194
  else if (typeof err === 'string') {
207
195
  if (i === 0) return C.rgb(...color) + symbol + err + C.reset
@@ -243,7 +231,7 @@ function logErrPrivate(level: NotInfoLogLevel, color: Color, ...errors) {
243
231
  }
244
232
  }
245
233
 
246
- function stringifyInstanceOfError(err, type = 'error', color: Color = [255, 0, 0], level = 0) { // level = keep track of recursions
234
+ function stringifyInstanceOfError(err: any, type: NotInfoLogLevel = 'error', color: Color = [255, 0, 0], level = 0): { str: string, stackTrace?: string } { // level = keep track of recursions
247
235
  if (level > 5) return { str: '' }
248
236
  let str = ''
249
237
  let stackTrace
@@ -261,7 +249,7 @@ function stringifyInstanceOfError(err, type = 'error', color: Color = [255, 0, 0
261
249
  return { str, stackTrace }
262
250
  }
263
251
 
264
- function stringifyExtraInfos(extraInfoOriginal, type, color, level = 0) {
252
+ function stringifyExtraInfos(extraInfoOriginal: Record<string, any>, type: NotInfoLogLevel, color: Color, level = 0) {
265
253
  let stackTrace
266
254
  const originalError = [C.dim(`ORIGINAL ERROR ${'-'.repeat(39)}\n`)]
267
255
  if (extraInfoOriginal instanceof Error) { // case where error is passed directly to extraInfos
@@ -336,7 +324,7 @@ export class cliLoadingSpinner {
336
324
  this.animFrames = anims[type].frames
337
325
  this.activeProcess = activeProcess
338
326
  }
339
- start(msg) {
327
+ start(msg: string) {
340
328
  this.frameNb = 0
341
329
  this.progressMessage = msg
342
330
  this.interval = setInterval(() => {