@villedemontreal/general-utils 5.17.6 → 5.18.0

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 (85) hide show
  1. package/dist/config/configs.d.ts +1 -0
  2. package/dist/config/configs.d.ts.map +1 -0
  3. package/dist/config/configs.js +1 -24
  4. package/dist/config/configs.js.map +1 -1
  5. package/dist/src/apiError.d.ts +1 -0
  6. package/dist/src/apiError.d.ts.map +1 -0
  7. package/dist/src/apiError.js +1 -24
  8. package/dist/src/apiError.js.map +1 -1
  9. package/dist/src/apiError.test.d.ts +1 -0
  10. package/dist/src/apiError.test.d.ts.map +1 -0
  11. package/dist/src/apiErrorBuilder.d.ts +1 -0
  12. package/dist/src/apiErrorBuilder.d.ts.map +1 -0
  13. package/dist/src/apiErrorBuilder.js +1 -24
  14. package/dist/src/apiErrorBuilder.js.map +1 -1
  15. package/dist/src/collectionUtils.d.ts +1 -0
  16. package/dist/src/collectionUtils.d.ts.map +1 -0
  17. package/dist/src/collectionUtils.js +1 -24
  18. package/dist/src/collectionUtils.js.map +1 -1
  19. package/dist/src/collectionUtils.test.d.ts +1 -0
  20. package/dist/src/collectionUtils.test.d.ts.map +1 -0
  21. package/dist/src/collectionUtils.test.js +1 -24
  22. package/dist/src/collectionUtils.test.js.map +1 -1
  23. package/dist/src/config/constants.d.ts +2 -0
  24. package/dist/src/config/constants.d.ts.map +1 -0
  25. package/dist/src/config/constants.js +15 -24
  26. package/dist/src/config/constants.js.map +1 -1
  27. package/dist/src/config/globalConstants.d.ts +1 -0
  28. package/dist/src/config/globalConstants.d.ts.map +1 -0
  29. package/dist/src/dateUtils.d.ts +1 -0
  30. package/dist/src/dateUtils.d.ts.map +1 -0
  31. package/dist/src/dateUtils.js +14 -17
  32. package/dist/src/dateUtils.js.map +1 -1
  33. package/dist/src/dateUtils.test.d.ts +1 -0
  34. package/dist/src/dateUtils.test.d.ts.map +1 -0
  35. package/dist/src/dateUtils.test.js +8 -11
  36. package/dist/src/dateUtils.test.js.map +1 -1
  37. package/dist/src/index.d.ts +1 -0
  38. package/dist/src/index.d.ts.map +1 -0
  39. package/dist/src/logLevel.d.ts +1 -0
  40. package/dist/src/logLevel.d.ts.map +1 -0
  41. package/dist/src/logLevel.js +13 -3
  42. package/dist/src/logLevel.js.map +1 -1
  43. package/dist/src/orderBy.d.ts +1 -0
  44. package/dist/src/orderBy.d.ts.map +1 -0
  45. package/dist/src/orderBy.js +1 -24
  46. package/dist/src/orderBy.js.map +1 -1
  47. package/dist/src/pagination.d.ts +1 -0
  48. package/dist/src/pagination.d.ts.map +1 -0
  49. package/dist/src/pagination.test.d.ts +1 -0
  50. package/dist/src/pagination.test.d.ts.map +1 -0
  51. package/dist/src/stringUtils.d.ts +1 -0
  52. package/dist/src/stringUtils.d.ts.map +1 -0
  53. package/dist/src/stringUtils.js +1 -24
  54. package/dist/src/stringUtils.js.map +1 -1
  55. package/dist/src/stringUtils.test.d.ts +1 -0
  56. package/dist/src/stringUtils.test.d.ts.map +1 -0
  57. package/dist/src/timer.d.ts +1 -0
  58. package/dist/src/timer.d.ts.map +1 -0
  59. package/dist/src/timer.js +1 -24
  60. package/dist/src/timer.js.map +1 -1
  61. package/dist/src/timer.test.d.ts +1 -0
  62. package/dist/src/timer.test.d.ts.map +1 -0
  63. package/dist/src/utils.d.ts +1 -0
  64. package/dist/src/utils.d.ts.map +1 -0
  65. package/dist/src/utils.js +19 -46
  66. package/dist/src/utils.js.map +1 -1
  67. package/dist/src/utils.test.d.ts +1 -0
  68. package/dist/src/utils.test.d.ts.map +1 -0
  69. package/dist/src/utils.test.js +1 -24
  70. package/dist/src/utils.test.js.map +1 -1
  71. package/dist/test-data/test_throwNotManaged/962a8539-5522-4e44-aa9c-32475e5e537e.d.ts +2 -0
  72. package/dist/test-data/test_throwNotManaged/962a8539-5522-4e44-aa9c-32475e5e537e.d.ts.map +1 -0
  73. package/dist/test-data/test_throwNotManaged/{99039260-e610-4019-91c3-9ef4255a214b.js → 962a8539-5522-4e44-aa9c-32475e5e537e.js} +1 -1
  74. package/dist/test-data/test_throwNotManaged/{99039260-e610-4019-91c3-9ef4255a214b.js.map → 962a8539-5522-4e44-aa9c-32475e5e537e.js.map} +1 -1
  75. package/dist/tests-resources/exec/execTest.d.ts +1 -0
  76. package/dist/tests-resources/exec/execTest.d.ts.map +1 -0
  77. package/dist/tsconfig.tsbuildinfo +1 -1
  78. package/package.json +15 -14
  79. package/src/collectionUtils.ts +1 -1
  80. package/src/config/constants.ts +16 -1
  81. package/src/dateUtils.test.ts +2 -2
  82. package/src/dateUtils.ts +6 -6
  83. package/src/logLevel.ts +13 -3
  84. package/src/utils.ts +16 -16
  85. package/dist/test-data/test_throwNotManaged/99039260-e610-4019-91c3-9ef4255a214b.d.ts +0 -1
package/src/dateUtils.ts CHANGED
@@ -1,8 +1,8 @@
1
- import _ from 'lodash';
2
1
  import { DateTime, Zone } from 'luxon';
3
- import moment from 'moment';
2
+ import * as moment from 'moment';
4
3
  import { Moment } from 'moment';
5
4
  import { getValueDescription, utils } from '.';
5
+ import { isDate, isNil } from 'lodash';
6
6
 
7
7
  export function isDateEqual(value: DateDefinition, expectedDate: DateDefinition) {
8
8
  const _moment: Moment = moment(value);
@@ -230,11 +230,11 @@ export function startOfDay(
230
230
  isoDate: Date | string,
231
231
  timezone: string | Zone = 'America/Montreal',
232
232
  ): Date {
233
- if (_.isNil(isoDate)) {
233
+ if (isNil(isoDate)) {
234
234
  return isoDate;
235
235
  }
236
236
 
237
- let luxonDate = DateTime.fromISO(_.isDate(isoDate) ? isoDate.toISOString() : isoDate);
237
+ let luxonDate = DateTime.fromISO(isDate(isoDate) ? isoDate.toISOString() : isoDate);
238
238
  if (!luxonDate.isValid) {
239
239
  throw new Error(`Invalid ISO date ${JSON.stringify(isoDate)} : ${luxonDate.invalidReason}`);
240
240
  }
@@ -261,11 +261,11 @@ export function endOfDay(
261
261
  isoDate: Date | string,
262
262
  timezone: string | Zone = 'America/Montreal',
263
263
  ): Date {
264
- if (_.isNil(isoDate)) {
264
+ if (isNil(isoDate)) {
265
265
  return isoDate;
266
266
  }
267
267
 
268
- let luxonDate = DateTime.fromISO(_.isDate(isoDate) ? isoDate.toISOString() : isoDate);
268
+ let luxonDate = DateTime.fromISO(isDate(isoDate) ? isoDate.toISOString() : isoDate);
269
269
  if (!luxonDate.isValid) {
270
270
  throw new Error(`Invalid ISO date ${JSON.stringify(isoDate)} : ${luxonDate.invalidReason}`);
271
271
  }
package/src/logLevel.ts CHANGED
@@ -24,10 +24,20 @@ export enum LogLevel {
24
24
  * LogLevel enum value.
25
25
  */
26
26
  export const logLevelFromString = (levelStr: string): LogLevel => {
27
- if (levelStr) {
28
- return LogLevel[levelStr.toUpperCase()];
27
+ switch ((levelStr || '').toUpperCase()) {
28
+ case 'DEBUG':
29
+ return LogLevel.DEBUG;
30
+ case 'TRACE':
31
+ return LogLevel.TRACE;
32
+ case 'ERROR':
33
+ return LogLevel.ERROR;
34
+ case 'INFO':
35
+ return LogLevel.INFO;
36
+ case 'WARNING':
37
+ return LogLevel.WARNING;
38
+ default:
39
+ return LogLevel.DEBUG;
29
40
  }
30
- return undefined;
31
41
  };
32
42
 
33
43
  /**
package/src/utils.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import { spawn, StdioOptions } from 'child_process';
2
2
  import * as fs from 'fs';
3
- import getPort from 'get-port';
4
- import _ from 'lodash';
3
+ import * as getPort from 'get-port';
5
4
  import * as pathUtils from 'path';
6
5
  import { rimraf } from 'rimraf';
7
6
  import * as tsconfig from 'tsconfig-extends';
8
7
  import { constants } from './config/constants';
8
+ import { isArray, isDate, isEqual, isFunction, isNil, isObject, isString, trimEnd } from 'lodash';
9
9
 
10
10
  /**
11
11
  * General utilities
@@ -158,7 +158,7 @@ export class Utils {
158
158
  pathClean = pathUtils.normalize(pathClean);
159
159
 
160
160
  pathClean = pathClean.replace(/\\/g, '/');
161
- pathClean = _.trimEnd(pathClean, '/ ');
161
+ pathClean = trimEnd(pathClean, '/ ');
162
162
 
163
163
  return (pathClean.match(/\//g) || []).length > 1;
164
164
  }
@@ -268,11 +268,12 @@ export class Utils {
268
268
  if (!this.tscCompilerOptionsParams) {
269
269
  this.tscCompilerOptionsParams = [];
270
270
  const compilerOptions = tsconfig.load_file_sync(constants.appRoot + '/tsconfig.json');
271
+
271
272
  for (const key of Object.keys(compilerOptions)) {
272
273
  // ==========================================
273
- // TS6064: Option 'plugins' can only be specified in 'tsconfig.json' file.
274
+ // TS6064: Options 'plugins', 'composite' can only be specified in 'tsconfig.json' file.
274
275
  // ==========================================
275
- if (key === 'plugins') {
276
+ if (['plugins', 'composite'].includes(key)) {
276
277
  continue;
277
278
  }
278
279
 
@@ -306,9 +307,8 @@ export class Utils {
306
307
  }
307
308
 
308
309
  const cmd = 'node';
309
- const args = [constants.libRoot + '/node_modules/typescript/lib/tsc.js']
310
- .concat(this.tscCompilerOptions)
311
- .concat(files);
310
+ const tscCmd = constants.findModulePath('node_modules/typescript/lib/tsc.js');
311
+ const args = [tscCmd].concat(this.tscCompilerOptions).concat(files);
312
312
 
313
313
  await this.execPromisified(cmd, args);
314
314
  }
@@ -362,13 +362,13 @@ export class Utils {
362
362
  public dateTransformer = (value: any): Date => {
363
363
  let date: Date;
364
364
 
365
- if (_.isNil(value)) {
365
+ if (isNil(value)) {
366
366
  return null;
367
367
  }
368
368
 
369
- if (_.isDate(value)) {
369
+ if (isDate(value)) {
370
370
  date = value;
371
- } else if (!_.isString(value) || utils.isBlank(value)) {
371
+ } else if (!isString(value) || utils.isBlank(value)) {
372
372
  // ==========================================
373
373
  // Makes sure it's an invalid date!
374
374
  // Because by default, true and 123 are accepted,
@@ -406,7 +406,7 @@ export class Utils {
406
406
  if (!val) {
407
407
  return false;
408
408
  }
409
- return _.isObject(val) && !_.isArray(val) && !_.isDate(val) && !_.isFunction(val);
409
+ return isObject(val) && !isArray(val) && !isDate(val) && !isFunction(val);
410
410
  };
411
411
 
412
412
  /**
@@ -415,12 +415,12 @@ export class Utils {
415
415
  * strictly equals to the specified "value".
416
416
  */
417
417
  public arrayContainsObjectWithKeyEqualsTo = (array: any[], key: string, value: any): boolean => {
418
- if (!array || !_.isArray(array) || array.length < 1) {
418
+ if (!array || !isArray(array) || array.length < 1) {
419
419
  return false;
420
420
  }
421
421
 
422
422
  for (const obj of array) {
423
- if (this.isObjectStrict(obj) && _.isEqual(obj[key], value)) {
423
+ if (this.isObjectStrict(obj) && isEqual(obj[key], value)) {
424
424
  return true;
425
425
  }
426
426
  }
@@ -499,7 +499,7 @@ export class Utils {
499
499
  const optionsClean = options ?? {};
500
500
  optionsClean.useShellOption = optionsClean.useShellOption ?? true;
501
501
  optionsClean.successExitCodes = optionsClean.successExitCodes
502
- ? _.isArray(optionsClean.successExitCodes)
502
+ ? isArray(optionsClean.successExitCodes)
503
503
  ? optionsClean.successExitCodes
504
504
  : [optionsClean.successExitCodes]
505
505
  : [0];
@@ -575,7 +575,7 @@ export function getValueDescription(value: any): string {
575
575
  }
576
576
 
577
577
  export function getValueDescriptionWithType(value: any): string {
578
- const valueType = _.isObject(value) ? value.constructor.name : typeof value;
578
+ const valueType = isObject(value) ? value.constructor.name : typeof value;
579
579
  return getValueDescription(value) + ` (${valueType})`;
580
580
  }
581
581