@etsoo/shared 1.1.74 → 1.1.76
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/lib/cjs/DateUtils.d.ts +2 -2
- package/lib/cjs/DateUtils.js +7 -2
- package/lib/cjs/NumberUtils.d.ts +5 -19
- package/lib/cjs/NumberUtils.js +2 -0
- package/lib/mjs/DateUtils.d.ts +2 -2
- package/lib/mjs/DateUtils.js +7 -2
- package/lib/mjs/NumberUtils.d.ts +5 -19
- package/lib/mjs/NumberUtils.js +2 -0
- package/package.json +1 -1
- package/src/DateUtils.ts +9 -2
- package/src/NumberUtils.ts +29 -5
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/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/NumberUtils.d.ts
CHANGED
|
@@ -8,29 +8,15 @@ declare global {
|
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
export declare namespace NumberUtils {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
* @param options Options
|
|
16
|
-
* @returns Result
|
|
17
|
-
*/
|
|
18
|
-
function format(input?: number | bigint, locale?: string | string[], options?: Intl.NumberFormatOptions): string | undefined;
|
|
19
|
-
/**
|
|
20
|
-
* Format money
|
|
21
|
-
* @param input Input
|
|
22
|
-
* @param currency Currency, like USD for US dollar
|
|
23
|
-
* @param locale Locale
|
|
24
|
-
* @param isInteger Is integer value
|
|
25
|
-
* @param options Options
|
|
26
|
-
* @returns Result
|
|
27
|
-
*/
|
|
28
|
-
function formatMoney(input?: number | bigint, currency?: string, locale?: string | string[], isInteger?: boolean, options?: Intl.NumberFormatOptions): string | undefined;
|
|
11
|
+
function format(input: undefined | null, locale?: string | string[], options?: Intl.NumberFormatOptions): undefined;
|
|
12
|
+
function format(input: number | bigint, locale?: string | string[], options?: Intl.NumberFormatOptions): string;
|
|
13
|
+
function formatMoney(input: undefined | null, currency?: string, locale?: string | string[], isInteger?: boolean, options?: Intl.NumberFormatOptions): undefined;
|
|
14
|
+
function formatMoney(input: number | bigint, currency?: string, locale?: string | string[], isInteger?: boolean, options?: Intl.NumberFormatOptions): string;
|
|
29
15
|
/**
|
|
30
16
|
* Parse float value
|
|
31
17
|
* @param rawData Raw data
|
|
32
18
|
*/
|
|
33
|
-
const parse: (rawData:
|
|
19
|
+
const parse: (rawData: unknown) => number;
|
|
34
20
|
/**
|
|
35
21
|
* Parse float value and unit
|
|
36
22
|
* @param input Input string
|
package/lib/cjs/NumberUtils.js
CHANGED
|
@@ -37,6 +37,8 @@ var NumberUtils;
|
|
|
37
37
|
*/
|
|
38
38
|
function formatMoney(input, currency, locale, isInteger = false, options = {}) {
|
|
39
39
|
var _a, _b, _c, _d;
|
|
40
|
+
if (input == null)
|
|
41
|
+
return format(input, locale, options);
|
|
40
42
|
if (currency) {
|
|
41
43
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat
|
|
42
44
|
options.style = 'currency';
|
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/NumberUtils.d.ts
CHANGED
|
@@ -8,29 +8,15 @@ declare global {
|
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
export declare namespace NumberUtils {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
* @param options Options
|
|
16
|
-
* @returns Result
|
|
17
|
-
*/
|
|
18
|
-
function format(input?: number | bigint, locale?: string | string[], options?: Intl.NumberFormatOptions): string | undefined;
|
|
19
|
-
/**
|
|
20
|
-
* Format money
|
|
21
|
-
* @param input Input
|
|
22
|
-
* @param currency Currency, like USD for US dollar
|
|
23
|
-
* @param locale Locale
|
|
24
|
-
* @param isInteger Is integer value
|
|
25
|
-
* @param options Options
|
|
26
|
-
* @returns Result
|
|
27
|
-
*/
|
|
28
|
-
function formatMoney(input?: number | bigint, currency?: string, locale?: string | string[], isInteger?: boolean, options?: Intl.NumberFormatOptions): string | undefined;
|
|
11
|
+
function format(input: undefined | null, locale?: string | string[], options?: Intl.NumberFormatOptions): undefined;
|
|
12
|
+
function format(input: number | bigint, locale?: string | string[], options?: Intl.NumberFormatOptions): string;
|
|
13
|
+
function formatMoney(input: undefined | null, currency?: string, locale?: string | string[], isInteger?: boolean, options?: Intl.NumberFormatOptions): undefined;
|
|
14
|
+
function formatMoney(input: number | bigint, currency?: string, locale?: string | string[], isInteger?: boolean, options?: Intl.NumberFormatOptions): string;
|
|
29
15
|
/**
|
|
30
16
|
* Parse float value
|
|
31
17
|
* @param rawData Raw data
|
|
32
18
|
*/
|
|
33
|
-
const parse: (rawData:
|
|
19
|
+
const parse: (rawData: unknown) => number;
|
|
34
20
|
/**
|
|
35
21
|
* Parse float value and unit
|
|
36
22
|
* @param input Input string
|
package/lib/mjs/NumberUtils.js
CHANGED
|
@@ -34,6 +34,8 @@ export var NumberUtils;
|
|
|
34
34
|
*/
|
|
35
35
|
function formatMoney(input, currency, locale, isInteger = false, options = {}) {
|
|
36
36
|
var _a, _b, _c, _d;
|
|
37
|
+
if (input == null)
|
|
38
|
+
return format(input, locale, options);
|
|
37
39
|
if (currency) {
|
|
38
40
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat
|
|
39
41
|
options.style = 'currency';
|
package/package.json
CHANGED
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/NumberUtils.ts
CHANGED
|
@@ -18,6 +18,16 @@ Number.prototype.toExact = function (this: number, precision?: number) {
|
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
export namespace NumberUtils {
|
|
21
|
+
export function format(
|
|
22
|
+
input: undefined | null,
|
|
23
|
+
locale?: string | string[],
|
|
24
|
+
options?: Intl.NumberFormatOptions
|
|
25
|
+
): undefined;
|
|
26
|
+
export function format(
|
|
27
|
+
input: number | bigint,
|
|
28
|
+
locale?: string | string[],
|
|
29
|
+
options?: Intl.NumberFormatOptions
|
|
30
|
+
): string;
|
|
21
31
|
/**
|
|
22
32
|
* Format number
|
|
23
33
|
* @param input Input
|
|
@@ -26,7 +36,7 @@ export namespace NumberUtils {
|
|
|
26
36
|
* @returns Result
|
|
27
37
|
*/
|
|
28
38
|
export function format(
|
|
29
|
-
input
|
|
39
|
+
input: number | bigint | undefined | null,
|
|
30
40
|
locale?: string | string[],
|
|
31
41
|
options?: Intl.NumberFormatOptions
|
|
32
42
|
) {
|
|
@@ -38,6 +48,20 @@ export namespace NumberUtils {
|
|
|
38
48
|
return intl.format(input);
|
|
39
49
|
}
|
|
40
50
|
|
|
51
|
+
export function formatMoney(
|
|
52
|
+
input: undefined | null,
|
|
53
|
+
currency?: string,
|
|
54
|
+
locale?: string | string[],
|
|
55
|
+
isInteger?: boolean,
|
|
56
|
+
options?: Intl.NumberFormatOptions
|
|
57
|
+
): undefined;
|
|
58
|
+
export function formatMoney(
|
|
59
|
+
input: number | bigint,
|
|
60
|
+
currency?: string,
|
|
61
|
+
locale?: string | string[],
|
|
62
|
+
isInteger?: boolean,
|
|
63
|
+
options?: Intl.NumberFormatOptions
|
|
64
|
+
): string;
|
|
41
65
|
/**
|
|
42
66
|
* Format money
|
|
43
67
|
* @param input Input
|
|
@@ -48,12 +72,14 @@ export namespace NumberUtils {
|
|
|
48
72
|
* @returns Result
|
|
49
73
|
*/
|
|
50
74
|
export function formatMoney(
|
|
51
|
-
input
|
|
75
|
+
input: number | bigint | undefined | null,
|
|
52
76
|
currency?: string,
|
|
53
77
|
locale?: string | string[],
|
|
54
78
|
isInteger: boolean = false,
|
|
55
79
|
options: Intl.NumberFormatOptions = {}
|
|
56
80
|
) {
|
|
81
|
+
if (input == null) return format(input, locale, options);
|
|
82
|
+
|
|
57
83
|
if (currency) {
|
|
58
84
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat
|
|
59
85
|
options.style = 'currency';
|
|
@@ -73,9 +99,7 @@ export namespace NumberUtils {
|
|
|
73
99
|
* Parse float value
|
|
74
100
|
* @param rawData Raw data
|
|
75
101
|
*/
|
|
76
|
-
export const parse = (
|
|
77
|
-
rawData: string | number | undefined | object
|
|
78
|
-
): number => {
|
|
102
|
+
export const parse = (rawData: unknown): number => {
|
|
79
103
|
if (rawData == null) {
|
|
80
104
|
return Number.NaN;
|
|
81
105
|
}
|