@etsoo/shared 1.1.91 → 1.1.92
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 +2 -0
- package/lib/cjs/Utils.js +12 -0
- package/lib/mjs/Utils.js +12 -0
- package/package.json +1 -1
- package/src/Utils.ts +14 -0
package/__tests__/Utils.ts
CHANGED
|
@@ -64,6 +64,7 @@ test('Tests for getDataChanges', () => {
|
|
|
64
64
|
amount: '',
|
|
65
65
|
enabled: true,
|
|
66
66
|
value: undefined,
|
|
67
|
+
date: new Date('2023/03/18'),
|
|
67
68
|
ids: [1, 2],
|
|
68
69
|
data: { d1: 1, d2: false, d3: 1.2, d4: 'Hello' }
|
|
69
70
|
};
|
|
@@ -74,6 +75,7 @@ test('Tests for getDataChanges', () => {
|
|
|
74
75
|
brand: 'ETSOO',
|
|
75
76
|
price: 6,
|
|
76
77
|
amount: 0,
|
|
78
|
+
date: '2023/03/18',
|
|
77
79
|
enabled: true,
|
|
78
80
|
ids: [1, 2],
|
|
79
81
|
data: { d1: 1, d3: 1.2, d4: 'Hello', d2: false }
|
package/lib/cjs/Utils.js
CHANGED
|
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.Utils = void 0;
|
|
16
16
|
const DataTypes_1 = require("./DataTypes");
|
|
17
17
|
const lodash_isequal_1 = __importDefault(require("lodash.isequal"));
|
|
18
|
+
const DateUtils_1 = require("./DateUtils");
|
|
18
19
|
String.prototype.containChinese = function () {
|
|
19
20
|
const regExp = /[\u3040-\u30ff\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff\uff66-\uff9f]/g;
|
|
20
21
|
return regExp.test(this);
|
|
@@ -222,6 +223,7 @@ var Utils;
|
|
|
222
223
|
// Changed fields
|
|
223
224
|
const changes = [];
|
|
224
225
|
Object.entries(input).forEach(([key, value]) => {
|
|
226
|
+
var _a;
|
|
225
227
|
// Ignore fields, no process
|
|
226
228
|
if (ignoreFields.includes(key))
|
|
227
229
|
return;
|
|
@@ -233,6 +235,16 @@ var Utils;
|
|
|
233
235
|
return;
|
|
234
236
|
}
|
|
235
237
|
if (initValue != null) {
|
|
238
|
+
// Date when meets string
|
|
239
|
+
if (value instanceof Date) {
|
|
240
|
+
if (value.valueOf() ===
|
|
241
|
+
((_a = DateUtils_1.DateUtils.parse(initValue)) === null || _a === void 0 ? void 0 : _a.valueOf())) {
|
|
242
|
+
Reflect.deleteProperty(input, key);
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
changes.push(key);
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
236
248
|
const newValue = DataTypes_1.DataTypes.convert(value, initValue);
|
|
237
249
|
if (Utils.equals(newValue, initValue)) {
|
|
238
250
|
Reflect.deleteProperty(input, key);
|
package/lib/mjs/Utils.js
CHANGED
|
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { DataTypes } from './DataTypes';
|
|
11
11
|
import isEqual from 'lodash.isequal';
|
|
12
|
+
import { DateUtils } from './DateUtils';
|
|
12
13
|
String.prototype.containChinese = function () {
|
|
13
14
|
const regExp = /[\u3040-\u30ff\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff\uff66-\uff9f]/g;
|
|
14
15
|
return regExp.test(this);
|
|
@@ -216,6 +217,7 @@ export var Utils;
|
|
|
216
217
|
// Changed fields
|
|
217
218
|
const changes = [];
|
|
218
219
|
Object.entries(input).forEach(([key, value]) => {
|
|
220
|
+
var _a;
|
|
219
221
|
// Ignore fields, no process
|
|
220
222
|
if (ignoreFields.includes(key))
|
|
221
223
|
return;
|
|
@@ -227,6 +229,16 @@ export var Utils;
|
|
|
227
229
|
return;
|
|
228
230
|
}
|
|
229
231
|
if (initValue != null) {
|
|
232
|
+
// Date when meets string
|
|
233
|
+
if (value instanceof Date) {
|
|
234
|
+
if (value.valueOf() ===
|
|
235
|
+
((_a = DateUtils.parse(initValue)) === null || _a === void 0 ? void 0 : _a.valueOf())) {
|
|
236
|
+
Reflect.deleteProperty(input, key);
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
changes.push(key);
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
230
242
|
const newValue = DataTypes.convert(value, initValue);
|
|
231
243
|
if (Utils.equals(newValue, initValue)) {
|
|
232
244
|
Reflect.deleteProperty(input, key);
|
package/package.json
CHANGED
package/src/Utils.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DataTypes } from './DataTypes';
|
|
2
2
|
import isEqual from 'lodash.isequal';
|
|
3
|
+
import { DateUtils } from './DateUtils';
|
|
3
4
|
|
|
4
5
|
declare global {
|
|
5
6
|
interface String {
|
|
@@ -327,6 +328,19 @@ export namespace Utils {
|
|
|
327
328
|
}
|
|
328
329
|
|
|
329
330
|
if (initValue != null) {
|
|
331
|
+
// Date when meets string
|
|
332
|
+
if (value instanceof Date) {
|
|
333
|
+
if (
|
|
334
|
+
value.valueOf() ===
|
|
335
|
+
DateUtils.parse(initValue)?.valueOf()
|
|
336
|
+
) {
|
|
337
|
+
Reflect.deleteProperty(input, key);
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
changes.push(key);
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
|
|
330
344
|
const newValue = DataTypes.convert(value, initValue);
|
|
331
345
|
if (Utils.equals(newValue, initValue)) {
|
|
332
346
|
Reflect.deleteProperty(input, key);
|