@karta.io/utils 1.0.0-beta.35 → 1.0.0-beta.36
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/index.cjs +24 -16
- package/dist/index.d.cts +2 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.mjs +24 -16
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -87,6 +87,22 @@ class EnrichError extends Error {
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
+
function isHtml(data) {
|
|
91
|
+
try {
|
|
92
|
+
if (typeof DOMParser !== "undefined") {
|
|
93
|
+
const parser = new DOMParser();
|
|
94
|
+
const doc = parser.parseFromString(data, "text/html");
|
|
95
|
+
return Array.from(doc.body.childNodes).some(
|
|
96
|
+
(node) => node.nodeType === Node.ELEMENT_NODE
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
const htmlPattern = /<\/?[a-z][\s\S]*>/i;
|
|
100
|
+
return htmlPattern.test(data);
|
|
101
|
+
} catch (_) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
90
106
|
function getStatusMessage(status) {
|
|
91
107
|
let message = "";
|
|
92
108
|
switch (status) {
|
|
@@ -136,26 +152,18 @@ function formatErrorDataMessage(data) {
|
|
|
136
152
|
return accum;
|
|
137
153
|
}, "");
|
|
138
154
|
}
|
|
139
|
-
function isHtml(data) {
|
|
140
|
-
try {
|
|
141
|
-
if (typeof DOMParser !== "undefined") {
|
|
142
|
-
const parser = new DOMParser();
|
|
143
|
-
const doc = parser.parseFromString(data, "text/html");
|
|
144
|
-
return Array.from(doc.body.childNodes).some(
|
|
145
|
-
(node) => node.nodeType === Node.ELEMENT_NODE
|
|
146
|
-
);
|
|
147
|
-
}
|
|
148
|
-
const htmlPattern = /<\/?[a-z][\s\S]*>/i;
|
|
149
|
-
return htmlPattern.test(data);
|
|
150
|
-
} catch (_) {
|
|
151
|
-
return false;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
155
|
function formatErrorForNotify(error) {
|
|
155
156
|
if (!error)
|
|
156
157
|
return;
|
|
157
158
|
if (error.status >= 400 && error.status < 500) {
|
|
158
|
-
|
|
159
|
+
let message = "";
|
|
160
|
+
if (!error.data || typeof error.data === "string" && isHtml(error.data)) {
|
|
161
|
+
message = error.statusMessage || error.message || getStatusMessage(error.status);
|
|
162
|
+
} else if (typeof error.data === "string" && !isHtml(error.data)) {
|
|
163
|
+
message = error.data;
|
|
164
|
+
} else {
|
|
165
|
+
message = formatErrorDataMessage(error.data);
|
|
166
|
+
}
|
|
159
167
|
return {
|
|
160
168
|
title: "Request error",
|
|
161
169
|
message
|
package/dist/index.d.cts
CHANGED
|
@@ -43,7 +43,6 @@ declare class EnrichError extends Error {
|
|
|
43
43
|
|
|
44
44
|
declare function getStatusMessage(status: number): string;
|
|
45
45
|
declare function formatErrorDataMessage(data?: Record<string, string | string[]>): string;
|
|
46
|
-
declare function isHtml(data: string): boolean;
|
|
47
46
|
declare function formatErrorForNotify(error: Error | ResponseError | any): {
|
|
48
47
|
title: string;
|
|
49
48
|
message: any;
|
|
@@ -77,6 +76,8 @@ declare function isElementIgnored({ ignoredClasses, event, }?: {
|
|
|
77
76
|
|
|
78
77
|
declare function isEmptyObject(object: object): boolean;
|
|
79
78
|
|
|
79
|
+
declare function isHtml(data: string): boolean;
|
|
80
|
+
|
|
80
81
|
interface MapOptions {
|
|
81
82
|
labelKey?: string;
|
|
82
83
|
valueKey?: string;
|
package/dist/index.d.mts
CHANGED
|
@@ -43,7 +43,6 @@ declare class EnrichError extends Error {
|
|
|
43
43
|
|
|
44
44
|
declare function getStatusMessage(status: number): string;
|
|
45
45
|
declare function formatErrorDataMessage(data?: Record<string, string | string[]>): string;
|
|
46
|
-
declare function isHtml(data: string): boolean;
|
|
47
46
|
declare function formatErrorForNotify(error: Error | ResponseError | any): {
|
|
48
47
|
title: string;
|
|
49
48
|
message: any;
|
|
@@ -77,6 +76,8 @@ declare function isElementIgnored({ ignoredClasses, event, }?: {
|
|
|
77
76
|
|
|
78
77
|
declare function isEmptyObject(object: object): boolean;
|
|
79
78
|
|
|
79
|
+
declare function isHtml(data: string): boolean;
|
|
80
|
+
|
|
80
81
|
interface MapOptions {
|
|
81
82
|
labelKey?: string;
|
|
82
83
|
valueKey?: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -43,7 +43,6 @@ declare class EnrichError extends Error {
|
|
|
43
43
|
|
|
44
44
|
declare function getStatusMessage(status: number): string;
|
|
45
45
|
declare function formatErrorDataMessage(data?: Record<string, string | string[]>): string;
|
|
46
|
-
declare function isHtml(data: string): boolean;
|
|
47
46
|
declare function formatErrorForNotify(error: Error | ResponseError | any): {
|
|
48
47
|
title: string;
|
|
49
48
|
message: any;
|
|
@@ -77,6 +76,8 @@ declare function isElementIgnored({ ignoredClasses, event, }?: {
|
|
|
77
76
|
|
|
78
77
|
declare function isEmptyObject(object: object): boolean;
|
|
79
78
|
|
|
79
|
+
declare function isHtml(data: string): boolean;
|
|
80
|
+
|
|
80
81
|
interface MapOptions {
|
|
81
82
|
labelKey?: string;
|
|
82
83
|
valueKey?: string;
|
package/dist/index.mjs
CHANGED
|
@@ -68,6 +68,22 @@ class EnrichError extends Error {
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
function isHtml(data) {
|
|
72
|
+
try {
|
|
73
|
+
if (typeof DOMParser !== "undefined") {
|
|
74
|
+
const parser = new DOMParser();
|
|
75
|
+
const doc = parser.parseFromString(data, "text/html");
|
|
76
|
+
return Array.from(doc.body.childNodes).some(
|
|
77
|
+
(node) => node.nodeType === Node.ELEMENT_NODE
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
const htmlPattern = /<\/?[a-z][\s\S]*>/i;
|
|
81
|
+
return htmlPattern.test(data);
|
|
82
|
+
} catch (_) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
71
87
|
function getStatusMessage(status) {
|
|
72
88
|
let message = "";
|
|
73
89
|
switch (status) {
|
|
@@ -117,26 +133,18 @@ function formatErrorDataMessage(data) {
|
|
|
117
133
|
return accum;
|
|
118
134
|
}, "");
|
|
119
135
|
}
|
|
120
|
-
function isHtml(data) {
|
|
121
|
-
try {
|
|
122
|
-
if (typeof DOMParser !== "undefined") {
|
|
123
|
-
const parser = new DOMParser();
|
|
124
|
-
const doc = parser.parseFromString(data, "text/html");
|
|
125
|
-
return Array.from(doc.body.childNodes).some(
|
|
126
|
-
(node) => node.nodeType === Node.ELEMENT_NODE
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
const htmlPattern = /<\/?[a-z][\s\S]*>/i;
|
|
130
|
-
return htmlPattern.test(data);
|
|
131
|
-
} catch (_) {
|
|
132
|
-
return false;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
136
|
function formatErrorForNotify(error) {
|
|
136
137
|
if (!error)
|
|
137
138
|
return;
|
|
138
139
|
if (error.status >= 400 && error.status < 500) {
|
|
139
|
-
|
|
140
|
+
let message = "";
|
|
141
|
+
if (!error.data || typeof error.data === "string" && isHtml(error.data)) {
|
|
142
|
+
message = error.statusMessage || error.message || getStatusMessage(error.status);
|
|
143
|
+
} else if (typeof error.data === "string" && !isHtml(error.data)) {
|
|
144
|
+
message = error.data;
|
|
145
|
+
} else {
|
|
146
|
+
message = formatErrorDataMessage(error.data);
|
|
147
|
+
}
|
|
140
148
|
return {
|
|
141
149
|
title: "Request error",
|
|
142
150
|
message
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@karta.io/utils",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.36",
|
|
4
4
|
"description": "karta.io utils for admin and application",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"vue": "3.x"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@karta.io/common-data": "^1.0.0-beta.
|
|
28
|
+
"@karta.io/common-data": "^1.0.0-beta.36",
|
|
29
29
|
"@tanstack/vue-query": "5.52.3",
|
|
30
30
|
"@vueuse/core": "11.0.3",
|
|
31
31
|
"async-validator": "4.2.5",
|