@villedemontreal/general-utils 5.17.1 → 5.17.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 (71) hide show
  1. package/dist/config/configs.d.ts +16 -0
  2. package/dist/config/configs.js +38 -0
  3. package/dist/config/configs.js.map +1 -0
  4. package/dist/scripts/index.d.ts +2 -0
  5. package/dist/scripts/index.js +14 -0
  6. package/dist/scripts/index.js.map +1 -0
  7. package/dist/scripts/lint.d.ts +6 -0
  8. package/dist/scripts/lint.js +31 -0
  9. package/dist/scripts/lint.js.map +1 -0
  10. package/dist/scripts/lintFix.d.ts +6 -0
  11. package/dist/scripts/lintFix.js +40 -0
  12. package/dist/scripts/lintFix.js.map +1 -0
  13. package/dist/src/apiError.d.ts +3 -3
  14. package/dist/src/apiError.js +3 -3
  15. package/dist/src/apiError.js.map +1 -1
  16. package/dist/src/apiError.test.js +57 -48
  17. package/dist/src/apiError.test.js.map +1 -1
  18. package/dist/src/apiErrorBuilder.d.ts +1 -1
  19. package/dist/src/apiErrorBuilder.js +2 -2
  20. package/dist/src/apiErrorBuilder.js.map +1 -1
  21. package/dist/src/collectionUtils.js +2 -2
  22. package/dist/src/collectionUtils.js.map +1 -1
  23. package/dist/src/collectionUtils.test.js +12 -4
  24. package/dist/src/collectionUtils.test.js.map +1 -1
  25. package/dist/src/config/constants.d.ts +1 -1
  26. package/dist/src/config/constants.js.map +1 -1
  27. package/dist/src/config/globalConstants.d.ts +1 -1
  28. package/dist/src/config/globalConstants.js +7 -7
  29. package/dist/src/config/globalConstants.js.map +1 -1
  30. package/dist/src/dateUtils.js +6 -2
  31. package/dist/src/dateUtils.js.map +1 -1
  32. package/dist/src/dateUtils.test.js +31 -16
  33. package/dist/src/dateUtils.test.js.map +1 -1
  34. package/dist/src/pagination.d.ts +1 -1
  35. package/dist/src/pagination.js +1 -1
  36. package/dist/src/pagination.js.map +1 -1
  37. package/dist/src/pagination.test.js +14 -5
  38. package/dist/src/pagination.test.js.map +1 -1
  39. package/dist/src/stringUtils.js +4 -1
  40. package/dist/src/stringUtils.js.map +1 -1
  41. package/dist/src/stringUtils.test.js.map +1 -1
  42. package/dist/src/timer.js.map +1 -1
  43. package/dist/src/timer.test.js +47 -32
  44. package/dist/src/timer.test.js.map +1 -1
  45. package/dist/src/utils.d.ts +1 -1
  46. package/dist/src/utils.js +118 -97
  47. package/dist/src/utils.js.map +1 -1
  48. package/dist/src/utils.test.js +219 -196
  49. package/dist/src/utils.test.js.map +1 -1
  50. package/dist/tests-resources/exec/execTest.js +11 -2
  51. package/dist/tests-resources/exec/execTest.js.map +1 -1
  52. package/package.json +8 -5
  53. package/src/apiError.test.ts +57 -27
  54. package/src/apiError.ts +5 -5
  55. package/src/apiErrorBuilder.ts +21 -12
  56. package/src/collectionUtils.test.ts +13 -5
  57. package/src/collectionUtils.ts +11 -7
  58. package/src/config/constants.ts +1 -1
  59. package/src/config/globalConstants.ts +8 -8
  60. package/src/dateUtils.test.ts +40 -20
  61. package/src/dateUtils.ts +25 -11
  62. package/src/logLevel.ts +1 -1
  63. package/src/orderBy.ts +1 -1
  64. package/src/pagination.test.ts +3 -3
  65. package/src/pagination.ts +1 -1
  66. package/src/stringUtils.test.ts +16 -6
  67. package/src/stringUtils.ts +7 -2
  68. package/src/timer.test.ts +3 -3
  69. package/src/timer.ts +1 -1
  70. package/src/utils.test.ts +64 -47
  71. package/src/utils.ts +14 -11
package/src/utils.test.ts CHANGED
@@ -15,12 +15,12 @@ import { ExecError, utils, Utils } from './utils';
15
15
  // A regular "function" is required here for the call to "this.timeout(...)"
16
16
  // @see https://github.com/mochajs/mocha/issues/2018
17
17
  // tslint:disable-next-line:only-arrow-functions ter-prefer-arrow-callback
18
- describe("App's utilities functions", function() {
18
+ describe("App's utilities functions", function () {
19
19
  // ==========================================
20
20
  // tsc()
21
21
  // ==========================================
22
22
  describe('tsc', () => {
23
- it("Compiles a TypeScript file using the 'tsc()' utility", async function() {
23
+ it("Compiles a TypeScript file using the 'tsc()' utility", async function () {
24
24
  if (!fs.existsSync(constants.testDataDirPath)) {
25
25
  fs.mkdirSync(constants.testDataDirPath);
26
26
  }
@@ -37,7 +37,10 @@ describe("App's utilities functions", function() {
37
37
  const fileName = uuid();
38
38
  const filesPathPrefix = tmpRepPath + '/' + fileName;
39
39
  const tsFilePath = filesPathPrefix + '.ts';
40
- fs.writeFileSync(tsFilePath, `import * as path from 'path';\nlet t = 'a';\nt = t + path.sep;`);
40
+ fs.writeFileSync(
41
+ tsFilePath,
42
+ `import * as path from 'path';\nlet t = 'a';\nt = t + path.sep;`,
43
+ );
41
44
 
42
45
  const distRepPath = constants.libRoot + '/dist';
43
46
 
@@ -281,10 +284,18 @@ describe("App's utilities functions", function() {
281
284
  result = utils.isIntegerValue(['string', 2, false]);
282
285
  assert.isFalse(result);
283
286
 
284
- result = utils.isIntegerValue({ firstStringValue: 'a', secondStringValue: 'b', thirdStringValue: 'c' });
287
+ result = utils.isIntegerValue({
288
+ firstStringValue: 'a',
289
+ secondStringValue: 'b',
290
+ thirdStringValue: 'c',
291
+ });
285
292
  assert.isFalse(result);
286
293
 
287
- result = utils.isIntegerValue({ firstNumberValue: 1, secondNumberValue: 2, thirdNumberValue: 3 });
294
+ result = utils.isIntegerValue({
295
+ firstNumberValue: 1,
296
+ secondNumberValue: 2,
297
+ thirdNumberValue: 3,
298
+ });
288
299
  assert.isFalse(result);
289
300
 
290
301
  result = utils.isIntegerValue({ stringValue: 'string', numberValue: 2, booleanValue: false });
@@ -933,7 +944,7 @@ describe("App's utilities functions", function() {
933
944
  fs.removeSync(constants.testDataDirPath);
934
945
  });
935
946
 
936
- it('compile', async function() {
947
+ it('compile', async function () {
937
948
  // May take some time to compile...
938
949
  this.timeout(7000);
939
950
 
@@ -941,9 +952,12 @@ describe("App's utilities functions", function() {
941
952
  const filesPathPrefix = tmpRepPath + '/' + fileName;
942
953
  const tsFilePath = filesPathPrefix + '.ts';
943
954
 
944
- const content = fs.readFileSync(constants.libRoot + '/tests-resources/throwNotManagedSuccess.txt', {
945
- encoding: 'utf-8'
946
- });
955
+ const content = fs.readFileSync(
956
+ constants.libRoot + '/tests-resources/throwNotManagedSuccess.txt',
957
+ {
958
+ encoding: 'utf-8',
959
+ },
960
+ );
947
961
  fs.writeFileSync(tsFilePath, content);
948
962
 
949
963
  await utils.tsc([tsFilePath]);
@@ -953,7 +967,7 @@ describe("App's utilities functions", function() {
953
967
  fs.removeSync(distRepPath);
954
968
  });
955
969
 
956
- it("doesn't compile", async function() {
970
+ it("doesn't compile", async function () {
957
971
  // May take some time to compile...
958
972
  this.timeout(7000);
959
973
 
@@ -966,9 +980,12 @@ describe("App's utilities functions", function() {
966
980
  const filesPathPrefix = tmpRepPath + '/' + fileName;
967
981
  const tsFilePath = filesPathPrefix + '.ts';
968
982
 
969
- const content = fs.readFileSync(constants.libRoot + '/tests-resources/throwNotManagedFail.txt', {
970
- encoding: 'utf-8'
971
- });
983
+ const content = fs.readFileSync(
984
+ constants.libRoot + '/tests-resources/throwNotManagedFail.txt',
985
+ {
986
+ encoding: 'utf-8',
987
+ },
988
+ );
972
989
  fs.writeFileSync(tsFilePath, content);
973
990
 
974
991
  try {
@@ -1003,7 +1020,7 @@ describe("App's utilities functions", function() {
1003
1020
  [],
1004
1021
  [123],
1005
1022
  // tslint:disable-next-line:prefer-array-literal
1006
- new Array(),
1023
+ [],
1007
1024
  null,
1008
1025
  undefined,
1009
1026
  '',
@@ -1013,7 +1030,7 @@ describe("App's utilities functions", function() {
1013
1030
  new Date(),
1014
1031
  () => {
1015
1032
  /* ok */
1016
- }
1033
+ },
1017
1034
  ] as any) {
1018
1035
  assert.isFalse(utils.isObjectStrict(value));
1019
1036
  }
@@ -1028,8 +1045,8 @@ describe("App's utilities functions", function() {
1028
1045
  const array = [
1029
1046
  {
1030
1047
  aaa: 123,
1031
- myKey: 'myValue'
1032
- }
1048
+ myKey: 'myValue',
1049
+ },
1033
1050
  ];
1034
1051
  assert.isTrue(utils.arrayContainsObjectWithKeyEqualsTo(array, 'myKey', 'myValue'));
1035
1052
  });
@@ -1038,8 +1055,8 @@ describe("App's utilities functions", function() {
1038
1055
  const array = [
1039
1056
  {
1040
1057
  aaa: 123,
1041
- myKey: 12345
1042
- }
1058
+ myKey: 12345,
1059
+ },
1043
1060
  ];
1044
1061
  assert.isTrue(utils.arrayContainsObjectWithKeyEqualsTo(array, 'myKey', 12345));
1045
1062
  });
@@ -1049,8 +1066,8 @@ describe("App's utilities functions", function() {
1049
1066
  const array = [
1050
1067
  {
1051
1068
  aaa: 123,
1052
- myKey: someDate
1053
- }
1069
+ myKey: someDate,
1070
+ },
1054
1071
  ];
1055
1072
  assert.isTrue(utils.arrayContainsObjectWithKeyEqualsTo(array, 'myKey', someDate));
1056
1073
  });
@@ -1066,17 +1083,17 @@ describe("App's utilities functions", function() {
1066
1083
  '',
1067
1084
  null,
1068
1085
  {
1069
- juju: 123.45
1070
- }
1086
+ juju: 123.45,
1087
+ },
1071
1088
  ],
1072
- tata: undefined as number
1089
+ tata: undefined as number,
1073
1090
  };
1074
1091
 
1075
1092
  const array = [
1076
1093
  {
1077
1094
  aaa: 123,
1078
- myKey: obj
1079
- }
1095
+ myKey: obj,
1096
+ },
1080
1097
  ];
1081
1098
  assert.isTrue(utils.arrayContainsObjectWithKeyEqualsTo(array, 'myKey', obj));
1082
1099
  });
@@ -1092,17 +1109,17 @@ describe("App's utilities functions", function() {
1092
1109
  '',
1093
1110
  null,
1094
1111
  {
1095
- juju: 123.45
1096
- }
1112
+ juju: 123.45,
1113
+ },
1097
1114
  ],
1098
- tata: undefined as number
1115
+ tata: undefined as number,
1099
1116
  };
1100
1117
 
1101
1118
  const array = [
1102
1119
  {
1103
1120
  aaa: 123,
1104
- nope: obj
1105
- }
1121
+ nope: obj,
1122
+ },
1106
1123
  ];
1107
1124
  assert.isFalse(utils.arrayContainsObjectWithKeyEqualsTo(array, 'myKey', obj));
1108
1125
  });
@@ -1118,17 +1135,17 @@ describe("App's utilities functions", function() {
1118
1135
  '',
1119
1136
  null,
1120
1137
  {
1121
- juju: 123.45
1122
- }
1138
+ juju: 123.45,
1139
+ },
1123
1140
  ],
1124
- tata: undefined as number
1141
+ tata: undefined as number,
1125
1142
  };
1126
1143
 
1127
1144
  const array = [
1128
1145
  {
1129
1146
  aaa: 123,
1130
- myKey: obj
1131
- }
1147
+ myKey: obj,
1148
+ },
1132
1149
  ];
1133
1150
  assert.isFalse(
1134
1151
  utils.arrayContainsObjectWithKeyEqualsTo(array, 'myKey', {
@@ -1139,11 +1156,11 @@ describe("App's utilities functions", function() {
1139
1156
  '',
1140
1157
  null,
1141
1158
  {
1142
- juju: 123.45
1143
- }
1159
+ juju: 123.45,
1160
+ },
1144
1161
  ],
1145
- tata: undefined as number
1146
- })
1162
+ tata: undefined as number,
1163
+ }),
1147
1164
  );
1148
1165
  });
1149
1166
 
@@ -1274,26 +1291,26 @@ describe("App's utilities functions", function() {
1274
1291
 
1275
1292
  it('custom exit code - success', async () => {
1276
1293
  const exitCode = await utils.exec(`node`, [dummyJs, `customExitCode`, `123`], {
1277
- successExitCodes: 123
1294
+ successExitCodes: 123,
1278
1295
  });
1279
1296
  assert.deepEqual(exitCode, 123);
1280
1297
  });
1281
1298
 
1282
1299
  it('custom exit code - multiple', async () => {
1283
1300
  let exitCode = await utils.exec(`node`, [dummyJs, `customExitCode`, `123`], {
1284
- successExitCodes: [0, 123]
1301
+ successExitCodes: [0, 123],
1285
1302
  });
1286
1303
  assert.deepEqual(exitCode, 123);
1287
1304
 
1288
1305
  exitCode = await utils.exec(`node`, [dummyJs, `success`], {
1289
- successExitCodes: [0, 123]
1306
+ successExitCodes: [0, 123],
1290
1307
  });
1291
1308
  assert.deepEqual(exitCode, 0);
1292
1309
 
1293
1310
  let error;
1294
1311
  try {
1295
1312
  await utils.exec(`node`, [dummyJs, `customExitCode`, `1`], {
1296
- successExitCodes: [0, 123]
1313
+ successExitCodes: [0, 123],
1297
1314
  });
1298
1315
  } catch (err) {
1299
1316
  error = err;
@@ -1331,7 +1348,7 @@ describe("App's utilities functions", function() {
1331
1348
  outputHandler: (stdoutOutput: string, stderrOutput: string): void => {
1332
1349
  execOut += stdoutOutput ? stdoutOutput : '';
1333
1350
  execErr += stderrOutput ? stderrOutput : '';
1334
- }
1351
+ },
1335
1352
  });
1336
1353
 
1337
1354
  assert.isTrue(execOut.includes(`in dummy - info`));
@@ -1374,7 +1391,7 @@ describe("App's utilities functions", function() {
1374
1391
  execOut += stdoutOutput ? stdoutOutput : '';
1375
1392
  execErr += stderrOutput ? stderrOutput : '';
1376
1393
  },
1377
- disableConsoleOutputs: true
1394
+ disableConsoleOutputs: true,
1378
1395
  });
1379
1396
 
1380
1397
  assert.isTrue(execOut.includes(`in dummy - info`));
@@ -1400,7 +1417,7 @@ describe("App's utilities functions", function() {
1400
1417
  (stdoutOutput: string, stderrOutput: string): void => {
1401
1418
  execOut += stdoutOutput ? stdoutOutput : '';
1402
1419
  execErr += stderrOutput ? stderrOutput : '';
1403
- }
1420
+ },
1404
1421
  );
1405
1422
  assert.isUndefined(exitCode); // no exit code
1406
1423
 
package/src/utils.ts CHANGED
@@ -84,7 +84,7 @@ export class Utils {
84
84
  * to "clean" it, e.g., getting rid of unmeaningful
85
85
  * decimal zeros or whitespaces.
86
86
  */
87
- public isIntegerValue(value: any, positiveOnly: boolean = false, includeZero: boolean = true): boolean {
87
+ public isIntegerValue(value: any, positiveOnly = false, includeZero = true): boolean {
88
88
  if (this.isNaNSafe(value)) {
89
89
  return false;
90
90
  }
@@ -305,7 +305,7 @@ export class Utils {
305
305
  return;
306
306
  }
307
307
 
308
- const cmd: string = 'node';
308
+ const cmd = 'node';
309
309
  const args = [constants.libRoot + '/node_modules/typescript/lib/tsc.js']
310
310
  .concat(this.tscCompilerOptions)
311
311
  .concat(files);
@@ -319,7 +319,7 @@ export class Utils {
319
319
  * Both "start" and "end" are inclusive.
320
320
  */
321
321
  public range = (start: number, end: number): number[] => {
322
- return [...Array(1 + end - start).keys()].map(v => start + v);
322
+ return [...Array(1 + end - start).keys()].map((v) => start + v);
323
323
  };
324
324
 
325
325
  /**
@@ -435,12 +435,12 @@ export class Utils {
435
435
  command: string,
436
436
  args: string[],
437
437
  dataHandler: (stdoutData: string, stderrData: string) => void = null,
438
- useShellOption: boolean = false
438
+ useShellOption = false,
439
439
  ): Promise<void> {
440
440
  return this.exec(command, args, {
441
441
  outputHandler: dataHandler,
442
442
  useShellOption,
443
- disableConsoleOutputs: !dataHandler
443
+ disableConsoleOutputs: !dataHandler,
444
444
  }).then((_val: number) => {
445
445
  // nothing, returns void
446
446
  });
@@ -494,7 +494,7 @@ export class Utils {
494
494
  disableConsoleOutputs?: boolean;
495
495
  stdio?: StdioOptions;
496
496
  useShellOption?: boolean;
497
- }
497
+ },
498
498
  ): Promise<number> {
499
499
  const optionsClean = options ?? {};
500
500
  optionsClean.useShellOption = optionsClean.useShellOption ?? true;
@@ -515,7 +515,7 @@ export class Utils {
515
515
  detached: false,
516
516
  stdio: optionsClean.stdio,
517
517
  shell: optionsClean.useShellOption,
518
- windowsVerbatimArguments: false
518
+ windowsVerbatimArguments: false,
519
519
  });
520
520
 
521
521
  spawnedProcess.on('close', (code: number) => {
@@ -524,8 +524,8 @@ export class Utils {
524
524
  reject(
525
525
  new ExecError(
526
526
  `Expected success codes were "${successExitCodes.toString()}", but the process exited with "${code}".`,
527
- code
528
- )
527
+ code,
528
+ ),
529
529
  );
530
530
  } else {
531
531
  resolve(code);
@@ -562,7 +562,10 @@ export class Utils {
562
562
  */
563
563
  // tslint:disable-next-line: max-classes-per-file
564
564
  export class ExecError extends Error {
565
- constructor(message: string, public exitCode: number) {
565
+ constructor(
566
+ message: string,
567
+ public exitCode: number,
568
+ ) {
566
569
  super(message);
567
570
  }
568
571
  }
@@ -576,4 +579,4 @@ export function getValueDescriptionWithType(value: any): string {
576
579
  return getValueDescription(value) + ` (${valueType})`;
577
580
  }
578
581
 
579
- export let utils: Utils = new Utils();
582
+ export const utils: Utils = new Utils();