restful-dummy-server 1.0.4 → 1.0.5
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/.npmrc_x +1 -0
- package/dist/utils.js +36 -13
- package/package.json +1 -1
- package/.idea/modules.xml +0 -8
- package/.idea/restful-dummy-server.iml +0 -9
- package/.idea/vcs.xml +0 -7
package/.npmrc_x
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//registry.npmjs.org/:_authToken=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
|
package/dist/utils.js
CHANGED
|
@@ -53,6 +53,40 @@ function getItem(req, filePath) {
|
|
|
53
53
|
return mockData?.find((item) => (isMatchingPathExists(req, item)));
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
// Below cases supporting -
|
|
57
|
+
// 1. url: /test/:input will match with /test/abc or /test/xyz etc.
|
|
58
|
+
// 2. url: /test/*.* will match with /test/abc.jpg or /test/xyz.png etc.
|
|
59
|
+
// 3. url: /test/**/*.jpg will match with /test/abc.jpg or /test/xyz/abc.jpg or /test/test2/xyg.jpg etc.
|
|
60
|
+
// 4. url: /test/**/*.* will match with /test/test2/xyz.jpg or /test/test2/test3/xyz.png etc.
|
|
61
|
+
function buildMockPathRegex(mockPath) {
|
|
62
|
+
if (!mockPath || typeof mockPath !== 'string') {
|
|
63
|
+
throw new Error('mockPath must be a non-empty string');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// 1) Escape literal '.' and '/'
|
|
67
|
+
let pattern = mockPath
|
|
68
|
+
.replace(/\//g, '\\/')
|
|
69
|
+
.replace(/\./g, '\\.');
|
|
70
|
+
|
|
71
|
+
// 2) Handle double-star first (deep wildcard)
|
|
72
|
+
// - matches across '/' as well
|
|
73
|
+
pattern = pattern.replace(/\*\*(?!\*)/g, '[\\w./-]+');
|
|
74
|
+
|
|
75
|
+
// 3) Handle single star (single segment wildcard)
|
|
76
|
+
pattern = pattern.replace(/\*(?!\*)/g, '[\\w.-]+');
|
|
77
|
+
|
|
78
|
+
// 4) Special :list placeholder -> comma-separated list of tokens
|
|
79
|
+
// Example: :list -> SRDSS,ERTT,SAA,SSSS
|
|
80
|
+
pattern = pattern.replace(/:list\b/g, '[\\w.-]+(?:,[\\w.-]+)*');
|
|
81
|
+
|
|
82
|
+
// 5) Other named params like :id, :type etc. -> single token
|
|
83
|
+
pattern = pattern.replace(/:[\w.-]+\b/g, '[\\w.-]+');
|
|
84
|
+
|
|
85
|
+
// 6) Anchor the pattern
|
|
86
|
+
return new RegExp('^' + pattern + '$');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
|
|
56
90
|
/**
|
|
57
91
|
* To check if req path exists on mock data
|
|
58
92
|
*/
|
|
@@ -63,18 +97,7 @@ function isMatchingPathExists(req, mockData) {
|
|
|
63
97
|
// removing starting and trailing /
|
|
64
98
|
path = path.replace(/^\//, '').replace(/\/$/, '');
|
|
65
99
|
mockPath = mockPath.replace(/^\//, '').replace(/\/$/, '');
|
|
66
|
-
|
|
67
|
-
// Below cases supporting -
|
|
68
|
-
// 1. url: /test/:input will match with /test/abc or /test/xyz etc.
|
|
69
|
-
// 2. url: /test/*.* will match with /test/abc.jpg or /test/xyz.png etc.
|
|
70
|
-
// 3. url: /test/**/*.jpg will match with /test/abc.jpg or /test/xyz/abc.jpg or /test/test2/xyg.jpg etc.
|
|
71
|
-
// 4. url: /test/**/*.* will match with /test/test2/xyz.jpg or /test/test2/test3/xyz.png etc.
|
|
72
|
-
const regexForMockPath = mockPath?.replace(/\//g, '\\/')
|
|
73
|
-
.replace(/\./g, '\\.')
|
|
74
|
-
.replace(/\*{2,}/g, '[\\w-\.\/]\+')
|
|
75
|
-
.replace(/\*/g, '[\\w-]\+')
|
|
76
|
-
.replace(/:[\w-\.]+/g, '[\\w-\.]\+');
|
|
77
|
-
const regexEval = eval('/^' + regexForMockPath + '$/'); ;
|
|
100
|
+
const regexEval = buildMockPathRegex(mockPath);
|
|
78
101
|
|
|
79
102
|
if (reqMethod?.toLowerCase() !== mockMethod?.toLowerCase()) {
|
|
80
103
|
return false;
|
|
@@ -88,4 +111,4 @@ function isMatchingPathExists(req, mockData) {
|
|
|
88
111
|
|
|
89
112
|
module.exports = {
|
|
90
113
|
getMatchingDummyData
|
|
91
|
-
};
|
|
114
|
+
};
|
package/package.json
CHANGED
package/.idea/modules.xml
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<project version="4">
|
|
3
|
-
<component name="ProjectModuleManager">
|
|
4
|
-
<modules>
|
|
5
|
-
<module fileurl="file://$PROJECT_DIR$/.idea/restful-dummy-server.iml" filepath="$PROJECT_DIR$/.idea/restful-dummy-server.iml" />
|
|
6
|
-
</modules>
|
|
7
|
-
</component>
|
|
8
|
-
</project>
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<module type="JAVA_MODULE" version="4">
|
|
3
|
-
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
4
|
-
<exclude-output />
|
|
5
|
-
<content url="file://$MODULE_DIR$" />
|
|
6
|
-
<orderEntry type="inheritedJdk" />
|
|
7
|
-
<orderEntry type="sourceFolder" forTests="false" />
|
|
8
|
-
</component>
|
|
9
|
-
</module>
|
package/.idea/vcs.xml
DELETED