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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quasar-ui-danx",
3
- "version": "0.3.51",
3
+ "version": "0.3.52",
4
4
  "author": "Dan <dan@flytedesk.com>",
5
5
  "description": "DanX Vue / Quasar component library",
6
6
  "license": "MIT",
@@ -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
- dateTimeString = dateTimeString?.replace("T", " ");
12
- // noinspection JSCheckFunctionSignatures
13
- return DateTime.fromSQL(dateTimeString, { zone: SERVER_TZ }).setZone("local");
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
- dateTimeString = dateTimeString?.replace("T", " ");
23
- // noinspection JSCheckFunctionSignatures
24
- return DateTime.fromSQL(dateTimeString, { zone: "local" }).setZone(SERVER_TZ);
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
- 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");
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
- return DateTime.fromFormat(date, format);
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
- return DateTime.fromFormat(date, format);
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
- return fDate(date, { format: "yyyy/MM/dd" });
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
- return fDateTime(localizedDateTime(dateTimeString), options);
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
- dateTime = null,
88
- { format = "M/d/yy h:mma", empty = "- -" } = {}
89
+ dateTime = null,
90
+ { format = "M/d/yy h:mma", empty = "- -" } = {}
89
91
  ) {
90
- const formatted = (dateTime ? parseDateTime(dateTime) : DateTime.now()).toFormat(format).toLowerCase();
91
- return formatted === "invalid datetime" ? empty : formatted;
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
- return fDateTime(dateTime, { format: "yyyy-MM-dd HH:mm:ss", empty: null });
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
- const formatted = parseDateTime(dateTime).toFormat(format);
112
- return ["Invalid DateTime", "invalid datetime"].includes(formatted) ? empty : formatted;
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
- 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");
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
- return new Intl.NumberFormat("en-US", {
134
- style: "currency",
135
- currency: "USD"
136
- }).format(amount);
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
- return new Intl.NumberFormat("en-US", options).format(number);
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
- 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
- }
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
- multiplier?: number,
171
- maximumFractionDigits?: number,
172
- NaN?: string
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
- options = { multiplier: 100, maximumFractionDigits: 1, NaN: "N/A", ...options };
184
+ options = { multiplier: 100, maximumFractionDigits: 1, NaN: "N/A", ...options };
183
185
 
184
- num = parseFloat("" + num);
186
+ num = parseFloat("" + num);
185
187
 
186
- if (isNaN(num)) {
187
- return options.NaN;
188
- }
188
+ if (isNaN(num)) {
189
+ return options.NaN;
190
+ }
189
191
 
190
- return fNumber(num * (options.multiplier || 100), options) + "%";
192
+ return fNumber(num * (options.multiplier || 100), options) + "%";
191
193
  }
192
194
 
193
195
 
194
196
  export function fPhone(value) {
195
- if (!value || typeof value !== "string") {
196
- return value || "";
197
- }
198
-
199
- const input = value.replace(/\D/g, "").split("");
200
- let phone = "";
201
-
202
- const startsWithOne = input.length > 0 && input[0] === "1";
203
- const shift = startsWithOne ? 1 : 0;
204
-
205
- input.map((number, index) => {
206
- switch (index) {
207
- case shift:
208
- phone += "(";
209
- break;
210
- case shift + 3:
211
- phone += ") ";
212
- break;
213
- case shift + 6:
214
- phone += "-";
215
- break;
216
- case shift + 10:
217
- phone += " x";
218
- break;
219
- }
220
- if (index === 0 && number === "1") {
221
- phone += "+1 ";
222
- } else {
223
- phone += number;
224
- }
225
- });
226
-
227
- if (value === "+1 (") {
228
- return "";
229
- }
230
-
231
- return phone;
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
  }
@@ -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
- return url;
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
- return requestOptions.value.baseUrl + url;
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
- return fetch(request.url(url), {
39
+ url = request.url(url, options.params);
40
+ return fetch(url, {
28
41
  method: "get",
29
42
  headers: {
30
43
  Accept: "application/json",