Skip to content

Commit 8d914b8

Browse files
committed
fix
1 parent b2ab55e commit 8d914b8

File tree

3 files changed

+116
-101
lines changed

3 files changed

+116
-101
lines changed

dist/hmpl.js

Lines changed: 74 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -12,72 +12,6 @@
1212
})(typeof self !== "undefined" ? self : this, function () {
1313
return (function () {
1414
"use strict";
15-
/**
16-
* Checks if the provided value is an object (excluding arrays and null).
17-
* @param val - The value to check.
18-
* @returns True if val is an object, false otherwise.
19-
*/
20-
const checkObject = (val) => {
21-
return typeof val === "object" && !Array.isArray(val) && val !== null;
22-
};
23-
/**
24-
* Validates whether the provided value is an array of strings.
25-
* @param arr - The value to check, expected to be an array.
26-
* @param currentError - The error message prefix for non-string elements.
27-
* @returns `true` if the value is an array of strings, `false` otherwise.
28-
* If an element is found that is not of the string type, an error is created with details.
29-
*/
30-
const checkIsStringArray = (arr, currentError) => {
31-
if (!Array.isArray(arr)) return false;
32-
let isArrString = true;
33-
for (let i = 0; i < arr.length; i++) {
34-
const arrItem = arr[i];
35-
if (typeof arrItem !== "string") {
36-
createError(
37-
`${currentError}: In the array, the element with index ${i} is not a string`
38-
);
39-
isArrString = false;
40-
break;
41-
}
42-
}
43-
return isArrString;
44-
};
45-
/**
46-
* Checks if the provided value is a function.
47-
* @param val - The value to check.
48-
* @returns True if val is a function, false otherwise.
49-
*/
50-
const checkFunction = (val) => {
51-
return Object.prototype.toString.call(val) === "[object Function]";
52-
};
53-
/**
54-
* Throws a new error with the provided message.
55-
* @param text - The error message.
56-
*/
57-
const createError = (text) => {
58-
throw new Error(text);
59-
};
60-
/**
61-
* Logs a warning message to the console.
62-
* @param text - The warning message.
63-
*/
64-
const createWarning = (text) => {
65-
console.warn(text);
66-
};
67-
/**
68-
* Validates the HTTP method.
69-
* @param method - The HTTP method to validate.
70-
* @returns False if the method is valid, true otherwise.
71-
*/
72-
const getIsMethodValid = (method) => {
73-
return (
74-
method !== "get" &&
75-
method !== "post" &&
76-
method !== "put" &&
77-
method !== "delete" &&
78-
method !== "patch"
79-
);
80-
};
8115
/**
8216
* Constants representing various property names and error messages.
8317
*/
@@ -126,6 +60,18 @@
12660
SANITIZE,
12761
INTERVAL
12862
];
63+
/**
64+
* List of valid HTTP methods
65+
*/
66+
const VALID_METHODS = [
67+
"get",
68+
"post",
69+
"put",
70+
"delete",
71+
"patch",
72+
"trace",
73+
"options"
74+
];
12975
/**
13076
* HTTP status codes without successful responses.
13177
* See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status for more details.
@@ -152,6 +98,66 @@
15298
* Default value for tags to remove from response
15399
*/
154100
const DEFAULT_DISALLOWED_TAGS = [];
101+
/**
102+
* Checks if the provided value is an object (excluding arrays and null).
103+
* @param val - The value to check.
104+
* @returns True if val is an object, false otherwise.
105+
*/
106+
const checkObject = (val) => {
107+
return typeof val === "object" && !Array.isArray(val) && val !== null;
108+
};
109+
/**
110+
* Validates whether the provided value is an array of strings.
111+
* @param arr - The value to check, expected to be an array.
112+
* @param currentError - The error message prefix for non-string elements.
113+
* @returns `true` if the value is an array of strings, `false` otherwise.
114+
* If an element is found that is not of the string type, an error is created with details.
115+
*/
116+
const checkIsStringArray = (arr, currentError) => {
117+
if (!Array.isArray(arr)) return false;
118+
let isArrString = true;
119+
for (let i = 0; i < arr.length; i++) {
120+
const arrItem = arr[i];
121+
if (typeof arrItem !== "string") {
122+
createError(
123+
`${currentError}: In the array, the element with index ${i} is not a string`
124+
);
125+
isArrString = false;
126+
break;
127+
}
128+
}
129+
return isArrString;
130+
};
131+
/**
132+
* Checks if the provided value is a function.
133+
* @param val - The value to check.
134+
* @returns True if val is a function, false otherwise.
135+
*/
136+
const checkFunction = (val) => {
137+
return Object.prototype.toString.call(val) === "[object Function]";
138+
};
139+
/**
140+
* Throws a new error with the provided message.
141+
* @param text - The error message.
142+
*/
143+
const createError = (text) => {
144+
throw new Error(text);
145+
};
146+
/**
147+
* Logs a warning message to the console.
148+
* @param text - The warning message.
149+
*/
150+
const createWarning = (text) => {
151+
console.warn(text);
152+
};
153+
/**
154+
* Validates the HTTP method.
155+
* @param method - The HTTP method to validate.
156+
* @returns False if the method is valid, true otherwise.
157+
*/
158+
const getIsMethodValid = (method) => {
159+
return VALID_METHODS.includes(method.toLowerCase());
160+
};
155161
/**
156162
* Parses a string into a HTML template element.
157163
* @param str - The string to parse.
@@ -698,9 +704,9 @@
698704
const source = req[SOURCE];
699705
if (source) {
700706
const method = (req[METHOD] || "GET").toLowerCase();
701-
if (getIsMethodValid(method)) {
707+
if (!getIsMethodValid(method)) {
702708
createError(
703-
`${REQUEST_COMPONENT_ERROR}: The "${METHOD}" property has only GET, POST, PUT, PATCH or DELETE values`
709+
`${REQUEST_COMPONENT_ERROR}: The "${METHOD}" property has only GET, POST, PUT, PATCH, TRACE, OPTIONS or DELETE values`
704710
);
705711
} else {
706712
const after = req[AFTER];

0 commit comments

Comments
 (0)