@etsoo/shared 1.1.73 → 1.1.74
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/__tests__/Utils.ts +4 -2
- package/lib/cjs/DataTypes.js +4 -1
- package/lib/cjs/Utils.js +6 -2
- package/lib/mjs/DataTypes.js +4 -1
- package/lib/mjs/Utils.js +3 -2
- package/package.json +7 -3
- package/src/DataTypes.ts +5 -2
- package/src/Utils.ts +3 -3
package/__tests__/Utils.ts
CHANGED
|
@@ -56,7 +56,8 @@ test('Tests for getDataChanges', () => {
|
|
|
56
56
|
amount: '',
|
|
57
57
|
enabled: true,
|
|
58
58
|
value: undefined,
|
|
59
|
-
ids: [1, 2]
|
|
59
|
+
ids: [1, 2],
|
|
60
|
+
data: { d1: 1, d2: false, d3: 1.2, d4: 'Hello' }
|
|
60
61
|
};
|
|
61
62
|
const initData = {
|
|
62
63
|
id: 1,
|
|
@@ -66,7 +67,8 @@ test('Tests for getDataChanges', () => {
|
|
|
66
67
|
price: 6,
|
|
67
68
|
amount: 0,
|
|
68
69
|
enabled: true,
|
|
69
|
-
ids: [1, 2]
|
|
70
|
+
ids: [1, 2],
|
|
71
|
+
data: { d1: 1, d3: 1.2, d4: 'Hello', d2: false }
|
|
70
72
|
};
|
|
71
73
|
const fields = Utils.getDataChanges(input, initData);
|
|
72
74
|
expect(fields).toStrictEqual(['gender', 'brand', 'amount']);
|
package/lib/cjs/DataTypes.js
CHANGED
|
@@ -96,8 +96,11 @@ var DataTypes;
|
|
|
96
96
|
}
|
|
97
97
|
// Target type
|
|
98
98
|
const targetType = getBasicNameByValue(target, false);
|
|
99
|
-
if (targetType == null)
|
|
99
|
+
if (targetType == null) {
|
|
100
|
+
if (typeof input === typeof target)
|
|
101
|
+
return input;
|
|
100
102
|
return undefined;
|
|
103
|
+
}
|
|
101
104
|
return convertByType(input, targetType);
|
|
102
105
|
}
|
|
103
106
|
DataTypes.convert = convert;
|
package/lib/cjs/Utils.js
CHANGED
|
@@ -8,9 +8,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
exports.Utils = void 0;
|
|
13
16
|
const DataTypes_1 = require("./DataTypes");
|
|
17
|
+
const lodash_isequal_1 = __importDefault(require("lodash.isequal"));
|
|
14
18
|
String.prototype.format = function (...parameters) {
|
|
15
19
|
let template = this;
|
|
16
20
|
parameters.forEach((value, index) => {
|
|
@@ -139,9 +143,9 @@ var Utils;
|
|
|
139
143
|
return true;
|
|
140
144
|
return v1 === v2;
|
|
141
145
|
}
|
|
142
|
-
// For array and object
|
|
146
|
+
// For date, array and object
|
|
143
147
|
if (typeof v1 === 'object')
|
|
144
|
-
return
|
|
148
|
+
return (0, lodash_isequal_1.default)(v1, v2);
|
|
145
149
|
// 1 and '1' case
|
|
146
150
|
if (strict === 0)
|
|
147
151
|
return v1 == v2;
|
package/lib/mjs/DataTypes.js
CHANGED
|
@@ -93,8 +93,11 @@ export var DataTypes;
|
|
|
93
93
|
}
|
|
94
94
|
// Target type
|
|
95
95
|
const targetType = getBasicNameByValue(target, false);
|
|
96
|
-
if (targetType == null)
|
|
96
|
+
if (targetType == null) {
|
|
97
|
+
if (typeof input === typeof target)
|
|
98
|
+
return input;
|
|
97
99
|
return undefined;
|
|
100
|
+
}
|
|
98
101
|
return convertByType(input, targetType);
|
|
99
102
|
}
|
|
100
103
|
DataTypes.convert = convert;
|
package/lib/mjs/Utils.js
CHANGED
|
@@ -8,6 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { DataTypes } from './DataTypes';
|
|
11
|
+
import isEqual from 'lodash.isequal';
|
|
11
12
|
String.prototype.format = function (...parameters) {
|
|
12
13
|
let template = this;
|
|
13
14
|
parameters.forEach((value, index) => {
|
|
@@ -136,9 +137,9 @@ export var Utils;
|
|
|
136
137
|
return true;
|
|
137
138
|
return v1 === v2;
|
|
138
139
|
}
|
|
139
|
-
// For array and object
|
|
140
|
+
// For date, array and object
|
|
140
141
|
if (typeof v1 === 'object')
|
|
141
|
-
return
|
|
142
|
+
return isEqual(v1, v2);
|
|
142
143
|
// 1 and '1' case
|
|
143
144
|
if (strict === 0)
|
|
144
145
|
return v1 == v2;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/shared",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.74",
|
|
4
4
|
"description": "TypeScript shared utilities and functions",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/mjs/index.js",
|
|
@@ -55,14 +55,18 @@
|
|
|
55
55
|
"homepage": "https://github.com/ETSOO/Shared#readme",
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@types/jest": "^29.2.2",
|
|
58
|
+
"@types/lodash.isequal": "^4.5.6",
|
|
58
59
|
"@typescript-eslint/eslint-plugin": "^5.42.1",
|
|
59
60
|
"@typescript-eslint/parser": "^5.42.1",
|
|
60
61
|
"eslint": "^8.27.0",
|
|
61
62
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
62
63
|
"eslint-plugin-import": "^2.26.0",
|
|
63
|
-
"jest": "^29.3.
|
|
64
|
-
"jest-environment-jsdom": "^29.3.
|
|
64
|
+
"jest": "^29.3.1",
|
|
65
|
+
"jest-environment-jsdom": "^29.3.1",
|
|
65
66
|
"ts-jest": "^29.0.3",
|
|
66
67
|
"typescript": "^4.8.4"
|
|
68
|
+
},
|
|
69
|
+
"dependencies": {
|
|
70
|
+
"lodash.isequal": "^4.5.0"
|
|
67
71
|
}
|
|
68
72
|
}
|
package/src/DataTypes.ts
CHANGED
|
@@ -340,8 +340,11 @@ export namespace DataTypes {
|
|
|
340
340
|
|
|
341
341
|
// Target type
|
|
342
342
|
const targetType = getBasicNameByValue(target, false);
|
|
343
|
-
if (targetType == null)
|
|
344
|
-
|
|
343
|
+
if (targetType == null) {
|
|
344
|
+
if (typeof input === typeof target) return <T>input;
|
|
345
|
+
return undefined;
|
|
346
|
+
}
|
|
347
|
+
return <T>convertByType(input, targetType);
|
|
345
348
|
}
|
|
346
349
|
|
|
347
350
|
/**
|
package/src/Utils.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DataTypes } from './DataTypes';
|
|
2
|
+
import isEqual from 'lodash.isequal';
|
|
2
3
|
|
|
3
4
|
declare global {
|
|
4
5
|
interface String {
|
|
@@ -200,9 +201,8 @@ export namespace Utils {
|
|
|
200
201
|
return v1 === v2;
|
|
201
202
|
}
|
|
202
203
|
|
|
203
|
-
// For array and object
|
|
204
|
-
if (typeof v1 === 'object')
|
|
205
|
-
return JSON.stringify(v1) === JSON.stringify(v2);
|
|
204
|
+
// For date, array and object
|
|
205
|
+
if (typeof v1 === 'object') return isEqual(v1, v2);
|
|
206
206
|
|
|
207
207
|
// 1 and '1' case
|
|
208
208
|
if (strict === 0) return v1 == v2;
|