@villedemontreal/general-utils 5.17.6 → 5.18.1
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.
- package/dist/config/configs.d.ts +1 -0
- package/dist/config/configs.d.ts.map +1 -0
- package/dist/config/configs.js +1 -24
- package/dist/config/configs.js.map +1 -1
- package/dist/src/apiError.d.ts +1 -0
- package/dist/src/apiError.d.ts.map +1 -0
- package/dist/src/apiError.js +1 -24
- package/dist/src/apiError.js.map +1 -1
- package/dist/src/apiError.test.d.ts +1 -0
- package/dist/src/apiError.test.d.ts.map +1 -0
- package/dist/src/apiErrorBuilder.d.ts +1 -0
- package/dist/src/apiErrorBuilder.d.ts.map +1 -0
- package/dist/src/apiErrorBuilder.js +1 -24
- package/dist/src/apiErrorBuilder.js.map +1 -1
- package/dist/src/collectionUtils.d.ts +1 -0
- package/dist/src/collectionUtils.d.ts.map +1 -0
- package/dist/src/collectionUtils.js +1 -24
- package/dist/src/collectionUtils.js.map +1 -1
- package/dist/src/collectionUtils.test.d.ts +1 -0
- package/dist/src/collectionUtils.test.d.ts.map +1 -0
- package/dist/src/collectionUtils.test.js +1 -24
- package/dist/src/collectionUtils.test.js.map +1 -1
- package/dist/src/config/constants.d.ts +2 -0
- package/dist/src/config/constants.d.ts.map +1 -0
- package/dist/src/config/constants.js +15 -24
- package/dist/src/config/constants.js.map +1 -1
- package/dist/src/config/globalConstants.d.ts +1 -0
- package/dist/src/config/globalConstants.d.ts.map +1 -0
- package/dist/src/dateUtils.d.ts +1 -0
- package/dist/src/dateUtils.d.ts.map +1 -0
- package/dist/src/dateUtils.js +14 -17
- package/dist/src/dateUtils.js.map +1 -1
- package/dist/src/dateUtils.test.d.ts +1 -0
- package/dist/src/dateUtils.test.d.ts.map +1 -0
- package/dist/src/dateUtils.test.js +8 -11
- package/dist/src/dateUtils.test.js.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/logLevel.d.ts +1 -0
- package/dist/src/logLevel.d.ts.map +1 -0
- package/dist/src/logLevel.js +13 -3
- package/dist/src/logLevel.js.map +1 -1
- package/dist/src/logLevel.test.d.ts +2 -0
- package/dist/src/logLevel.test.d.ts.map +1 -0
- package/dist/src/logLevel.test.js +26 -0
- package/dist/src/logLevel.test.js.map +1 -0
- package/dist/src/orderBy.d.ts +1 -0
- package/dist/src/orderBy.d.ts.map +1 -0
- package/dist/src/orderBy.js +1 -24
- package/dist/src/orderBy.js.map +1 -1
- package/dist/src/pagination.d.ts +1 -0
- package/dist/src/pagination.d.ts.map +1 -0
- package/dist/src/pagination.test.d.ts +1 -0
- package/dist/src/pagination.test.d.ts.map +1 -0
- package/dist/src/stringUtils.d.ts +1 -0
- package/dist/src/stringUtils.d.ts.map +1 -0
- package/dist/src/stringUtils.js +1 -24
- package/dist/src/stringUtils.js.map +1 -1
- package/dist/src/stringUtils.test.d.ts +1 -0
- package/dist/src/stringUtils.test.d.ts.map +1 -0
- package/dist/src/timer.d.ts +1 -0
- package/dist/src/timer.d.ts.map +1 -0
- package/dist/src/timer.js +1 -24
- package/dist/src/timer.js.map +1 -1
- package/dist/src/timer.test.d.ts +1 -0
- package/dist/src/timer.test.d.ts.map +1 -0
- package/dist/src/utils.d.ts +1 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/utils.js +19 -46
- package/dist/src/utils.js.map +1 -1
- package/dist/src/utils.test.d.ts +1 -0
- package/dist/src/utils.test.d.ts.map +1 -0
- package/dist/src/utils.test.js +1 -24
- package/dist/src/utils.test.js.map +1 -1
- package/dist/test-data/test_throwNotManaged/249443ee-bd55-4058-b620-258ee0f192cd.d.ts +2 -0
- package/dist/test-data/test_throwNotManaged/249443ee-bd55-4058-b620-258ee0f192cd.d.ts.map +1 -0
- package/dist/test-data/test_throwNotManaged/{99039260-e610-4019-91c3-9ef4255a214b.js → 249443ee-bd55-4058-b620-258ee0f192cd.js} +1 -1
- package/dist/test-data/test_throwNotManaged/{99039260-e610-4019-91c3-9ef4255a214b.js.map → 249443ee-bd55-4058-b620-258ee0f192cd.js.map} +1 -1
- package/dist/tests-resources/exec/execTest.d.ts +1 -0
- package/dist/tests-resources/exec/execTest.d.ts.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +15 -14
- package/src/collectionUtils.ts +1 -1
- package/src/config/constants.ts +16 -1
- package/src/dateUtils.test.ts +2 -2
- package/src/dateUtils.ts +6 -6
- package/src/logLevel.test.ts +26 -0
- package/src/logLevel.ts +13 -3
- package/src/utils.ts +16 -16
- package/dist/test-data/test_throwNotManaged/99039260-e610-4019-91c3-9ef4255a214b.d.ts +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@villedemontreal/general-utils",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.18.1",
|
|
4
4
|
"description": "General utilities library",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"engines": {
|
|
@@ -24,9 +24,10 @@
|
|
|
24
24
|
},
|
|
25
25
|
"repository": {
|
|
26
26
|
"type": "git",
|
|
27
|
-
"url": "https://github.com/villedemontreal/node-
|
|
27
|
+
"url": "https://github.com/villedemontreal/node-core-libs.git",
|
|
28
|
+
"directory": "packages/node-general-utils"
|
|
28
29
|
},
|
|
29
|
-
"homepage": "https://github.com/villedemontreal/node-
|
|
30
|
+
"homepage": "https://github.com/villedemontreal/node-core-libs",
|
|
30
31
|
"keywords": [
|
|
31
32
|
"montreal",
|
|
32
33
|
"utils",
|
|
@@ -42,7 +43,7 @@
|
|
|
42
43
|
"@types/luxon": "3.4.2",
|
|
43
44
|
"app-root-path": "3.1.0",
|
|
44
45
|
"get-port": "5.1.1",
|
|
45
|
-
"globby": "14.0
|
|
46
|
+
"globby": "14.1.0",
|
|
46
47
|
"http-status-codes": "2.3.0",
|
|
47
48
|
"lodash": "4.17.21",
|
|
48
49
|
"luxon": "3.5.0",
|
|
@@ -56,21 +57,21 @@
|
|
|
56
57
|
"@types/mocha": "10.0.10",
|
|
57
58
|
"@types/node": "20.x",
|
|
58
59
|
"@types/sinon": "17.0.4",
|
|
59
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
60
|
-
"@typescript-eslint/parser": "5.
|
|
60
|
+
"@typescript-eslint/eslint-plugin": "5.62.0",
|
|
61
|
+
"@typescript-eslint/parser": "5.62.0",
|
|
61
62
|
"@types/uuid": "10.0.0",
|
|
62
63
|
"chai": "4.5.0",
|
|
63
|
-
"eslint": "8.
|
|
64
|
-
"eslint-config-prettier": "8.
|
|
65
|
-
"eslint-plugin-prettier": "5.2.
|
|
66
|
-
"fs-extra": "11.
|
|
67
|
-
"mocha": "10.
|
|
64
|
+
"eslint": "8.57.1",
|
|
65
|
+
"eslint-config-prettier": "8.10.0",
|
|
66
|
+
"eslint-plugin-prettier": "5.2.4",
|
|
67
|
+
"fs-extra": "11.3.0",
|
|
68
|
+
"mocha": "10.8.2",
|
|
68
69
|
"nyc": "17.1.0",
|
|
69
|
-
"prettier": "3.
|
|
70
|
-
"sinon": "19.0.
|
|
70
|
+
"prettier": "3.5.3",
|
|
71
|
+
"sinon": "19.0.5",
|
|
71
72
|
"source-map-support": "0.5.21",
|
|
72
73
|
"ts-node": "^10.9.2",
|
|
73
|
-
"typescript": "5.
|
|
74
|
+
"typescript": "5.8.2",
|
|
74
75
|
"uuid": "10.0.0"
|
|
75
76
|
}
|
|
76
77
|
}
|
package/src/collectionUtils.ts
CHANGED
package/src/config/constants.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as fs from 'fs';
|
|
2
2
|
import * as path from 'path';
|
|
3
|
+
import { path as appRoot } from 'app-root-path';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Library constants
|
|
@@ -32,6 +33,20 @@ export class Constants {
|
|
|
32
33
|
get testDataDirPath() {
|
|
33
34
|
return this.libRoot + '/test-data';
|
|
34
35
|
}
|
|
36
|
+
|
|
37
|
+
public findModulePath(subPath: string): string {
|
|
38
|
+
let current = this.libRoot;
|
|
39
|
+
let counter = 0;
|
|
40
|
+
while (counter < 10 && current !== '/' && fs.existsSync(current)) {
|
|
41
|
+
const p = path.join(current, subPath);
|
|
42
|
+
if (fs.existsSync(p)) {
|
|
43
|
+
return path.normalize(p);
|
|
44
|
+
}
|
|
45
|
+
current = path.normalize(path.join(current, '..'));
|
|
46
|
+
counter += 1;
|
|
47
|
+
}
|
|
48
|
+
throw new Error(`Could not find module "${subPath}"`);
|
|
49
|
+
}
|
|
35
50
|
}
|
|
36
51
|
|
|
37
52
|
export const constants: Constants = new Constants();
|
package/src/dateUtils.test.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { assert } from 'chai';
|
|
2
|
-
import _ from 'lodash';
|
|
3
|
-
import moment from 'moment';
|
|
2
|
+
import * as _ from 'lodash';
|
|
3
|
+
import * as moment from 'moment';
|
|
4
4
|
import { getValueDescription, getValueDescriptionWithType, utils } from '.';
|
|
5
5
|
import { getCartesianProduct } from './collectionUtils';
|
|
6
6
|
import {
|
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 (
|
|
233
|
+
if (isNil(isoDate)) {
|
|
234
234
|
return isoDate;
|
|
235
235
|
}
|
|
236
236
|
|
|
237
|
-
let luxonDate = DateTime.fromISO(
|
|
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 (
|
|
264
|
+
if (isNil(isoDate)) {
|
|
265
265
|
return isoDate;
|
|
266
266
|
}
|
|
267
267
|
|
|
268
|
-
let luxonDate = DateTime.fromISO(
|
|
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
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { assert } from 'chai';
|
|
2
|
+
import { LogLevel, logLevelFromString, logLevelToString } from './logLevel';
|
|
3
|
+
|
|
4
|
+
describe('logLevel', () => {
|
|
5
|
+
it('logLevelFromString success', () => {
|
|
6
|
+
assert.equal(logLevelFromString('debug'), LogLevel.DEBUG);
|
|
7
|
+
assert.equal(logLevelFromString('Debug'), LogLevel.DEBUG);
|
|
8
|
+
assert.equal(logLevelFromString('DEBUG'), LogLevel.DEBUG);
|
|
9
|
+
assert.equal(logLevelFromString('info'), LogLevel.INFO);
|
|
10
|
+
assert.equal(logLevelFromString('error'), LogLevel.ERROR);
|
|
11
|
+
assert.equal(logLevelFromString('trace'), LogLevel.TRACE);
|
|
12
|
+
assert.equal(logLevelFromString('warning'), LogLevel.WARNING);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('logLevelFromString failure', () => {
|
|
16
|
+
assert.isUndefined(logLevelFromString('zorg'));
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('logLevelFromString success', () => {
|
|
20
|
+
assert.equal(logLevelToString(LogLevel.DEBUG), 'DEBUG');
|
|
21
|
+
assert.equal(logLevelToString(LogLevel.ERROR), 'ERROR');
|
|
22
|
+
assert.equal(logLevelToString(LogLevel.INFO), 'INFO');
|
|
23
|
+
assert.equal(logLevelToString(LogLevel.TRACE), 'TRACE');
|
|
24
|
+
assert.equal(logLevelToString(LogLevel.WARNING), 'WARNING');
|
|
25
|
+
});
|
|
26
|
+
});
|
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
|
-
|
|
28
|
-
|
|
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 undefined;
|
|
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 =
|
|
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:
|
|
274
|
+
// TS6064: Options 'plugins', 'composite' can only be specified in 'tsconfig.json' file.
|
|
274
275
|
// ==========================================
|
|
275
|
-
if (
|
|
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
|
|
310
|
-
|
|
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 (
|
|
365
|
+
if (isNil(value)) {
|
|
366
366
|
return null;
|
|
367
367
|
}
|
|
368
368
|
|
|
369
|
-
if (
|
|
369
|
+
if (isDate(value)) {
|
|
370
370
|
date = value;
|
|
371
|
-
} else if (!
|
|
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
|
|
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 || !
|
|
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) &&
|
|
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
|
-
?
|
|
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 =
|
|
578
|
+
const valueType = isObject(value) ? value.constructor.name : typeof value;
|
|
579
579
|
return getValueDescription(value) + ` (${valueType})`;
|
|
580
580
|
}
|
|
581
581
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|