@inzombieland/nuxt-common 1.18.37 → 1.18.38
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/module.json +1 -1
- package/dist/module.mjs +1 -1
- package/dist/runtime/packages/core/helpers/api-helper.mjs +28 -4
- package/dist/runtime/packages/core/helpers/index.d.ts +0 -1
- package/dist/runtime/packages/core/helpers/index.mjs +0 -1
- package/dist/runtime/packages/core/package.json +1 -1
- package/package.json +1 -1
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
2
2
|
import { defineNuxtModule, createResolver, addServerHandler, addImportsDir, addPlugin, addComponent } from '@nuxt/kit';
|
|
3
3
|
|
|
4
4
|
const name = "@inzombieland/nuxt-common";
|
|
5
|
-
const version = "1.18.
|
|
5
|
+
const version = "1.18.38";
|
|
6
6
|
|
|
7
7
|
const module = defineNuxtModule({
|
|
8
8
|
meta: {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
const isoExp = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)((-(\d{2}):(\d{2})|Z)?)$/gm;
|
|
1
|
+
const isoExp = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)((-(\d{2}):(\d{2})|Z)?)$/;
|
|
3
2
|
const isISODate = (value) => {
|
|
4
3
|
return typeof value === "string" && isoExp.test(value);
|
|
5
4
|
};
|
|
@@ -40,7 +39,7 @@ export function convertToClient(data) {
|
|
|
40
39
|
} else if (isObject(value)) {
|
|
41
40
|
res[newKey] = convertToClient(value);
|
|
42
41
|
} else if (isISODate(value)) {
|
|
43
|
-
res[newKey] =
|
|
42
|
+
res[newKey] = stringToDate(value);
|
|
44
43
|
} else if (value === null) {
|
|
45
44
|
delete res[newKey];
|
|
46
45
|
} else {
|
|
@@ -82,7 +81,7 @@ export function convertToServer(data) {
|
|
|
82
81
|
} else if (isObject(value)) {
|
|
83
82
|
res[newKey] = convertToServer(value);
|
|
84
83
|
} else if (isDate(value)) {
|
|
85
|
-
res[newKey] =
|
|
84
|
+
res[newKey] = dateToString(value);
|
|
86
85
|
} else {
|
|
87
86
|
res[newKey] = value;
|
|
88
87
|
}
|
|
@@ -96,6 +95,31 @@ function parseData(data) {
|
|
|
96
95
|
return data;
|
|
97
96
|
}
|
|
98
97
|
}
|
|
98
|
+
function stringToDate(dateString) {
|
|
99
|
+
if (typeof dateString !== "string" || dateString === "0001-01-01T00:00:00Z") {
|
|
100
|
+
return void 0;
|
|
101
|
+
}
|
|
102
|
+
const parts = isoExp.exec(dateString);
|
|
103
|
+
if (!parts) {
|
|
104
|
+
return new Date(Number.NaN);
|
|
105
|
+
}
|
|
106
|
+
const year = Number(parts[1]);
|
|
107
|
+
const month = Number(parts[2]) - 1;
|
|
108
|
+
const day = Number(parts[3]);
|
|
109
|
+
const hours = Number(parts[4]);
|
|
110
|
+
const minutes = Number(parts[5]);
|
|
111
|
+
const seconds = Number(parts[6]);
|
|
112
|
+
return parts.at(-1) === "Z" ? new Date(Date.UTC(year, month, day, hours, minutes, seconds)) : new Date(year, month, day, hours, minutes, seconds);
|
|
113
|
+
}
|
|
114
|
+
function dateToString(date) {
|
|
115
|
+
const year = date.getFullYear();
|
|
116
|
+
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
117
|
+
const day = String(date.getDate()).padStart(2, "0");
|
|
118
|
+
const hours = String(date.getHours()).padStart(2, "0");
|
|
119
|
+
const minutes = String(date.getMinutes()).padStart(2, "0");
|
|
120
|
+
const seconds = String(date.getSeconds()).padStart(2, "0");
|
|
121
|
+
return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}`;
|
|
122
|
+
}
|
|
99
123
|
export const apiHelper = { convertToClient, convertToServer };
|
|
100
124
|
export const useApiHelper = () => {
|
|
101
125
|
return apiHelper;
|