@esportsplus/routing 0.0.9 → 0.0.11
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/build/hash.d.ts +70 -0
- package/build/hash.js +75 -0
- package/build/index.d.ts +6 -92
- package/build/index.js +6 -8
- package/build/middleware/dispatch.d.ts +5 -0
- package/build/middleware/dispatch.js +7 -0
- package/build/middleware/factory.d.ts +3 -3
- package/build/middleware/factory.js +13 -13
- package/build/middleware/index.d.ts +17 -47
- package/build/middleware/index.js +5 -4
- package/build/middleware/match.d.ts +5 -0
- package/build/middleware/match.js +23 -0
- package/build/router/index.d.ts +26 -0
- package/build/router/index.js +160 -0
- package/build/router/node.d.ts +17 -0
- package/build/router/node.js +93 -0
- package/build/router/path.d.ts +6 -0
- package/build/router/path.js +20 -0
- package/build/router/route.d.ts +13 -0
- package/build/router/route.js +24 -0
- package/build/slugify.d.ts +2 -0
- package/build/slugify.js +3 -0
- package/build/symbols.d.ts +4 -0
- package/build/symbols.js +4 -0
- package/build/types.d.ts +18 -26
- package/build/types.js +2 -1
- package/package.json +5 -4
- package/readme.md +1 -0
- package/src/hash.ts +106 -0
- package/src/index.ts +4 -6
- package/src/middleware/dispatch.ts +12 -0
- package/src/middleware/index.ts +5 -4
- package/src/middleware/match.ts +32 -0
- package/src/router/index.ts +209 -0
- package/src/router/node.ts +141 -0
- package/src/router/path.ts +28 -0
- package/src/router/route.ts +34 -0
- package/src/slugify.ts +4 -0
- package/src/symbols.ts +8 -0
- package/src/types.ts +16 -28
- package/tsconfig.json +5 -19
- package/build/group.d.ts +0 -3
- package/build/group.js +0 -8
- package/build/listener.d.ts +0 -4
- package/build/listener.js +0 -13
- package/build/middleware/common/dispatch.d.ts +0 -3
- package/build/middleware/common/dispatch.js +0 -11
- package/build/middleware/common/index.d.ts +0 -29
- package/build/middleware/common/index.js +0 -3
- package/build/middleware/common/match.d.ts +0 -3
- package/build/middleware/common/match.js +0 -12
- package/build/redirect.d.ts +0 -2
- package/build/redirect.js +0 -10
- package/build/routes.d.ts +0 -20
- package/build/routes.js +0 -45
- package/build/url.d.ts +0 -30
- package/build/url.js +0 -22
- package/src/group.ts +0 -11
- package/src/listener.ts +0 -24
- package/src/middleware/common/dispatch.ts +0 -17
- package/src/middleware/common/index.ts +0 -5
- package/src/middleware/common/match.ts +0 -24
- package/src/middleware/factory.ts +0 -21
- package/src/redirect.ts +0 -16
- package/src/routes.ts +0 -68
- package/src/url.ts +0 -30
package/src/routes.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { Group, Responder, Routes, Route } from './types';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
let groups: Group[] = [],
|
|
5
|
-
routes: Record<Route['name'], Route> = {},
|
|
6
|
-
subdomains: Record<NonNullable<Route['subdomain']>, Record<NonNullable<Route['path']>, Route['name']>> = {};
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const add = ({ name, path, responder }: { name: string, path?: string, responder: Responder }) => {
|
|
10
|
-
let http = path !== undefined,
|
|
11
|
-
route: Route = {
|
|
12
|
-
middleware: [],
|
|
13
|
-
name: '',
|
|
14
|
-
responder
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
if (http) {
|
|
18
|
-
route.path = '';
|
|
19
|
-
route.subdomain = '';
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
for (let i = 0, n = groups.length; i < n; i++) {
|
|
23
|
-
let group = groups[i];
|
|
24
|
-
|
|
25
|
-
if (group.middleware.length) {
|
|
26
|
-
route.middleware.push(...group.middleware);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
route.name += group.name;
|
|
30
|
-
|
|
31
|
-
if (http) {
|
|
32
|
-
route.path += group.path;
|
|
33
|
-
route.subdomain = group.subdomain + route.subdomain;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
routes[ route.name += name ] = route;
|
|
38
|
-
|
|
39
|
-
if (http) {
|
|
40
|
-
route.path = `${route.path}${path}`;
|
|
41
|
-
|
|
42
|
-
if (route.path[0] !== '/') {
|
|
43
|
-
route.path = `/${route.path}`;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (!route.subdomain || route.subdomain === 'www') {
|
|
47
|
-
route.subdomain = '';
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (!subdomains[route.subdomain]) {
|
|
51
|
-
subdomains[route.subdomain] = {};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
subdomains[route.subdomain][route.path] = route.name;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return route;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const group = (group: any, fn: (routes: Routes) => void) => {
|
|
61
|
-
groups.push(group);
|
|
62
|
-
fn({ add, group, routes, subdomains });
|
|
63
|
-
groups.pop();
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
export default { add, group, routes, subdomains };
|
|
68
|
-
export { add, group, routes, subdomains };
|
package/src/url.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
const parse = (url: string = window?.location?.href || '') => {
|
|
2
|
-
let { hash, host, hostname, href, origin, port, protocol } = new URL( url ),
|
|
3
|
-
parts = host.split('.'),
|
|
4
|
-
path = hash?.replace('#/', '/')?.split('?') || ['/', ''],
|
|
5
|
-
subdomain = '';
|
|
6
|
-
|
|
7
|
-
if (parts.length > 2) {
|
|
8
|
-
subdomain = parts[0];
|
|
9
|
-
|
|
10
|
-
if (['127', 'www'].includes(subdomain)) {
|
|
11
|
-
subdomain = '';
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return {
|
|
16
|
-
data: {} as Record<string, any>,
|
|
17
|
-
href: href,
|
|
18
|
-
hostname: hostname,
|
|
19
|
-
origin: origin,
|
|
20
|
-
path: path[0],
|
|
21
|
-
port: port,
|
|
22
|
-
protocol: protocol,
|
|
23
|
-
query: Object.fromEntries( (new URLSearchParams(path[1])).entries() ),
|
|
24
|
-
subdomain
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
export default { parse };
|
|
30
|
-
export { parse };
|