@torthu/jacketui-bring 0.1.0 → 0.2.0

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.
@@ -0,0 +1,13 @@
1
+ import { BringInitDecorator } from "../types/BringDecorator";
2
+ /** headers(Record<string, string> | Headers): BringInitDecorator
3
+ *
4
+ * Sets multiple headers on the request
5
+ * If a header already exists, it will be overwritten.
6
+ * If a header does not exist, it will be appended.
7
+ *
8
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Headers
9
+ *
10
+ * @param headers A record of headers to set or a Headers object.
11
+ * @returns BringDecorator
12
+ */
13
+ export declare const headers: (headers: Record<string, string> | Headers) => BringInitDecorator;
@@ -0,0 +1,29 @@
1
+ /** headers(Record<string, string> | Headers): BringInitDecorator
2
+ *
3
+ * Sets multiple headers on the request
4
+ * If a header already exists, it will be overwritten.
5
+ * If a header does not exist, it will be appended.
6
+ *
7
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Headers
8
+ *
9
+ * @param headers A record of headers to set or a Headers object.
10
+ * @returns BringDecorator
11
+ */
12
+ export const headers = (headers) => {
13
+ return (init) => {
14
+ init.headers ??= new Headers();
15
+ if (init.headers instanceof Headers) {
16
+ for (const [key, val] of Object.entries(headers)) {
17
+ !init.headers.has(key)
18
+ ? init.headers.append(key, val)
19
+ : init.headers.set(key, val);
20
+ }
21
+ }
22
+ else {
23
+ for (const [key, val] of Object.entries(headers)) {
24
+ init.headers[key] = val;
25
+ }
26
+ }
27
+ return init;
28
+ };
29
+ };
@@ -2,6 +2,7 @@ export * from "./cache";
2
2
  export * from "./cors";
3
3
  export * from "./credentials";
4
4
  export * from "./header";
5
+ export * from "./headers";
5
6
  export * from "./integrity";
6
7
  export * from "./keepalive";
7
8
  export * from "./method";
@@ -12,6 +13,7 @@ export * from "./retry";
12
13
  export * from "./body";
13
14
  export * from "./jsonBody";
14
15
  export * from "./priority";
16
+ export * from "./url";
15
17
  export * from "./backoff";
16
18
  export * from "./jitter";
17
19
  export * from "./timeout";
@@ -2,6 +2,7 @@ export * from "./cache";
2
2
  export * from "./cors";
3
3
  export * from "./credentials";
4
4
  export * from "./header";
5
+ export * from "./headers";
5
6
  export * from "./integrity";
6
7
  export * from "./keepalive";
7
8
  export * from "./method";
@@ -12,6 +13,7 @@ export * from "./retry";
12
13
  export * from "./body";
13
14
  export * from "./jsonBody";
14
15
  export * from "./priority";
16
+ export * from "./url";
15
17
  export * from "./backoff";
16
18
  export * from "./jitter";
17
19
  export * from "./timeout";
@@ -1,10 +1,9 @@
1
1
  import { BringInitDecorator } from "../types/BringDecorator";
2
- import { BringInit } from "../types/BringInit";
3
- /** jsonBody(body: BringInit["body"]): BringInitDecorator
2
+ /** jsonBody(body: any): BringInitDecorator
4
3
  *
5
4
  * Sets the body of the request to a JSON string.
6
5
  *
7
6
  * @param body Any JSON serializable value
8
7
  * @returns BringInitDecorator
9
8
  */
10
- export declare const jsonBody: (body: BringInit["body"]) => BringInitDecorator;
9
+ export declare const jsonBody: (body: any) => BringInitDecorator;
@@ -1,4 +1,4 @@
1
- /** jsonBody(body: BringInit["body"]): BringInitDecorator
1
+ /** jsonBody(body: any): BringInitDecorator
2
2
  *
3
3
  * Sets the body of the request to a JSON string.
4
4
  *
@@ -0,0 +1,12 @@
1
+ import { BringInitDecorator } from "../types/BringDecorator";
2
+ import { BringInit } from "../types/BringInit";
3
+ /** url(string | URL): BringInitDecorator
4
+ *
5
+ * Sets the URL of the request
6
+ *
7
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Request/url
8
+ *
9
+ * @param url - URL to request.
10
+ * @returns BringDecorator
11
+ */
12
+ export declare const url: (url: BringInit["url"]) => BringInitDecorator;
@@ -0,0 +1,13 @@
1
+ /** url(string | URL): BringInitDecorator
2
+ *
3
+ * Sets the URL of the request
4
+ *
5
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Request/url
6
+ *
7
+ * @param url - URL to request.
8
+ * @returns BringDecorator
9
+ */
10
+ export const url = (url) => (init) => ({
11
+ ...init,
12
+ url,
13
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@torthu/jacketui-bring",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Improved fetch API with retry, timeout, and more.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -0,0 +1,34 @@
1
+ import { BringInitDecorator } from "../types/BringDecorator";
2
+
3
+ /** headers(Record<string, string> | Headers): BringInitDecorator
4
+ *
5
+ * Sets multiple headers on the request
6
+ * If a header already exists, it will be overwritten.
7
+ * If a header does not exist, it will be appended.
8
+ *
9
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Headers
10
+ *
11
+ * @param headers A record of headers to set or a Headers object.
12
+ * @returns BringDecorator
13
+ */
14
+ export const headers = (
15
+ headers: Record<string, string> | Headers
16
+ ): BringInitDecorator => {
17
+ return (init) => {
18
+ init.headers ??= new Headers();
19
+
20
+ if (init.headers instanceof Headers) {
21
+ for (const [key, val] of Object.entries(headers)) {
22
+ !init.headers.has(key)
23
+ ? init.headers.append(key, val)
24
+ : init.headers.set(key, val);
25
+ }
26
+ } else {
27
+ for (const [key, val] of Object.entries(headers)) {
28
+ init.headers[key] = val;
29
+ }
30
+ }
31
+
32
+ return init;
33
+ };
34
+ };
@@ -2,6 +2,7 @@ export * from "./cache";
2
2
  export * from "./cors";
3
3
  export * from "./credentials";
4
4
  export * from "./header";
5
+ export * from "./headers";
5
6
  export * from "./integrity";
6
7
  export * from "./keepalive";
7
8
  export * from "./method";
@@ -12,6 +13,7 @@ export * from "./retry";
12
13
  export * from "./body";
13
14
  export * from "./jsonBody";
14
15
  export * from "./priority";
16
+ export * from "./url";
15
17
 
16
18
  export * from "./backoff";
17
19
  export * from "./jitter";
@@ -1,7 +1,6 @@
1
1
  import { BringInitDecorator } from "../types/BringDecorator";
2
- import { BringInit } from "../types/BringInit";
3
2
 
4
- /** jsonBody(body: BringInit["body"]): BringInitDecorator
3
+ /** jsonBody(body: any): BringInitDecorator
5
4
  *
6
5
  * Sets the body of the request to a JSON string.
7
6
  *
@@ -9,5 +8,5 @@ import { BringInit } from "../types/BringInit";
9
8
  * @returns BringInitDecorator
10
9
  */
11
10
  export const jsonBody =
12
- (body: BringInit["body"]): BringInitDecorator =>
11
+ (body: any): BringInitDecorator =>
13
12
  (init) => ({ ...init, body: JSON.stringify(body) });
@@ -0,0 +1,18 @@
1
+ import { BringInitDecorator } from "../types/BringDecorator";
2
+ import { BringInit } from "../types/BringInit";
3
+
4
+ /** url(string | URL): BringInitDecorator
5
+ *
6
+ * Sets the URL of the request
7
+ *
8
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/Request/url
9
+ *
10
+ * @param url - URL to request.
11
+ * @returns BringDecorator
12
+ */
13
+ export const url =
14
+ (url: BringInit["url"]): BringInitDecorator =>
15
+ (init) => ({
16
+ ...init,
17
+ url,
18
+ });