Compare commits
No commits in common. "develop" and "0.23.20" have entirely different histories.
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ztimson/utils",
|
"name": "@ztimson/utils",
|
||||||
"version": "0.23.22",
|
"version": "0.23.20",
|
||||||
"description": "Utility library",
|
"description": "Utility library",
|
||||||
"author": "Zak Timson",
|
"author": "Zak Timson",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
@ -14,9 +14,9 @@
|
|||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
"types": "./dist/index.d.ts",
|
|
||||||
"import": "./dist/index.mjs",
|
"import": "./dist/index.mjs",
|
||||||
"require": "./dist/index.cjs"
|
"require": "./dist/index.cjs",
|
||||||
|
"types": "./dist/index.d.ts"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@ -34,7 +34,7 @@
|
|||||||
"typedoc": "^0.26.7",
|
"typedoc": "^0.26.7",
|
||||||
"typescript": "^5.3.3",
|
"typescript": "^5.3.3",
|
||||||
"vite": "^5.0.12",
|
"vite": "^5.0.12",
|
||||||
"vite-plugin-dts": "^4.5.3"
|
"vite-plugin-dts": "^3.7.2"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"dist"
|
"dist"
|
||||||
|
13
src/http.ts
13
src/http.ts
@ -30,13 +30,7 @@ class HttpResponse<T = any> extends Response {
|
|||||||
url!: string;
|
url!: string;
|
||||||
|
|
||||||
constructor(resp: Response, stream: ReadableStream) {
|
constructor(resp: Response, stream: ReadableStream) {
|
||||||
const body = [204, 205, 304].includes(resp.status) ? null : stream;
|
super(stream, {headers: resp.headers, status: resp.status, statusText: resp.statusText});
|
||||||
super(body, {
|
|
||||||
headers: resp.headers,
|
|
||||||
status: resp.status,
|
|
||||||
statusText: resp.statusText,
|
|
||||||
});
|
|
||||||
|
|
||||||
this.ok = resp.ok;
|
this.ok = resp.ok;
|
||||||
this.redirected = resp.redirected;
|
this.redirected = resp.redirected;
|
||||||
this.type = resp.type;
|
this.type = resp.type;
|
||||||
@ -76,9 +70,8 @@ export class Http {
|
|||||||
|
|
||||||
request<T>(opts: HttpRequestOptions = {}): PromiseProgress<DecodedResponse<T>> {
|
request<T>(opts: HttpRequestOptions = {}): PromiseProgress<DecodedResponse<T>> {
|
||||||
if(!this.url && !opts.url) throw new Error('URL needs to be set');
|
if(!this.url && !opts.url) throw new Error('URL needs to be set');
|
||||||
let url = opts.url?.startsWith('http') ? opts.url : (this.url || '') + (opts.url || '');
|
let url = (opts.url?.startsWith('http') ? opts.url : (this.url || '') + (opts.url || '')).replace(/([^:]\/)\/+/g, '$1');
|
||||||
url = url.replaceAll(/([^:]\/)\/+/g, '$1');
|
if(opts.fragment) url.includes('#') ? url.replace(/#.*(\?|\n)/g, (match, arg1) => `#${opts.fragment}${arg1}`) : url += '#' + opts.fragment;
|
||||||
if(opts.fragment) url.includes('#') ? url.replace(/#.*(\?|\n)/g, (match, arg1) => `#${opts.fragment}${arg1}`) : `${url}#${opts.fragment}`;
|
|
||||||
if(opts.query) {
|
if(opts.query) {
|
||||||
const q = Array.isArray(opts.query) ? opts.query :
|
const q = Array.isArray(opts.query) ? opts.query :
|
||||||
Object.keys(opts.query).map(k => ({key: k, value: (<any>opts.query)[k]}))
|
Object.keys(opts.query).map(k => ({key: k, value: (<any>opts.query)[k]}))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user