@spirobel/mininext 0.3.7 → 0.3.8

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/dist/url.d.ts CHANGED
@@ -73,7 +73,7 @@ interface LinkSettings {
73
73
  export declare class url {
74
74
  static websocket: WebSocketHandler | undefined;
75
75
  static server: Server;
76
- static direct_handlers_html: ReadonlyMap<string, HtmlHandler>;
76
+ static direct_handlers_html: Map<string, HtmlHandler>;
77
77
  private static frontends;
78
78
  private static svgs;
79
79
  static svg(path: string, options?: ResponseInit): string | undefined;
@@ -138,14 +138,18 @@ export declare class url {
138
138
  * use this to define your routes.
139
139
  * @example
140
140
  * ``` js
141
+ * //define all routes at once
141
142
  * url.set([
142
143
  * ["/", (mini) => mini.html`<h1>Hello world</h1>`],
143
144
  * ["/apple", (mini) => mini.html`<h1>Hello apple</h1>`],
144
145
  * ["/banana", (mini) => mini.html`<h1>Hello banana</h1>`],
145
146
  * ]);
147
+ * //define or overwrite just one route
148
+ * url.set("/apple", (mini)=>mini.html`<h1> Hello pineapple </h1>`)
146
149
  * ```
147
150
  */
148
151
  static set<K extends string>(entries: [K, HtmlHandler][]): void;
152
+ static set(urlPath: string, handler: HtmlHandler): void;
149
153
  /**
150
154
  * wrap your handlers in this if you mutate something to prevent CSRF issues.
151
155
  * @param handler - normal html handler with mini as the argument
package/dist/url.js CHANGED
@@ -172,19 +172,17 @@ export class url {
172
172
  },
173
173
  };
174
174
  }
175
- /**
176
- * use this to define your routes.
177
- * @example
178
- * ``` js
179
- * url.set([
180
- * ["/", (mini) => mini.html`<h1>Hello world</h1>`],
181
- * ["/apple", (mini) => mini.html`<h1>Hello apple</h1>`],
182
- * ["/banana", (mini) => mini.html`<h1>Hello banana</h1>`],
183
- * ]);
184
- * ```
185
- */
186
- static set(entries) {
187
- url.direct_handlers_html = new Map(entries);
175
+ static set(entries, handler) {
176
+ if (typeof entries === "string" && handler) {
177
+ if (url.direct_handlers_html) {
178
+ url.direct_handlers_html.set(entries, handler);
179
+ }
180
+ else {
181
+ url.direct_handlers_html = new Map([[entries, handler]]);
182
+ }
183
+ }
184
+ if (typeof entries !== "string")
185
+ url.direct_handlers_html = new Map(entries);
188
186
  }
189
187
  /**
190
188
  * wrap your handlers in this if you mutate something to prevent CSRF issues.
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "clean":"rm -rf ./dist"
12
12
  },
13
13
  "files": ["dist"],
14
- "version": "0.3.7",
14
+ "version": "0.3.8",
15
15
  "devDependencies": {
16
16
  "@types/bun": "latest"
17
17
  },