@uxf/router 11.32.0 → 11.46.0
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/helper.d.ts +1 -0
- package/helper.js +8 -0
- package/helper.test.d.ts +1 -0
- package/helper.test.js +89 -0
- package/package.json +34 -34
- package/utils/object-to-xml.test.d.ts +1 -0
- package/utils/object-to-xml.test.js +43 -0
package/helper.d.ts
CHANGED
|
@@ -5,4 +5,5 @@ export declare function queryParamToBoolean(param: ParamType): boolean | undefin
|
|
|
5
5
|
export declare function queryParamToBooleanStrict(param: ParamType): boolean;
|
|
6
6
|
export declare function queryParamToNumber(param: ParamType): number | undefined;
|
|
7
7
|
export declare function queryParamToNumberStrict(param: ParamType): number;
|
|
8
|
+
export declare function queryParamToEnumStrict<T>(param: ParamType, enums: Record<string, any>, fallback: T): T;
|
|
8
9
|
export {};
|
package/helper.js
CHANGED
|
@@ -6,6 +6,7 @@ exports.queryParamToBoolean = queryParamToBoolean;
|
|
|
6
6
|
exports.queryParamToBooleanStrict = queryParamToBooleanStrict;
|
|
7
7
|
exports.queryParamToNumber = queryParamToNumber;
|
|
8
8
|
exports.queryParamToNumberStrict = queryParamToNumberStrict;
|
|
9
|
+
exports.queryParamToEnumStrict = queryParamToEnumStrict;
|
|
9
10
|
function queryParamToString(param) {
|
|
10
11
|
if (Array.isArray(param)) {
|
|
11
12
|
throw new Error(`Query parameter is array. Should be string.`);
|
|
@@ -61,3 +62,10 @@ function queryParamToNumberStrict(param) {
|
|
|
61
62
|
}
|
|
62
63
|
return paramOrUndefined;
|
|
63
64
|
}
|
|
65
|
+
function queryParamToEnumStrict(param, enums, fallback) {
|
|
66
|
+
const result = queryParamToString(Array.isArray(param) ? param.at(0) : param);
|
|
67
|
+
if (result && Object.values(enums).includes(result)) {
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
return fallback;
|
|
71
|
+
}
|
package/helper.test.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/helper.test.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const helper_1 = require("./helper");
|
|
4
|
+
describe("Query Parameter Functions", () => {
|
|
5
|
+
describe("queryParamToString", () => {
|
|
6
|
+
it("should return the string when provided", () => {
|
|
7
|
+
expect((0, helper_1.queryParamToString)("test")).toBe("test");
|
|
8
|
+
});
|
|
9
|
+
it("should return undefined when provided as undefined", () => {
|
|
10
|
+
expect((0, helper_1.queryParamToString)(undefined)).toBeUndefined();
|
|
11
|
+
});
|
|
12
|
+
it("should throw an error when provided an array", () => {
|
|
13
|
+
expect(() => (0, helper_1.queryParamToString)(["test"])).toThrowError("Query parameter is array. Should be string.");
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
describe("queryParamToStringStrict", () => {
|
|
17
|
+
it("should return the string when provided", () => {
|
|
18
|
+
expect((0, helper_1.queryParamToStringStrict)("test")).toBe("test");
|
|
19
|
+
});
|
|
20
|
+
it("should throw an error when provided as undefined", () => {
|
|
21
|
+
expect(() => (0, helper_1.queryParamToStringStrict)(undefined)).toThrowError("Parameter not found.");
|
|
22
|
+
});
|
|
23
|
+
it("should throw an error when provided an array", () => {
|
|
24
|
+
expect(() => (0, helper_1.queryParamToStringStrict)(["test"])).toThrowError("Query parameter is array. Should be string.");
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
describe("queryParamToBoolean", () => {
|
|
28
|
+
it('should return true when provided as "true"', () => {
|
|
29
|
+
expect((0, helper_1.queryParamToBoolean)("true")).toBe(true);
|
|
30
|
+
});
|
|
31
|
+
it('should return false when provided as "false"', () => {
|
|
32
|
+
expect((0, helper_1.queryParamToBoolean)("false")).toBe(false);
|
|
33
|
+
});
|
|
34
|
+
it("should return undefined when provided as undefined", () => {
|
|
35
|
+
expect((0, helper_1.queryParamToBoolean)(undefined)).toBeUndefined();
|
|
36
|
+
});
|
|
37
|
+
it("should throw an error when provided as an invalid boolean string", () => {
|
|
38
|
+
expect(() => (0, helper_1.queryParamToBoolean)("invalid")).toThrowError("Parameter should be boolean (true|false). Given 'invalid'.");
|
|
39
|
+
});
|
|
40
|
+
it("should throw an error when provided an array", () => {
|
|
41
|
+
expect(() => (0, helper_1.queryParamToBoolean)(["true"])).toThrowError("Query parameter is array. Should be string.");
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
describe("queryParamToBooleanStrict", () => {
|
|
45
|
+
it('should return true when provided as "true"', () => {
|
|
46
|
+
expect((0, helper_1.queryParamToBooleanStrict)("true")).toBe(true);
|
|
47
|
+
});
|
|
48
|
+
it('should return false when provided as "false"', () => {
|
|
49
|
+
expect((0, helper_1.queryParamToBooleanStrict)("false")).toBe(false);
|
|
50
|
+
});
|
|
51
|
+
it("should throw an error when provided as undefined", () => {
|
|
52
|
+
expect(() => (0, helper_1.queryParamToBooleanStrict)(undefined)).toThrowError("Parameter not found.");
|
|
53
|
+
});
|
|
54
|
+
it("should throw an error when provided an invalid boolean string", () => {
|
|
55
|
+
expect(() => (0, helper_1.queryParamToBooleanStrict)("invalid")).toThrowError("Parameter should be boolean (true|false). Given 'invalid'.");
|
|
56
|
+
});
|
|
57
|
+
it("should throw an error when provided an array", () => {
|
|
58
|
+
expect(() => (0, helper_1.queryParamToBooleanStrict)(["true"])).toThrowError("Query parameter is array. Should be string.");
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
describe("queryParamToNumber", () => {
|
|
62
|
+
it("should return a number when provided a valid string", () => {
|
|
63
|
+
expect((0, helper_1.queryParamToNumber)("123")).toBe(123);
|
|
64
|
+
});
|
|
65
|
+
it("should return undefined when provided as undefined", () => {
|
|
66
|
+
expect((0, helper_1.queryParamToNumber)(undefined)).toBeUndefined();
|
|
67
|
+
});
|
|
68
|
+
it("should throw an error when provided as an invalid number string", () => {
|
|
69
|
+
expect(() => (0, helper_1.queryParamToNumber)("invalid")).toThrowError("Query parameter is NaN. Should be number.");
|
|
70
|
+
});
|
|
71
|
+
it("should throw an error when provided an array", () => {
|
|
72
|
+
expect(() => (0, helper_1.queryParamToNumber)(["123"])).toThrowError("Query parameter is array. Should be number.");
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
describe("queryParamToNumberStrict", () => {
|
|
76
|
+
it("should return a number when provided a valid string", () => {
|
|
77
|
+
expect((0, helper_1.queryParamToNumberStrict)("123")).toBe(123);
|
|
78
|
+
});
|
|
79
|
+
it("should throw an error when provided as undefined", () => {
|
|
80
|
+
expect(() => (0, helper_1.queryParamToNumberStrict)(undefined)).toThrowError("Parameter not found.");
|
|
81
|
+
});
|
|
82
|
+
it("should throw an error when provided as an invalid number string", () => {
|
|
83
|
+
expect(() => (0, helper_1.queryParamToNumberStrict)("invalid")).toThrowError("Query parameter is NaN. Should be number.");
|
|
84
|
+
});
|
|
85
|
+
it("should throw an error when provided an array", () => {
|
|
86
|
+
expect(() => (0, helper_1.queryParamToNumberStrict)(["123"])).toThrowError("Query parameter is array. Should be number.");
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
});
|
package/package.json
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
2
|
+
"name": "@uxf/router",
|
|
3
|
+
"version": "11.46.0",
|
|
4
|
+
"description": "UXF Router",
|
|
5
|
+
"author": "UXFans <dev@uxf.cz>",
|
|
6
|
+
"homepage": "https://gitlab.com/uxf-npm/router#readme",
|
|
7
|
+
"license": "ISC",
|
|
8
|
+
"main": "index.js",
|
|
9
|
+
"typings": "index.d.ts",
|
|
10
|
+
"module": "index.js",
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://gitlab.com/uxf-npm/router.git"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc -P tsconfig.json",
|
|
20
|
+
"typecheck": "tsc --noEmit --skipLibCheck"
|
|
21
|
+
},
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://gitlab.com/uxf-npm/router/issues"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"qs": "6.13.0"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"next": ">= 12"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/qs": "6.9.15",
|
|
33
|
+
"next": "14.2.6"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const object_to_xml_1 = require("./object-to-xml");
|
|
4
|
+
describe("objectToXml", () => {
|
|
5
|
+
it("should convert a simple object to XML format", () => {
|
|
6
|
+
const input = {
|
|
7
|
+
name: "John Doe",
|
|
8
|
+
age: 30,
|
|
9
|
+
city: "New York",
|
|
10
|
+
};
|
|
11
|
+
const expectedOutput = ` <name>John Doe</name>
|
|
12
|
+
<age>30</age>
|
|
13
|
+
<city>New York</city>`;
|
|
14
|
+
expect((0, object_to_xml_1.objectToXml)(input)).toBe(expectedOutput);
|
|
15
|
+
});
|
|
16
|
+
it("should ignore null and undefined values", () => {
|
|
17
|
+
const input = {
|
|
18
|
+
name: "John Doe",
|
|
19
|
+
age: null,
|
|
20
|
+
city: undefined,
|
|
21
|
+
country: "USA",
|
|
22
|
+
};
|
|
23
|
+
const expectedOutput = ` <name>John Doe</name>
|
|
24
|
+
<country>USA</country>`;
|
|
25
|
+
expect((0, object_to_xml_1.objectToXml)(input)).toBe(expectedOutput);
|
|
26
|
+
});
|
|
27
|
+
it("should handle empty objects", () => {
|
|
28
|
+
const input = {};
|
|
29
|
+
const expectedOutput = "";
|
|
30
|
+
expect((0, object_to_xml_1.objectToXml)(input)).toBe(expectedOutput);
|
|
31
|
+
});
|
|
32
|
+
it("should handle numeric values", () => {
|
|
33
|
+
const input = {
|
|
34
|
+
a: 1,
|
|
35
|
+
b: 2.5,
|
|
36
|
+
c: 0,
|
|
37
|
+
};
|
|
38
|
+
const expectedOutput = ` <a>1</a>
|
|
39
|
+
<b>2.5</b>
|
|
40
|
+
<c>0</c>`;
|
|
41
|
+
expect((0, object_to_xml_1.objectToXml)(input)).toBe(expectedOutput);
|
|
42
|
+
});
|
|
43
|
+
});
|