8 Commits

Author SHA1 Message Date
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
50e14811d4 1.0.5 2020-11-30 01:38:22 +00:00
f7e5af4113 fix(core): update 2020-11-30 01:38:21 +00:00
6 changed files with 18968 additions and 2859 deletions

View File

@ -19,23 +19,35 @@ mirror:
stage: security
script:
- npmci git mirror
only:
- tags
tags:
- lossless
- docker
- 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
stage: security
script:
- npmci npm prepare
- npmci command npm install --ignore-scripts
- 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:
- lossless
- docker
- notpriv
allow_failure: true
# ====================
# test stage
@ -50,9 +62,7 @@ testStable:
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- lossless
- docker
- priv
testBuild:
stage: test
@ -63,9 +73,7 @@ testBuild:
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- lossless
- docker
- notpriv
release:
stage: release
@ -85,6 +93,8 @@ release:
codequality:
stage: metadata
allow_failure: true
only:
- tags
script:
- npmci command npm install -g tslint typescript
- npmci npm prepare

View File

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

21744
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -8,8 +8,8 @@ tap.test('first test', async () => {
expect(testrouter).to.be.instanceOf(smartrouter.SmartRouter);
});
tap.test('should handle a route change', async (tools) => {
const done = tools.defer();
tap.test('should handle a route change', async (toolsArg) => {
const done = toolsArg.defer();
testrouter.on('/myawesomeroute/:any', async (routeInfoArg) => {
expect(routeInfoArg.params.any).to.equal('hello');
done.resolve();
@ -18,8 +18,8 @@ tap.test('should handle a route change', async (tools) => {
await done.promise;
});
tap.test('should handle a route change', async (tools) => {
const done = tools.defer();
tap.test('should handle a route change', async (toolsArg) => {
const done = toolsArg.defer();
testrouter.on('/myawesomeroute2/:wow', async (routeInfoArg) => {
expect(routeInfoArg.params.wow).to.equal('hello2');
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');
});
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();

View File

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