@ribbon-studios/js-utils 2.0.0 → 2.1.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/README.md CHANGED
@@ -26,7 +26,7 @@ Collection of generic javascript utilities curated by the Ribbon Studios Team~
26
26
  - [`rfetch.put`](#rfetchput)
27
27
  - [`rfetch.post`](#rfetchpost)
28
28
  - [`rfetch.patch`](#rfetchpatch)
29
- - [`rfetch.remove`](#rfetchremove)
29
+ - [`rfetch.delete`](#rfetchdelete)
30
30
  - [`rfetch.interceptors`](#rfetchinterceptors)
31
31
  - [`rfetch.delimiters`](#rfetchdelimiters)
32
32
 
@@ -195,7 +195,7 @@ import { rfetch, type RibbonFetchError } from '@ribbon-studios/js-utils';
195
195
  await rfetch.patch<MyExpectedResponse>('https://ribbonstudios.com');
196
196
  ```
197
197
 
198
- ### `rfetch.remove`
198
+ ### `rfetch.delete`
199
199
 
200
200
  Shorthand for DELETE requests.
201
201
 
@@ -203,7 +203,7 @@ Shorthand for DELETE requests.
203
203
  import { rfetch, type RibbonFetchError } from '@ribbon-studios/js-utils';
204
204
 
205
205
  // Shorthand for DELETE requests.
206
- await rfetch.remove<MyExpectedResponse>('https://ribbonstudios.com');
206
+ await rfetch.delete<MyExpectedResponse>('https://ribbonstudios.com');
207
207
  ```
208
208
 
209
209
  ### `rfetch.interceptors`
package/dist/index.cjs CHANGED
@@ -104,6 +104,7 @@ async function rfetch(url, { params, body, ...options } = {}) {
104
104
  );
105
105
  const content = ((_b = (_a = response.headers.get("Content-Type")) == null ? void 0 : _a.toLowerCase()) == null ? void 0 : _b.includes("json")) ? await response.json() : await response.text();
106
106
  if (response.ok) {
107
+ if (response.status === 204) return void 0;
107
108
  return content;
108
109
  }
109
110
  return Promise.reject(
@@ -113,6 +114,12 @@ async function rfetch(url, { params, body, ...options } = {}) {
113
114
  })
114
115
  );
115
116
  }
117
+ rfetch.delete = (url, options) => {
118
+ return rfetch(url, {
119
+ ...options,
120
+ method: "DELETE"
121
+ });
122
+ };
116
123
  ((rfetch2) => {
117
124
  async function get(url, options) {
118
125
  return rfetch2(url, {
@@ -143,10 +150,7 @@ async function rfetch(url, { params, body, ...options } = {}) {
143
150
  }
144
151
  rfetch2.patch = patch;
145
152
  async function remove(url, options) {
146
- return rfetch2(url, {
147
- ...options,
148
- method: "DELETE"
149
- });
153
+ return rfetch2.delete(url, options);
150
154
  }
151
155
  rfetch2.remove = remove;
152
156
  async function delimiters(type) {
package/dist/index.js CHANGED
@@ -102,6 +102,7 @@ async function rfetch(url, { params, body, ...options } = {}) {
102
102
  );
103
103
  const content = ((_b = (_a = response.headers.get("Content-Type")) == null ? void 0 : _a.toLowerCase()) == null ? void 0 : _b.includes("json")) ? await response.json() : await response.text();
104
104
  if (response.ok) {
105
+ if (response.status === 204) return void 0;
105
106
  return content;
106
107
  }
107
108
  return Promise.reject(
@@ -111,6 +112,12 @@ async function rfetch(url, { params, body, ...options } = {}) {
111
112
  })
112
113
  );
113
114
  }
115
+ rfetch.delete = (url, options) => {
116
+ return rfetch(url, {
117
+ ...options,
118
+ method: "DELETE"
119
+ });
120
+ };
114
121
  ((rfetch2) => {
115
122
  async function get(url, options) {
116
123
  return rfetch2(url, {
@@ -141,10 +148,7 @@ async function rfetch(url, { params, body, ...options } = {}) {
141
148
  }
142
149
  rfetch2.patch = patch;
143
150
  async function remove(url, options) {
144
- return rfetch2(url, {
145
- ...options,
146
- method: "DELETE"
147
- });
151
+ return rfetch2.delete(url, options);
148
152
  }
149
153
  rfetch2.remove = remove;
150
154
  async function delimiters(type) {
package/dist/rfetch.d.ts CHANGED
@@ -27,6 +27,10 @@ export declare enum DelimiterType {
27
27
  * @returns The typed response or an error containing the `status` and the `content`
28
28
  */
29
29
  export declare function rfetch<T = any>(url: string | URL, { params, body, ...options }?: RibbonFetchOptions): Promise<T>;
30
+ export declare namespace rfetch {
31
+ var _a: <T>(url: string | URL, options?: RibbonFetchBodyOptions) => Promise<T>;
32
+ export { _a as delete };
33
+ }
30
34
  export declare namespace rfetch {
31
35
  /**
32
36
  * Shorthand method for a GET request
@@ -66,7 +70,7 @@ export declare namespace rfetch {
66
70
  * @param url The url you wish to fetch.
67
71
  * @param options The request options.
68
72
  * @returns The typed response or an error containing the `status` and the `content`
69
- * @note This is named `remove` purely because `delete` is a reserved key
73
+ * @deprecated in favor of {@link rfetch.delete}
70
74
  */
71
75
  function remove<T>(url: string | URL, options?: RibbonFetchBodyOptions): Promise<T>;
72
76
  function delimiters(type: DelimiterType): Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ribbon-studios/js-utils",
3
- "version": "2.0.0",
3
+ "version": "2.1.1",
4
4
  "description": "Collection of generic javascript utilities curated by the Rainbow Cafe~",
5
5
  "type": "module",
6
6
  "source": "src/*.ts",