@dreamkit/app 0.0.1
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/LICENSE +21 -0
- package/README.md +22 -0
- package/lib/$route.d.ts +3 -0
- package/lib/$route.d.ts.map +1 -0
- package/lib/$route.js +2 -0
- package/lib/App.d.ts +34 -0
- package/lib/App.d.ts.map +1 -0
- package/lib/App.js +46 -0
- package/lib/builders/RouteBuilder.d.ts +53 -0
- package/lib/builders/RouteBuilder.d.ts.map +1 -0
- package/lib/builders/RouteBuilder.js +54 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +5 -0
- package/lib/routePath.d.ts +6 -0
- package/lib/routePath.d.ts.map +1 -0
- package/lib/routePath.js +8 -0
- package/lib/utils/kind.d.ts +5 -0
- package/lib/utils/kind.d.ts.map +1 -0
- package/lib/utils/kind.js +3 -0
- package/lib/utils/routing.d.ts +8 -0
- package/lib/utils/routing.d.ts.map +1 -0
- package/lib/utils/routing.js +21 -0
- package/package.json +39 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Juanra GM <juanrgm724@gmail.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# @dreamkit/app
|
|
2
|
+
|
|
3
|
+
> Set of utils to create applications.
|
|
4
|
+
|
|
5
|
+
[![workflow-badge]](https://github.com/swordev/dreamkit/actions/workflows/ci.yaml) [![npm-badge]](https://www.npmjs.com/package/@dreamkit/app)
|
|
6
|
+
|
|
7
|
+
[workflow-badge]: https://img.shields.io/github/actions/workflow/status/swordev/dreamkit/ci.yaml?branch=main
|
|
8
|
+
[npm-badge]: https://img.shields.io/npm/v/@dreamkit/app?label=@dreamkit/app
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
npm install @dreamkit/app
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Documentation
|
|
17
|
+
|
|
18
|
+
https://dreamkit.dev
|
|
19
|
+
|
|
20
|
+
## License
|
|
21
|
+
|
|
22
|
+
Distributed under the MIT License. See LICENSE for more information.
|
package/lib/$route.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"$route.d.ts","sourceRoot":"","sources":["../src/$route.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE1D,eAAO,MAAM,MAAM,kBAAqC,CAAC"}
|
package/lib/$route.js
ADDED
package/lib/App.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Route } from "./builders/RouteBuilder.js";
|
|
2
|
+
export declare class App {
|
|
3
|
+
readonly objects: Map<string, any>;
|
|
4
|
+
readonly routes: Set<Route>;
|
|
5
|
+
protected listeners: {
|
|
6
|
+
add: Set<(data: {
|
|
7
|
+
id: string;
|
|
8
|
+
value: unknown;
|
|
9
|
+
}) => any>;
|
|
10
|
+
remove: Set<(data: {
|
|
11
|
+
id: string;
|
|
12
|
+
value: unknown;
|
|
13
|
+
}) => any>;
|
|
14
|
+
change: Set<(data: {
|
|
15
|
+
id: string;
|
|
16
|
+
value: unknown;
|
|
17
|
+
action: "add" | "remove";
|
|
18
|
+
}) => any>;
|
|
19
|
+
};
|
|
20
|
+
constructor();
|
|
21
|
+
on(event: "add" | "remove", cb: (data: {
|
|
22
|
+
id: string;
|
|
23
|
+
value: unknown;
|
|
24
|
+
}) => any): this;
|
|
25
|
+
on(event: "change", cb: (data: {
|
|
26
|
+
id: string;
|
|
27
|
+
value: unknown;
|
|
28
|
+
action: "add" | "remove";
|
|
29
|
+
}) => any): this;
|
|
30
|
+
off(event: "add" | "remove" | "change", cb: any): this;
|
|
31
|
+
remove(ids: string[]): Promise<void>;
|
|
32
|
+
add(objects: Record<string, any>): Promise<void>;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=App.d.ts.map
|
package/lib/App.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"App.d.ts","sourceRoot":"","sources":["../src/App.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AAGnD,qBAAa,GAAG;IACd,QAAQ,CAAC,OAAO,mBAA0B;IAC1C,QAAQ,CAAC,MAAM,aAAoB;IACnC,SAAS,CAAC,SAAS;wBACG;YAAE,EAAE,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,OAAO,CAAA;SAAE,KAAK,GAAG;2BACnC;YAAE,EAAE,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,OAAO,CAAA;SAAE,KAAK,GAAG;2BAEpD;YAAE,EAAE,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,OAAO,CAAC;YAAC,MAAM,EAAE,KAAK,GAAG,QAAQ,CAAA;SAAE,KAAK,GAAG;MAEzE;;IAGF,EAAE,CACA,KAAK,EAAE,KAAK,GAAG,QAAQ,EACvB,EAAE,EAAE,CAAC,IAAI,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,KAAK,GAAG,GAChD,IAAI;IACP,EAAE,CACA,KAAK,EAAE,QAAQ,EACf,EAAE,EAAE,CAAC,IAAI,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,KAAK,GAAG,QAAQ,CAAA;KAAE,KAAK,GAAG,GAC1E,IAAI;IAKP,GAAG,CAAC,KAAK,EAAE,KAAK,GAAG,QAAQ,GAAG,QAAQ,EAAE,EAAE,EAAE,GAAG,GAAG,IAAI;IAIhD,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE;IAapB,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;CAWvC"}
|
package/lib/App.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { isRoute } from "./utils/kind.js";
|
|
2
|
+
export class App {
|
|
3
|
+
objects = new Map();
|
|
4
|
+
routes = new Set();
|
|
5
|
+
listeners = {
|
|
6
|
+
add: new Set(),
|
|
7
|
+
remove: new Set(),
|
|
8
|
+
change: new Set(),
|
|
9
|
+
};
|
|
10
|
+
constructor() { }
|
|
11
|
+
on(event, cb) {
|
|
12
|
+
this.listeners[event].add(cb);
|
|
13
|
+
return this;
|
|
14
|
+
}
|
|
15
|
+
off(event, cb) {
|
|
16
|
+
this.listeners[event].delete(cb);
|
|
17
|
+
return this;
|
|
18
|
+
}
|
|
19
|
+
async remove(ids) {
|
|
20
|
+
for (const id of ids) {
|
|
21
|
+
const value = this.objects.get(id);
|
|
22
|
+
if (!value)
|
|
23
|
+
throw new Error(`Object not found: ${id}`);
|
|
24
|
+
if (isRoute(value)) {
|
|
25
|
+
this.routes.delete(value);
|
|
26
|
+
}
|
|
27
|
+
for (const cb of this.listeners.remove)
|
|
28
|
+
await cb({ id, value });
|
|
29
|
+
for (const cb of this.listeners.change)
|
|
30
|
+
await cb({ id, value, action: "remove" });
|
|
31
|
+
this.objects.delete(id);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async add(objects) {
|
|
35
|
+
for (const [id, value] of Object.entries(objects)) {
|
|
36
|
+
if (isRoute(value)) {
|
|
37
|
+
this.routes.add(value);
|
|
38
|
+
}
|
|
39
|
+
this.objects.set(id, value);
|
|
40
|
+
for (const cb of this.listeners.add)
|
|
41
|
+
await cb({ id, value });
|
|
42
|
+
for (const cb of this.listeners.change)
|
|
43
|
+
await cb({ id, value, action: "add" });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { InferType, MinimalObjectType, ObjectType, ObjectTypeProps } from "@dreamkit/schema";
|
|
2
|
+
import type { Merge } from "@dreamkit/utils/ts.js";
|
|
3
|
+
export type RoutePathParams<P extends string | number | symbol> = {
|
|
4
|
+
[K in P]: K extends string ? `:${K}` : never;
|
|
5
|
+
};
|
|
6
|
+
export type RouteParams = MinimalObjectType | undefined;
|
|
7
|
+
export type RouteData<TParams extends RouteParams = RouteParams> = {
|
|
8
|
+
params?: TParams;
|
|
9
|
+
};
|
|
10
|
+
export type RouteOptions<T extends RouteData = RouteData> = T & {
|
|
11
|
+
title?: string;
|
|
12
|
+
path?: string;
|
|
13
|
+
onParamsError?: {
|
|
14
|
+
value: InferRouteParams<T>;
|
|
15
|
+
} | {
|
|
16
|
+
redirect: string;
|
|
17
|
+
};
|
|
18
|
+
component?: (props: any) => any;
|
|
19
|
+
filePath?: string;
|
|
20
|
+
createComponent?: (options: RouteOptions, component: (props?: any) => any) => any;
|
|
21
|
+
};
|
|
22
|
+
export type InferRouteParams<T extends RouteData> = [undefined] extends [
|
|
23
|
+
T["params"]
|
|
24
|
+
] ? undefined : InferType<T["params"] & {}>;
|
|
25
|
+
export type RouteProps<T extends RouteData = RouteData> = {
|
|
26
|
+
setParams: [undefined] extends [T["params"]] ? never : (params: InferRouteParams<T>) => void;
|
|
27
|
+
params: InferRouteParams<T>;
|
|
28
|
+
};
|
|
29
|
+
export type Route<T extends RouteData = RouteData> = ((props: any) => any) & {
|
|
30
|
+
$options: RouteOptions<T>;
|
|
31
|
+
};
|
|
32
|
+
export type MergeFuncData<D1 extends RouteData, D2 extends Partial<RouteData>> = Merge<RouteData, D1, D2>;
|
|
33
|
+
export declare class RouteBuilder<T extends RouteData = RouteData> {
|
|
34
|
+
readonly data: T;
|
|
35
|
+
readonly options: RouteOptions<T>;
|
|
36
|
+
constructor(options: RouteOptions<T>);
|
|
37
|
+
protected clone(options?: Partial<RouteOptions>): this;
|
|
38
|
+
title(value: string | undefined): this;
|
|
39
|
+
params<TParams extends RouteParams>(type: TParams): RouteBuilder<MergeFuncData<T, {
|
|
40
|
+
params: TParams;
|
|
41
|
+
}>>;
|
|
42
|
+
params<TProps extends ObjectTypeProps>(props: TProps): RouteBuilder<MergeFuncData<T, {
|
|
43
|
+
params: ObjectType<TProps>;
|
|
44
|
+
}>>;
|
|
45
|
+
onParamsError(input: {
|
|
46
|
+
value: InferRouteParams<T>;
|
|
47
|
+
} | {
|
|
48
|
+
redirect: string;
|
|
49
|
+
}): this;
|
|
50
|
+
path(value: string | ((params: RoutePathParams<keyof NonNullable<T["params"]>["props"]>) => string)): this;
|
|
51
|
+
create(component: (props: RouteProps<T>) => any): Route;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=RouteBuilder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RouteBuilder.d.ts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AAC,EAAE;QAAE,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,CAAA;KAAE,CAAC,CAAC;IAIjE,aAAa,CACX,KAAK,EAAE;QAAE,KAAK,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAA;KAAE,GAAG;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,GAC3D,IAAI;IAGP,IAAI,CACF,KAAK,EACD,MAAM,GACN,CAAC,CACC,MAAM,EAAE,eAAe,CAAC,MAAM,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,KAC7D,MAAM,CAAC,GACf,IAAI;IAQP,MAAM,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,GAAG,GAAG,KAAK;CAgBxD"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { kindRoute } from "../utils/kind.js";
|
|
2
|
+
import { kindOf } from "@dreamkit/kind";
|
|
3
|
+
import { ObjectType, s, } from "@dreamkit/schema";
|
|
4
|
+
export class RouteBuilder {
|
|
5
|
+
data;
|
|
6
|
+
options;
|
|
7
|
+
constructor(options) {
|
|
8
|
+
this.options = options;
|
|
9
|
+
this.data = {
|
|
10
|
+
params: options.params,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
clone(options = {}) {
|
|
14
|
+
const prev = this.options;
|
|
15
|
+
const next = options;
|
|
16
|
+
return new RouteBuilder({
|
|
17
|
+
...prev,
|
|
18
|
+
...next,
|
|
19
|
+
params: "params" in next
|
|
20
|
+
? next.params === undefined || kindOf(next.params, ObjectType)
|
|
21
|
+
? next.params
|
|
22
|
+
: s.object(next.params)
|
|
23
|
+
: prev.params,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
title(value) {
|
|
27
|
+
return this.clone({ title: value });
|
|
28
|
+
}
|
|
29
|
+
params(params) {
|
|
30
|
+
return this.clone({ params });
|
|
31
|
+
}
|
|
32
|
+
onParamsError(input) {
|
|
33
|
+
return this.clone({ onParamsError: input });
|
|
34
|
+
}
|
|
35
|
+
path(value) {
|
|
36
|
+
if (typeof value === "string")
|
|
37
|
+
return this.clone({ path: value });
|
|
38
|
+
const params = new Proxy({}, { get: (_, prop) => `:${prop}` });
|
|
39
|
+
return this.clone({ path: value(params) });
|
|
40
|
+
}
|
|
41
|
+
create(component) {
|
|
42
|
+
const self = this.clone({ component });
|
|
43
|
+
const result = function (props) {
|
|
44
|
+
if (!self.options.createComponent)
|
|
45
|
+
throw new Error("createComponent is not defined");
|
|
46
|
+
return self.options.createComponent(self.options, component);
|
|
47
|
+
};
|
|
48
|
+
kindRoute(result);
|
|
49
|
+
Object.assign(result, {
|
|
50
|
+
$options: self.options,
|
|
51
|
+
});
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { isRoute, isApp } from "./utils/kind.js";
|
|
2
|
+
export { App } from "./App.js";
|
|
3
|
+
export { $route } from "./$route.js";
|
|
4
|
+
export { RouteBuilder, type RouteOptions, type Route, type RouteData, type RouteProps, } from "./builders/RouteBuilder.js";
|
|
5
|
+
export { defineRoutePath, routePath } from "./routePath.js";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EACL,YAAY,EACZ,KAAK,YAAY,EACjB,KAAK,KAAK,EACV,KAAK,SAAS,EACd,KAAK,UAAU,GAChB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type RoutePathFunc<T> = {
|
|
2
|
+
<K extends keyof T>(path: K, ...data: T[K] extends never ? [] : [data: T[K]]): string;
|
|
3
|
+
};
|
|
4
|
+
export declare function defineRoutePath<T>(): RoutePathFunc<T>;
|
|
5
|
+
export declare const routePath: RoutePathFunc<unknown>;
|
|
6
|
+
//# sourceMappingURL=routePath.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routePath.d.ts","sourceRoot":"","sources":["../src/routePath.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI;IAC7B,CAAC,CAAC,SAAS,MAAM,CAAC,EAChB,IAAI,EAAE,CAAC,EACP,GAAG,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,KAAK,GAAG,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAC9C,MAAM,CAAC;CACX,CAAC;AAGF,wBAAgB,eAAe,CAAC,CAAC,KAAK,aAAa,CAAC,CAAC,CAAC,CAIrD;AAED,eAAO,MAAM,SAAS,wBAAoB,CAAC"}
|
package/lib/routePath.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { App } from "../App.js";
|
|
2
|
+
import type { Route } from "../builders/RouteBuilder.js";
|
|
3
|
+
export declare const kindApp: (input: object, name?: string) => void, isApp: (input: unknown) => input is App;
|
|
4
|
+
export declare const kindRoute: (input: object, name?: string) => void, isRoute: (input: unknown) => input is Route;
|
|
5
|
+
//# sourceMappingURL=kind.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kind.d.ts","sourceRoot":"","sources":["../../src/utils/kind.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAC;AAGzD,eAAO,MAAO,OAAO,0CAAE,KAAK,kCAAoC,CAAC;AACjE,eAAO,MAAO,SAAS,0CAAE,OAAO,oCAA4C,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function extractPathParams(path: string): {
|
|
2
|
+
spread: boolean;
|
|
3
|
+
name: string;
|
|
4
|
+
key: string;
|
|
5
|
+
}[];
|
|
6
|
+
export declare function createRouteUrl(path: string, params?: Record<string, any>, base?: string): URL;
|
|
7
|
+
export declare function createRouteHref(path: string, params?: Record<string, any>): string;
|
|
8
|
+
//# sourceMappingURL=routing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routing.d.ts","sourceRoot":"","sources":["../../src/utils/routing.ts"],"names":[],"mappings":"AAAA,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,GACX;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,EAAE,CAMlD;AAED,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,EAChC,IAAI,SAAoD,OAazD;AAED,wBAAgB,eAAe,CAC7B,IAAI,EAAE,MAAM,EACZ,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,UAIjC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export function extractPathParams(path) {
|
|
2
|
+
return [...path.matchAll(/([:\*])(\w+)/g)].map((match) => ({
|
|
3
|
+
key: match[0],
|
|
4
|
+
spread: match[1] === "*",
|
|
5
|
+
name: match[2],
|
|
6
|
+
}));
|
|
7
|
+
}
|
|
8
|
+
export function createRouteUrl(path, params = {}, base = globalThis.location?.origin ?? "http://localhost") {
|
|
9
|
+
const paramNames = extractPathParams(path);
|
|
10
|
+
for (const param of paramNames)
|
|
11
|
+
path = path.replaceAll(param.key, params[param.name]);
|
|
12
|
+
const url = new URL(path, base);
|
|
13
|
+
for (const name in params)
|
|
14
|
+
if (!paramNames.find((param) => param.name === name))
|
|
15
|
+
url.searchParams.set(name, params[name]);
|
|
16
|
+
return url;
|
|
17
|
+
}
|
|
18
|
+
export function createRouteHref(path, params = {}) {
|
|
19
|
+
const url = createRouteUrl(path, params);
|
|
20
|
+
return url.pathname + url.search;
|
|
21
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dreamkit/app",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Set of utils to create applications.",
|
|
5
|
+
"homepage": "https://dreamkit.dev",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/swordev/dreamkit/tree/main/packages/app"
|
|
9
|
+
},
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"author": "Juanra GM",
|
|
12
|
+
"contributors": [
|
|
13
|
+
{
|
|
14
|
+
"name": "Juanra GM",
|
|
15
|
+
"email": "juanrgm724@gmail.com",
|
|
16
|
+
"url": "https://github.com/juanrgm"
|
|
17
|
+
}
|
|
18
|
+
],
|
|
19
|
+
"sideEffects": false,
|
|
20
|
+
"type": "module",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": "./lib/index.js",
|
|
23
|
+
"./*": "./lib/*"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"lib"
|
|
27
|
+
],
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@dreamkit/kind": "0.0.1",
|
|
30
|
+
"@dreamkit/schema": "0.0.1",
|
|
31
|
+
"@dreamkit/utils": "0.0.1"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@dreamkit/tsconfig": "0.0.1"
|
|
35
|
+
},
|
|
36
|
+
"x-dreamkit": {
|
|
37
|
+
"profile": "lib"
|
|
38
|
+
}
|
|
39
|
+
}
|