@spirobel/mininext 0.4.2 → 0.4.3
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/mininext.d.ts +2 -2
- package/dist/mininext.js +2 -2
- package/dist/url.d.ts +14 -1
- package/dist/url.js +16 -1
- package/package.json +1 -1
package/dist/mininext.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="bun-types" />
|
|
2
2
|
/// <reference types="bun-types" />
|
|
3
|
-
import { url, Mini, type HtmlHandler } from "./url";
|
|
3
|
+
import { url, Mini, has, type HtmlHandler } from "./url";
|
|
4
4
|
import { isError, HtmlString, BasedHtml, head, commonHead, cssReset, basedHtml as html } from "./html";
|
|
5
5
|
import type { Server, WebSocketHandler } from "bun";
|
|
6
6
|
declare global {
|
|
@@ -12,4 +12,4 @@ declare function makeEntrypoint(): Promise<{
|
|
|
12
12
|
fetch: (req: Request, server: Server) => Promise<Response>;
|
|
13
13
|
websocket: WebSocketHandler;
|
|
14
14
|
}>;
|
|
15
|
-
export { html, url, head, build, makeEntrypoint, isError, BasedHtml, HtmlString, type HtmlHandler, Mini, standardDevReloader, commonHead, cssReset, };
|
|
15
|
+
export { has, html, url, head, build, makeEntrypoint, isError, BasedHtml, HtmlString, type HtmlHandler, Mini, standardDevReloader, commonHead, cssReset, };
|
package/dist/mininext.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { url, Mini } from "./url";
|
|
1
|
+
import { url, Mini, has } from "./url";
|
|
2
2
|
import { isError, HtmlString, BasedHtml, head, commonHead, cssReset, basedHtml as html, } from "./html";
|
|
3
3
|
import { watch } from "fs/promises";
|
|
4
4
|
import * as path from "path";
|
|
@@ -182,4 +182,4 @@ async function makeEntrypoint() {
|
|
|
182
182
|
}
|
|
183
183
|
return module.default();
|
|
184
184
|
}
|
|
185
|
-
export { html, url, head, build, makeEntrypoint, isError, BasedHtml, HtmlString, Mini, standardDevReloader, commonHead, cssReset, };
|
|
185
|
+
export { has, html, url, head, build, makeEntrypoint, isError, BasedHtml, HtmlString, Mini, standardDevReloader, commonHead, cssReset, };
|
package/dist/url.d.ts
CHANGED
|
@@ -3,11 +3,24 @@
|
|
|
3
3
|
import type { Server, WebSocketHandler } from "bun";
|
|
4
4
|
import { html, json, dangerjson, HtmlString } from "./html";
|
|
5
5
|
import type { BasedHtml, DangerJsonInHtml, JsonString, JsonStringValues } from "./html";
|
|
6
|
+
/**
|
|
7
|
+
* A helper function that helps narrow unknown objects
|
|
8
|
+
* @param object - the object of type unknown that is to be narrowed
|
|
9
|
+
* @param key - the key that may or may not exist in object
|
|
10
|
+
* @returns true if the key is present and false if not
|
|
11
|
+
* @example
|
|
12
|
+
* ``` js
|
|
13
|
+
* has(this.form.formJson, "formName") &&
|
|
14
|
+
* this.form.formJson.formName === this.form.formName
|
|
15
|
+
* ```
|
|
16
|
+
* https://stackoverflow.com/questions/70028907/narrowing-an-object-of-type-unknown
|
|
17
|
+
*/
|
|
18
|
+
export declare function has<T, K extends string>(object: T, key: K): object is T & object & Record<K, unknown>;
|
|
6
19
|
export type Form = {
|
|
7
20
|
post: boolean;
|
|
8
21
|
urlencoded: boolean;
|
|
9
22
|
multipart: boolean;
|
|
10
|
-
formJson?:
|
|
23
|
+
formJson?: unknown;
|
|
11
24
|
formData?: FormData;
|
|
12
25
|
formName?: string;
|
|
13
26
|
hiddenField?: HtmlString;
|
package/dist/url.js
CHANGED
|
@@ -1,4 +1,19 @@
|
|
|
1
1
|
import { htmlResponder, html, json, dangerjson, HtmlString } from "./html";
|
|
2
|
+
/**
|
|
3
|
+
* A helper function that helps narrow unknown objects
|
|
4
|
+
* @param object - the object of type unknown that is to be narrowed
|
|
5
|
+
* @param key - the key that may or may not exist in object
|
|
6
|
+
* @returns true if the key is present and false if not
|
|
7
|
+
* @example
|
|
8
|
+
* ``` js
|
|
9
|
+
* has(this.form.formJson, "formName") &&
|
|
10
|
+
* this.form.formJson.formName === this.form.formName
|
|
11
|
+
* ```
|
|
12
|
+
* https://stackoverflow.com/questions/70028907/narrowing-an-object-of-type-unknown
|
|
13
|
+
*/
|
|
14
|
+
export function has(object, key) {
|
|
15
|
+
return typeof object === "object" && object !== null && key in object;
|
|
16
|
+
}
|
|
2
17
|
/**
|
|
3
18
|
* Mini - the data object can be filled with url.data
|
|
4
19
|
* @example
|
|
@@ -37,7 +52,7 @@ export class Mini {
|
|
|
37
52
|
this.form.formData.get("formName") === this.form.formName) {
|
|
38
53
|
return cb();
|
|
39
54
|
}
|
|
40
|
-
else if (this.form.formJson &&
|
|
55
|
+
else if (has(this.form.formJson, "formName") &&
|
|
41
56
|
this.form.formJson.formName === this.form.formName) {
|
|
42
57
|
return cb();
|
|
43
58
|
}
|