12 Commits

Author SHA1 Message Date
ee87a6269e 1.0.11 2021-09-08 22:25:52 +02:00
2d76e799a4 fix(core): update 2021-09-08 22:25:52 +02:00
f24520ea89 1.0.10 2021-09-08 22:11:48 +02:00
5072728118 fix(core): update 2021-09-08 22:11:48 +02:00
bb4df0c47f 1.0.9 2021-09-08 21:49:40 +02:00
101533cddd fix(core): update 2021-09-08 21:49:40 +02:00
3b31f88b0c 1.0.8 2021-09-08 21:46:21 +02:00
daeaac2367 fix(core): update 2021-09-08 21:46:21 +02:00
9b9675bd96 1.0.7 2020-11-30 10:40:40 +00:00
e7d7865750 fix(core): update 2020-11-30 10:40:39 +00:00
b7feb5098b 1.0.6 2020-11-30 10:14:22 +00:00
76fcf14831 fix(core): update 2020-11-30 10:14:22 +00:00
6 changed files with 18594 additions and 3771 deletions

View File

@ -19,23 +19,35 @@ mirror:
stage: security stage: security
script: script:
- npmci git mirror - npmci git mirror
only:
- tags
tags: tags:
- lossless - lossless
- docker - docker
- notpriv - notpriv
audit: auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --production --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=prod --production
tags:
- docker
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security stage: security
script: script:
- npmci npm prepare - npmci npm prepare
- npmci command npm install --ignore-scripts - npmci command npm install --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org - npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high - npmci command npm audit --audit-level=high --only=dev
tags: tags:
- lossless
- docker - docker
- notpriv allow_failure: true
# ==================== # ====================
# test stage # test stage
@ -50,9 +62,7 @@ testStable:
- npmci npm test - npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- lossless
- docker - docker
- priv
testBuild: testBuild:
stage: test stage: test
@ -63,9 +73,7 @@ testBuild:
- npmci command npm run build - npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/ coverage: /\d+.?\d+?\%\s*coverage/
tags: tags:
- lossless
- docker - docker
- notpriv
release: release:
stage: release stage: release
@ -85,6 +93,8 @@ release:
codequality: codequality:
stage: metadata stage: metadata
allow_failure: true allow_failure: true
only:
- tags
script: script:
- npmci command npm install -g tslint typescript - npmci command npm install -g tslint typescript
- npmci npm prepare - npmci npm prepare

View File

@ -15,7 +15,7 @@
"properties": { "properties": {
"projectType": { "projectType": {
"type": "string", "type": "string",
"enum": ["website", "element", "service", "npm"] "enum": ["website", "element", "service", "npm", "wcc"]
} }
} }
} }

22286
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartrouter", "name": "@pushrocks/smartrouter",
"version": "1.0.5", "version": "1.0.11",
"private": false, "private": false,
"description": "a router for routing on websites", "description": "a router for routing on websites",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
@ -13,16 +13,16 @@
"format": "(gitzone format)" "format": "(gitzone format)"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.0.22", "@gitzone/tsbuild": "^2.1.27",
"@gitzone/tsbundle": "^1.0.72", "@gitzone/tsbundle": "^1.0.87",
"@gitzone/tstest": "^1.0.43", "@gitzone/tstest": "^1.0.57",
"@pushrocks/tapbundle": "^3.2.9", "@pushrocks/tapbundle": "^3.2.14",
"@types/node": "^14.0.23", "@types/node": "^16.7.13",
"tslint": "^6.1.2", "tslint": "^6.1.3",
"tslint-config-prettier": "^1.15.0" "tslint-config-prettier": "^1.15.0"
}, },
"dependencies": { "dependencies": {
"path-to-regexp": "^6.1.0" "path-to-regexp": "^6.2.0"
}, },
"files": [ "files": [
"ts/**/*", "ts/**/*",

View File

@ -8,8 +8,8 @@ tap.test('first test', async () => {
expect(testrouter).to.be.instanceOf(smartrouter.SmartRouter); expect(testrouter).to.be.instanceOf(smartrouter.SmartRouter);
}); });
tap.test('should handle a route change', async (tools) => { tap.test('should handle a route change', async (toolsArg) => {
const done = tools.defer(); const done = toolsArg.defer();
testrouter.on('/myawesomeroute/:any', async (routeInfoArg) => { testrouter.on('/myawesomeroute/:any', async (routeInfoArg) => {
expect(routeInfoArg.params.any).to.equal('hello'); expect(routeInfoArg.params.any).to.equal('hello');
done.resolve(); done.resolve();
@ -18,8 +18,8 @@ tap.test('should handle a route change', async (tools) => {
await done.promise; await done.promise;
}); });
tap.test('should handle a route change', async (tools) => { tap.test('should handle a route change', async (toolsArg) => {
const done = tools.defer(); const done = toolsArg.defer();
testrouter.on('/myawesomeroute2/:wow', async (routeInfoArg) => { testrouter.on('/myawesomeroute2/:wow', async (routeInfoArg) => {
expect(routeInfoArg.params.wow).to.equal('hello2'); expect(routeInfoArg.params.wow).to.equal('hello2');
done.resolve(); done.resolve();
@ -29,4 +29,18 @@ tap.test('should handle a route change', async (tools) => {
expect(window.location.href).to.equal('http://localhost:3007/myawesomeroute2/hello2'); expect(window.location.href).to.equal('http://localhost:3007/myawesomeroute2/hello2');
}); });
tap.test('should find a query param', async (toolsArg) => {
const done = toolsArg.defer();
testrouter.on('/myawesomeroute2/:wow', async (routeInfoArg) => {
expect(routeInfoArg.params.wow).to.equal('hello2');
expect(routeInfoArg.queryParams.aparam).to.equal('Yes');
console.log('Here is what queryParams looks like');
console.log(JSON.stringify(routeInfoArg.queryParams));
done.resolve();
});
testrouter.pushUrl('/myawesomeroute2/hello2?aparam=Yes');
await done.promise;
expect(window.location.href).to.equal('http://localhost:3007/myawesomeroute2/hello2?aparam=Yes');
});
tap.start(); tap.start();

View File

@ -11,8 +11,9 @@ export interface IRouterOptions {
export type THandlerFunction = <T extends object>(routeArg: IRouteInfo) => Promise<any>; export type THandlerFunction = <T extends object>(routeArg: IRouteInfo) => Promise<any>;
export interface IRouteInfo { export interface IRouteInfo {
path: string; path: string;
index:number; index: number;
params: {[key: string]: string}; params: { [key: string]: string };
queryParams: { [key: string]: string };
} }
/** /**
@ -80,13 +81,19 @@ export class SmartRouter {
*/ */
async _handleRouteState() { async _handleRouteState() {
const currentLocation = window.location.pathname; const currentLocation = window.location.pathname;
const urlSearchParams = new URLSearchParams(window.location.search);
// lets find all wanted routes.
const wantedRoutes = this.routes.filter((routeArg) => { const wantedRoutes = this.routes.filter((routeArg) => {
return !!routeArg.matchFunction(currentLocation); return !!routeArg.matchFunction(currentLocation);
}); });
for (const wantedRoute of wantedRoutes) { for (const wantedRoute of wantedRoutes) {
const routeResult = wantedRoute.matchFunction(currentLocation); const routeResult = wantedRoute.matchFunction(currentLocation);
await wantedRoute.handler(routeResult.valueOf() as IRouteInfo); wantedRoute.handler({
...(routeResult.valueOf() as Object),
queryParams: Object.fromEntries((urlSearchParams as any).entries()), // TODO check wether entries is supported in typings
} as IRouteInfo); // not waiting here
} }
} }
} }