quasar-ui-danx 0.0.17 → 0.0.18
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +1 -1
- package/src/helpers/formats.ts +87 -46
package/package.json
CHANGED
package/src/helpers/formats.ts
CHANGED
@@ -8,9 +8,9 @@ const SERVER_TZ = new IANAZone("America/Chicago");
|
|
8
8
|
* @returns {DateTime}
|
9
9
|
*/
|
10
10
|
export function localizedDateTime(dateTimeString) {
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
dateTimeString = dateTimeString?.replace("T", " ");
|
12
|
+
// noinspection JSCheckFunctionSignatures
|
13
|
+
return DateTime.fromSQL(dateTimeString, { zone: SERVER_TZ }).setZone("local");
|
14
14
|
}
|
15
15
|
|
16
16
|
/**
|
@@ -19,9 +19,9 @@ export function localizedDateTime(dateTimeString) {
|
|
19
19
|
* @returns {DateTime}
|
20
20
|
*/
|
21
21
|
export function remoteDateTime(dateTimeString) {
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
dateTimeString = dateTimeString?.replace("T", " ");
|
23
|
+
// noinspection JSCheckFunctionSignatures
|
24
|
+
return DateTime.fromSQL(dateTimeString, { zone: "local" }).setZone(SERVER_TZ);
|
25
25
|
}
|
26
26
|
|
27
27
|
/**
|
@@ -29,11 +29,11 @@ export function remoteDateTime(dateTimeString) {
|
|
29
29
|
* @returns {DateTime|*}
|
30
30
|
*/
|
31
31
|
export function parseDateTime(dateTime) {
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
if (typeof dateTime === "string") {
|
33
|
+
dateTime = dateTime.replace("T", " ").replace(/\//g, "-");
|
34
|
+
return DateTime.fromSQL(dateTime);
|
35
|
+
}
|
36
|
+
return dateTime || DateTime.fromSQL("0000-00-00 00:00:00");
|
37
37
|
}
|
38
38
|
|
39
39
|
/**
|
@@ -43,7 +43,7 @@ export function parseDateTime(dateTime) {
|
|
43
43
|
* @returns {DateTime}
|
44
44
|
*/
|
45
45
|
export function parseQDate(date, format = "yyyy/MM/dd") {
|
46
|
-
|
46
|
+
return DateTime.fromFormat(date, format);
|
47
47
|
}
|
48
48
|
|
49
49
|
/**
|
@@ -53,7 +53,7 @@ export function parseQDate(date, format = "yyyy/MM/dd") {
|
|
53
53
|
* @returns {DateTime}
|
54
54
|
*/
|
55
55
|
export function parseQDateTime(date, format = "yyyy/MM/dd HH:mm:ss") {
|
56
|
-
|
56
|
+
return DateTime.fromFormat(date, format);
|
57
57
|
}
|
58
58
|
|
59
59
|
/**
|
@@ -62,7 +62,7 @@ export function parseQDateTime(date, format = "yyyy/MM/dd HH:mm:ss") {
|
|
62
62
|
* @returns {string}
|
63
63
|
*/
|
64
64
|
export function fQDate(date) {
|
65
|
-
|
65
|
+
return fDate(date, { format: "yyyy/MM/dd" });
|
66
66
|
}
|
67
67
|
|
68
68
|
/**
|
@@ -72,7 +72,7 @@ export function fQDate(date) {
|
|
72
72
|
* @returns {string}
|
73
73
|
*/
|
74
74
|
export function fLocalizedDateTime(dateTimeString, options = {}) {
|
75
|
-
|
75
|
+
return fDateTime(localizedDateTime(dateTimeString), options);
|
76
76
|
}
|
77
77
|
|
78
78
|
/**
|
@@ -84,11 +84,11 @@ export function fLocalizedDateTime(dateTimeString, options = {}) {
|
|
84
84
|
* @returns {string}
|
85
85
|
*/
|
86
86
|
export function fDateTime(
|
87
|
-
|
88
|
-
|
87
|
+
dateTime = null,
|
88
|
+
{ format = "M/d/yy h:mma", empty = "- -" } = {}
|
89
89
|
) {
|
90
|
-
|
91
|
-
|
90
|
+
const formatted = (dateTime ? parseDateTime(dateTime) : DateTime.now()).toFormat(format).toLowerCase();
|
91
|
+
return formatted === "invalid datetime" ? empty : formatted;
|
92
92
|
}
|
93
93
|
|
94
94
|
/**
|
@@ -97,7 +97,7 @@ export function fDateTime(
|
|
97
97
|
* @returns {string}
|
98
98
|
*/
|
99
99
|
export function dbDateTime(dateTime = null) {
|
100
|
-
|
100
|
+
return fDateTime(dateTime, { format: "yyyy-MM-dd HH:mm:ss", empty: null });
|
101
101
|
}
|
102
102
|
|
103
103
|
/**
|
@@ -108,8 +108,8 @@ export function dbDateTime(dateTime = null) {
|
|
108
108
|
* @returns {string}
|
109
109
|
*/
|
110
110
|
export function fDate(dateTime, { empty = "--", format = "M/d/yy" } = {}) {
|
111
|
-
|
112
|
-
|
111
|
+
const formatted = parseDateTime(dateTime).toFormat(format);
|
112
|
+
return ["Invalid DateTime", "invalid datetime"].includes(formatted) ? empty : formatted;
|
113
113
|
}
|
114
114
|
|
115
115
|
/**
|
@@ -119,9 +119,9 @@ export function fDate(dateTime, { empty = "--", format = "M/d/yy" } = {}) {
|
|
119
119
|
* @returns {string}
|
120
120
|
*/
|
121
121
|
export function fSecondsToTime(second) {
|
122
|
-
|
123
|
-
|
124
|
-
|
122
|
+
const time = DateTime.now().setZone("UTC").startOf("year").set({ second });
|
123
|
+
const hours = Math.floor(second / 3600);
|
124
|
+
return (hours ? hours + ":" : "") + time.toFormat("mm:ss");
|
125
125
|
}
|
126
126
|
|
127
127
|
/**
|
@@ -130,10 +130,10 @@ export function fSecondsToTime(second) {
|
|
130
130
|
* @returns {string}
|
131
131
|
*/
|
132
132
|
export function fCurrency(amount) {
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
133
|
+
return new Intl.NumberFormat("en-US", {
|
134
|
+
style: "currency",
|
135
|
+
currency: "USD"
|
136
|
+
}).format(amount);
|
137
137
|
}
|
138
138
|
|
139
139
|
/**
|
@@ -143,7 +143,7 @@ export function fCurrency(amount) {
|
|
143
143
|
* @returns {string}
|
144
144
|
*/
|
145
145
|
export function fNumber(number, options = {}) {
|
146
|
-
|
146
|
+
return new Intl.NumberFormat("en-US", options).format(number);
|
147
147
|
}
|
148
148
|
|
149
149
|
/**
|
@@ -153,17 +153,17 @@ export function fNumber(number, options = {}) {
|
|
153
153
|
* @returns {string|*}
|
154
154
|
*/
|
155
155
|
export function centerTruncate(str, maxLength) {
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
156
|
+
if (str.length > maxLength) {
|
157
|
+
const frontCharCount = Math.floor((maxLength - 3) / 2);
|
158
|
+
const backCharCount = maxLength - frontCharCount - 3;
|
159
|
+
return (
|
160
|
+
str.substring(0, frontCharCount) +
|
161
|
+
"..." +
|
162
|
+
str.substring(str.length - backCharCount)
|
163
|
+
);
|
164
|
+
} else {
|
165
|
+
return str;
|
166
|
+
}
|
167
167
|
}
|
168
168
|
|
169
169
|
/**
|
@@ -173,11 +173,52 @@ export function centerTruncate(str, maxLength) {
|
|
173
173
|
* @returns {string}
|
174
174
|
*/
|
175
175
|
export function fPercent(num, options = { multiplier: 100, maximumFractionDigits: 1, NaN: "N/A" }) {
|
176
|
-
|
176
|
+
num = parseFloat(num);
|
177
177
|
|
178
|
-
|
179
|
-
|
180
|
-
|
178
|
+
if (isNaN(num)) {
|
179
|
+
return options.NaN;
|
180
|
+
}
|
181
181
|
|
182
|
-
|
182
|
+
return fNumber(num * options.multiplier, options) + "%";
|
183
|
+
}
|
184
|
+
|
185
|
+
|
186
|
+
export function fPhone(value) {
|
187
|
+
if (!value || typeof value !== "string") {
|
188
|
+
return value || "";
|
189
|
+
}
|
190
|
+
|
191
|
+
const input = value.replace(/\D/g, "").split("");
|
192
|
+
let phone = "";
|
193
|
+
|
194
|
+
const startsWithOne = input.length > 0 && input[0] === "1";
|
195
|
+
const shift = startsWithOne ? 1 : 0;
|
196
|
+
|
197
|
+
input.map((number, index) => {
|
198
|
+
switch (index) {
|
199
|
+
case shift:
|
200
|
+
phone += "(";
|
201
|
+
break;
|
202
|
+
case shift + 3:
|
203
|
+
phone += ") ";
|
204
|
+
break;
|
205
|
+
case shift + 6:
|
206
|
+
phone += "-";
|
207
|
+
break;
|
208
|
+
case shift + 10:
|
209
|
+
phone += " x";
|
210
|
+
break;
|
211
|
+
}
|
212
|
+
if (index === 0 && number === "1") {
|
213
|
+
phone += "+1 ";
|
214
|
+
} else {
|
215
|
+
phone += number;
|
216
|
+
}
|
217
|
+
});
|
218
|
+
|
219
|
+
if (value === "+1 (") {
|
220
|
+
return "";
|
221
|
+
}
|
222
|
+
|
223
|
+
return phone;
|
183
224
|
}
|