quasar-ui-danx 0.3.51 → 0.3.52
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/dist/danx.es.js +208 -202
- package/dist/danx.es.js.map +1 -1
- package/dist/danx.umd.js +4 -4
- package/dist/danx.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/helpers/formats.ts +89 -87
- package/src/helpers/request.ts +18 -5
package/package.json
CHANGED
package/src/helpers/formats.ts
CHANGED
@@ -2,15 +2,17 @@ import { DateTime, IANAZone } from "luxon";
|
|
2
2
|
|
3
3
|
const SERVER_TZ = new IANAZone("America/Chicago");
|
4
4
|
|
5
|
+
export const LuxonDateTime = DateTime;
|
6
|
+
|
5
7
|
/**
|
6
8
|
* Converts a date string from the server's time zone to the user's time zone.
|
7
9
|
* @param {String} dateTimeString
|
8
10
|
* @returns {DateTime}
|
9
11
|
*/
|
10
12
|
export function localizedDateTime(dateTimeString) {
|
11
|
-
|
12
|
-
|
13
|
-
|
13
|
+
dateTimeString = dateTimeString?.replace("T", " ");
|
14
|
+
// noinspection JSCheckFunctionSignatures
|
15
|
+
return DateTime.fromSQL(dateTimeString, { zone: SERVER_TZ }).setZone("local");
|
14
16
|
}
|
15
17
|
|
16
18
|
/**
|
@@ -19,9 +21,9 @@ export function localizedDateTime(dateTimeString) {
|
|
19
21
|
* @returns {DateTime}
|
20
22
|
*/
|
21
23
|
export function remoteDateTime(dateTimeString) {
|
22
|
-
|
23
|
-
|
24
|
-
|
24
|
+
dateTimeString = dateTimeString?.replace("T", " ");
|
25
|
+
// noinspection JSCheckFunctionSignatures
|
26
|
+
return DateTime.fromSQL(dateTimeString, { zone: "local" }).setZone(SERVER_TZ);
|
25
27
|
}
|
26
28
|
|
27
29
|
/**
|
@@ -29,11 +31,11 @@ export function remoteDateTime(dateTimeString) {
|
|
29
31
|
* @returns {DateTime|*}
|
30
32
|
*/
|
31
33
|
export function parseDateTime(dateTime) {
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
if (typeof dateTime === "string") {
|
35
|
+
dateTime = dateTime.replace("T", " ").replace(/\//g, "-");
|
36
|
+
return DateTime.fromSQL(dateTime);
|
37
|
+
}
|
38
|
+
return dateTime || DateTime.fromSQL("0000-00-00 00:00:00");
|
37
39
|
}
|
38
40
|
|
39
41
|
/**
|
@@ -43,7 +45,7 @@ export function parseDateTime(dateTime) {
|
|
43
45
|
* @returns {DateTime}
|
44
46
|
*/
|
45
47
|
export function parseQDate(date, format = "yyyy/MM/dd") {
|
46
|
-
|
48
|
+
return DateTime.fromFormat(date, format);
|
47
49
|
}
|
48
50
|
|
49
51
|
/**
|
@@ -53,7 +55,7 @@ export function parseQDate(date, format = "yyyy/MM/dd") {
|
|
53
55
|
* @returns {DateTime}
|
54
56
|
*/
|
55
57
|
export function parseQDateTime(date, format = "yyyy/MM/dd HH:mm:ss") {
|
56
|
-
|
58
|
+
return DateTime.fromFormat(date, format);
|
57
59
|
}
|
58
60
|
|
59
61
|
/**
|
@@ -62,7 +64,7 @@ export function parseQDateTime(date, format = "yyyy/MM/dd HH:mm:ss") {
|
|
62
64
|
* @returns {string}
|
63
65
|
*/
|
64
66
|
export function fQDate(date) {
|
65
|
-
|
67
|
+
return fDate(date, { format: "yyyy/MM/dd" });
|
66
68
|
}
|
67
69
|
|
68
70
|
/**
|
@@ -72,7 +74,7 @@ export function fQDate(date) {
|
|
72
74
|
* @returns {string}
|
73
75
|
*/
|
74
76
|
export function fLocalizedDateTime(dateTimeString, options = {}) {
|
75
|
-
|
77
|
+
return fDateTime(localizedDateTime(dateTimeString), options);
|
76
78
|
}
|
77
79
|
|
78
80
|
/**
|
@@ -84,11 +86,11 @@ export function fLocalizedDateTime(dateTimeString, options = {}) {
|
|
84
86
|
* @returns {string}
|
85
87
|
*/
|
86
88
|
export function fDateTime(
|
87
|
-
|
88
|
-
|
89
|
+
dateTime = null,
|
90
|
+
{ format = "M/d/yy h:mma", empty = "- -" } = {}
|
89
91
|
) {
|
90
|
-
|
91
|
-
|
92
|
+
const formatted = (dateTime ? parseDateTime(dateTime) : DateTime.now()).toFormat(format).toLowerCase();
|
93
|
+
return formatted === "invalid datetime" ? empty : formatted;
|
92
94
|
}
|
93
95
|
|
94
96
|
/**
|
@@ -97,7 +99,7 @@ export function fDateTime(
|
|
97
99
|
* @returns {string}
|
98
100
|
*/
|
99
101
|
export function dbDateTime(dateTime = null) {
|
100
|
-
|
102
|
+
return fDateTime(dateTime, { format: "yyyy-MM-dd HH:mm:ss", empty: null });
|
101
103
|
}
|
102
104
|
|
103
105
|
/**
|
@@ -108,8 +110,8 @@ export function dbDateTime(dateTime = null) {
|
|
108
110
|
* @returns {string}
|
109
111
|
*/
|
110
112
|
export function fDate(dateTime, { empty = "--", format = "M/d/yy" } = {}) {
|
111
|
-
|
112
|
-
|
113
|
+
const formatted = parseDateTime(dateTime).toFormat(format);
|
114
|
+
return ["Invalid DateTime", "invalid datetime"].includes(formatted) ? empty : formatted;
|
113
115
|
}
|
114
116
|
|
115
117
|
/**
|
@@ -119,9 +121,9 @@ export function fDate(dateTime, { empty = "--", format = "M/d/yy" } = {}) {
|
|
119
121
|
* @returns {string}
|
120
122
|
*/
|
121
123
|
export function fSecondsToTime(second) {
|
122
|
-
|
123
|
-
|
124
|
-
|
124
|
+
const time = DateTime.now().setZone("UTC").startOf("year").set({ second });
|
125
|
+
const hours = Math.floor(second / 3600);
|
126
|
+
return (hours ? hours + ":" : "") + time.toFormat("mm:ss");
|
125
127
|
}
|
126
128
|
|
127
129
|
/**
|
@@ -130,10 +132,10 @@ export function fSecondsToTime(second) {
|
|
130
132
|
* @returns {string}
|
131
133
|
*/
|
132
134
|
export function fCurrency(amount) {
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
135
|
+
return new Intl.NumberFormat("en-US", {
|
136
|
+
style: "currency",
|
137
|
+
currency: "USD"
|
138
|
+
}).format(amount);
|
137
139
|
}
|
138
140
|
|
139
141
|
/**
|
@@ -143,7 +145,7 @@ export function fCurrency(amount) {
|
|
143
145
|
* @returns {string}
|
144
146
|
*/
|
145
147
|
export function fNumber(number, options = {}) {
|
146
|
-
|
148
|
+
return new Intl.NumberFormat("en-US", options).format(number);
|
147
149
|
}
|
148
150
|
|
149
151
|
/**
|
@@ -153,23 +155,23 @@ export function fNumber(number, options = {}) {
|
|
153
155
|
* @returns {string|*}
|
154
156
|
*/
|
155
157
|
export function centerTruncate(str, maxLength) {
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
158
|
+
if (str.length > maxLength) {
|
159
|
+
const frontCharCount = Math.floor((maxLength - 3) / 2);
|
160
|
+
const backCharCount = maxLength - frontCharCount - 3;
|
161
|
+
return (
|
162
|
+
str.substring(0, frontCharCount) +
|
163
|
+
"..." +
|
164
|
+
str.substring(str.length - backCharCount)
|
165
|
+
);
|
166
|
+
} else {
|
167
|
+
return str;
|
168
|
+
}
|
167
169
|
}
|
168
170
|
|
169
171
|
interface FPercentOptions {
|
170
|
-
|
171
|
-
|
172
|
-
|
172
|
+
multiplier?: number,
|
173
|
+
maximumFractionDigits?: number,
|
174
|
+
NaN?: string
|
173
175
|
}
|
174
176
|
|
175
177
|
/**
|
@@ -179,54 +181,54 @@ interface FPercentOptions {
|
|
179
181
|
* @returns {string}
|
180
182
|
*/
|
181
183
|
export function fPercent(num: string | number, options: FPercentOptions = {}) {
|
182
|
-
|
184
|
+
options = { multiplier: 100, maximumFractionDigits: 1, NaN: "N/A", ...options };
|
183
185
|
|
184
|
-
|
186
|
+
num = parseFloat("" + num);
|
185
187
|
|
186
|
-
|
187
|
-
|
188
|
-
|
188
|
+
if (isNaN(num)) {
|
189
|
+
return options.NaN;
|
190
|
+
}
|
189
191
|
|
190
|
-
|
192
|
+
return fNumber(num * (options.multiplier || 100), options) + "%";
|
191
193
|
}
|
192
194
|
|
193
195
|
|
194
196
|
export function fPhone(value) {
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
197
|
+
if (!value || typeof value !== "string") {
|
198
|
+
return value || "";
|
199
|
+
}
|
200
|
+
|
201
|
+
const input = value.replace(/\D/g, "").split("");
|
202
|
+
let phone = "";
|
203
|
+
|
204
|
+
const startsWithOne = input.length > 0 && input[0] === "1";
|
205
|
+
const shift = startsWithOne ? 1 : 0;
|
206
|
+
|
207
|
+
input.map((number, index) => {
|
208
|
+
switch (index) {
|
209
|
+
case shift:
|
210
|
+
phone += "(";
|
211
|
+
break;
|
212
|
+
case shift + 3:
|
213
|
+
phone += ") ";
|
214
|
+
break;
|
215
|
+
case shift + 6:
|
216
|
+
phone += "-";
|
217
|
+
break;
|
218
|
+
case shift + 10:
|
219
|
+
phone += " x";
|
220
|
+
break;
|
221
|
+
}
|
222
|
+
if (index === 0 && number === "1") {
|
223
|
+
phone += "+1 ";
|
224
|
+
} else {
|
225
|
+
phone += number;
|
226
|
+
}
|
227
|
+
});
|
228
|
+
|
229
|
+
if (value === "+1 (") {
|
230
|
+
return "";
|
231
|
+
}
|
232
|
+
|
233
|
+
return phone;
|
232
234
|
}
|
package/src/helpers/request.ts
CHANGED
@@ -16,15 +16,28 @@ export const request = {
|
|
16
16
|
requestOptions.value = options;
|
17
17
|
},
|
18
18
|
|
19
|
-
url(url: string) {
|
20
|
-
if (url.startsWith("http")) {
|
21
|
-
|
19
|
+
url(url: string, params: string | string[][] | Record<string, string> | URLSearchParams | undefined = undefined) {
|
20
|
+
if (!url.startsWith("http")) {
|
21
|
+
url = requestOptions.value.baseUrl + url;
|
22
22
|
}
|
23
|
-
|
23
|
+
|
24
|
+
if (params) {
|
25
|
+
// Transform object values in params to JSON strings
|
26
|
+
for (const [key, value] of Object.entries(params)) {
|
27
|
+
if (typeof value === "object" && value !== null) {
|
28
|
+
params[key] = JSON.stringify(value);
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
url += (url.match(/\?/) ? "&" : "?") + new URLSearchParams(params).toString();
|
33
|
+
}
|
34
|
+
|
35
|
+
return url;
|
24
36
|
},
|
25
37
|
|
26
38
|
async get(url: string, options = {}): Promise<object> {
|
27
|
-
|
39
|
+
url = request.url(url, options.params);
|
40
|
+
return fetch(url, {
|
28
41
|
method: "get",
|
29
42
|
headers: {
|
30
43
|
Accept: "application/json",
|