@etsoo/shared 1.1.73 → 1.1.75
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__/DateUtils.ts +6 -0
- package/__tests__/Utils.ts +4 -2
- package/lib/cjs/DataTypes.js +4 -1
- package/lib/cjs/DateUtils.d.ts +2 -2
- package/lib/cjs/DateUtils.js +7 -2
- package/lib/cjs/Utils.js +6 -2
- package/lib/mjs/DataTypes.js +4 -1
- package/lib/mjs/DateUtils.d.ts +2 -2
- package/lib/mjs/DateUtils.js +7 -2
- package/lib/mjs/Utils.js +3 -2
- package/package.json +7 -3
- package/src/DataTypes.ts +5 -2
- package/src/DateUtils.ts +9 -2
- package/src/Utils.ts +3 -3
package/__tests__/DateUtils.ts
CHANGED
|
@@ -63,8 +63,14 @@ test('Tests for formatForInput', () => {
|
|
|
63
63
|
const result3 = DateUtils.formatForInput(d, false);
|
|
64
64
|
expect(result3).toBe('2021-06-06T20:08');
|
|
65
65
|
|
|
66
|
+
const result31 = DateUtils.formatForInput(d, 'date');
|
|
67
|
+
expect(result31).toBe('2021-06-06');
|
|
68
|
+
|
|
66
69
|
const result4 = DateUtils.formatForInput(d, true);
|
|
67
70
|
expect(result4).toBe('2021-06-06T20:08:45');
|
|
71
|
+
|
|
72
|
+
const result41 = DateUtils.formatForInput(d, 'datetime-local');
|
|
73
|
+
expect(result41).toBe('2021-06-06T20:08:45');
|
|
68
74
|
});
|
|
69
75
|
|
|
70
76
|
test('Tests for substract', () => {
|
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/DateUtils.d.ts
CHANGED
|
@@ -47,9 +47,9 @@ export declare namespace DateUtils {
|
|
|
47
47
|
/**
|
|
48
48
|
* Format to 'yyyy-MM-dd' or 'yyyy-MM-ddThh:mm:ss, especially used for date input min/max property
|
|
49
49
|
* @param date Input date
|
|
50
|
-
* @param
|
|
50
|
+
* @param hasSecondOrType 'undefined' for date only, 'false' for hour:minute only, 'true' for all, or input field type
|
|
51
51
|
*/
|
|
52
|
-
function formatForInput(date?: Date | string | null,
|
|
52
|
+
function formatForInput(date?: Date | string | null, hasSecondOrType?: boolean | string): string;
|
|
53
53
|
/**
|
|
54
54
|
* Get month's days
|
|
55
55
|
* @param year Year
|
package/lib/cjs/DateUtils.js
CHANGED
|
@@ -94,14 +94,19 @@ var DateUtils;
|
|
|
94
94
|
/**
|
|
95
95
|
* Format to 'yyyy-MM-dd' or 'yyyy-MM-ddThh:mm:ss, especially used for date input min/max property
|
|
96
96
|
* @param date Input date
|
|
97
|
-
* @param
|
|
97
|
+
* @param hasSecondOrType 'undefined' for date only, 'false' for hour:minute only, 'true' for all, or input field type
|
|
98
98
|
*/
|
|
99
|
-
function formatForInput(date,
|
|
99
|
+
function formatForInput(date, hasSecondOrType) {
|
|
100
100
|
// Parse string as date
|
|
101
101
|
if (typeof date === 'string')
|
|
102
102
|
date = new Date(date);
|
|
103
103
|
// Default is now
|
|
104
104
|
date !== null && date !== void 0 ? date : (date = new Date());
|
|
105
|
+
const hasSecond = typeof hasSecondOrType === 'string'
|
|
106
|
+
? hasSecondOrType === 'date'
|
|
107
|
+
? undefined
|
|
108
|
+
: true
|
|
109
|
+
: hasSecondOrType;
|
|
105
110
|
// Parts
|
|
106
111
|
const parts = [
|
|
107
112
|
date.getFullYear(),
|
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/DateUtils.d.ts
CHANGED
|
@@ -47,9 +47,9 @@ export declare namespace DateUtils {
|
|
|
47
47
|
/**
|
|
48
48
|
* Format to 'yyyy-MM-dd' or 'yyyy-MM-ddThh:mm:ss, especially used for date input min/max property
|
|
49
49
|
* @param date Input date
|
|
50
|
-
* @param
|
|
50
|
+
* @param hasSecondOrType 'undefined' for date only, 'false' for hour:minute only, 'true' for all, or input field type
|
|
51
51
|
*/
|
|
52
|
-
function formatForInput(date?: Date | string | null,
|
|
52
|
+
function formatForInput(date?: Date | string | null, hasSecondOrType?: boolean | string): string;
|
|
53
53
|
/**
|
|
54
54
|
* Get month's days
|
|
55
55
|
* @param year Year
|
package/lib/mjs/DateUtils.js
CHANGED
|
@@ -91,14 +91,19 @@ export var DateUtils;
|
|
|
91
91
|
/**
|
|
92
92
|
* Format to 'yyyy-MM-dd' or 'yyyy-MM-ddThh:mm:ss, especially used for date input min/max property
|
|
93
93
|
* @param date Input date
|
|
94
|
-
* @param
|
|
94
|
+
* @param hasSecondOrType 'undefined' for date only, 'false' for hour:minute only, 'true' for all, or input field type
|
|
95
95
|
*/
|
|
96
|
-
function formatForInput(date,
|
|
96
|
+
function formatForInput(date, hasSecondOrType) {
|
|
97
97
|
// Parse string as date
|
|
98
98
|
if (typeof date === 'string')
|
|
99
99
|
date = new Date(date);
|
|
100
100
|
// Default is now
|
|
101
101
|
date !== null && date !== void 0 ? date : (date = new Date());
|
|
102
|
+
const hasSecond = typeof hasSecondOrType === 'string'
|
|
103
|
+
? hasSecondOrType === 'date'
|
|
104
|
+
? undefined
|
|
105
|
+
: true
|
|
106
|
+
: hasSecondOrType;
|
|
102
107
|
// Parts
|
|
103
108
|
const parts = [
|
|
104
109
|
date.getFullYear(),
|
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.75",
|
|
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/DateUtils.ts
CHANGED
|
@@ -147,11 +147,11 @@ export namespace DateUtils {
|
|
|
147
147
|
/**
|
|
148
148
|
* Format to 'yyyy-MM-dd' or 'yyyy-MM-ddThh:mm:ss, especially used for date input min/max property
|
|
149
149
|
* @param date Input date
|
|
150
|
-
* @param
|
|
150
|
+
* @param hasSecondOrType 'undefined' for date only, 'false' for hour:minute only, 'true' for all, or input field type
|
|
151
151
|
*/
|
|
152
152
|
export function formatForInput(
|
|
153
153
|
date?: Date | string | null,
|
|
154
|
-
|
|
154
|
+
hasSecondOrType?: boolean | string
|
|
155
155
|
) {
|
|
156
156
|
// Parse string as date
|
|
157
157
|
if (typeof date === 'string') date = new Date(date);
|
|
@@ -159,6 +159,13 @@ export namespace DateUtils {
|
|
|
159
159
|
// Default is now
|
|
160
160
|
date ??= new Date();
|
|
161
161
|
|
|
162
|
+
const hasSecond =
|
|
163
|
+
typeof hasSecondOrType === 'string'
|
|
164
|
+
? hasSecondOrType === 'date'
|
|
165
|
+
? undefined
|
|
166
|
+
: true
|
|
167
|
+
: hasSecondOrType;
|
|
168
|
+
|
|
162
169
|
// Parts
|
|
163
170
|
const parts = [
|
|
164
171
|
date.getFullYear(),
|
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;
|