Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
a3b34ef03f | |||
f755d8f5b8 | |||
35c471eef4 | |||
fe9fdb9384 |
@ -6,9 +6,10 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<script type="module">
|
<script type="module">
|
||||||
import {formatDate} from './dist/index.mjs';
|
import {PathEvent} from './dist/index.mjs';
|
||||||
|
|
||||||
console.log(formatDate('D MMM, YYYY'));
|
console.log(PathEvent.filter(['payments/ztimson:cr', 'logs/momentum:c', 'data/Testing:r'], 'data'));
|
||||||
|
console.log(PathEvent.filter(['data/Submissions/Test:r'], 'data/Submissions/Test/test.html'));
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ztimson/utils",
|
"name": "@ztimson/utils",
|
||||||
"version": "0.23.8",
|
"version": "0.23.12",
|
||||||
"description": "Utility library",
|
"description": "Utility library",
|
||||||
"author": "Zak Timson",
|
"author": "Zak Timson",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
* @return {"white" | "black"} Color with the most contrast
|
* @return {"white" | "black"} Color with the most contrast
|
||||||
*/
|
*/
|
||||||
export function blackOrWhite(background: string): 'white' | 'black' {
|
export function blackOrWhite(background: string): 'white' | 'black' {
|
||||||
const exploded = background.match(background.length >= 6 ? /\w\w/g : /\w/g);
|
const exploded = background?.match(background.length >= 6 ? /\w\w/g : /\w/g);
|
||||||
if(!exploded) return 'black';
|
if(!exploded) return 'black';
|
||||||
const [r, g, b] = exploded.map(hex => parseInt(hex, 16));
|
const [r, g, b] = exploded.map(hex => parseInt(hex, 16));
|
||||||
const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
|
const luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
|
||||||
|
29
src/http.ts
29
src/http.ts
@ -22,6 +22,22 @@ export type HttpDefaults = {
|
|||||||
url?: string;
|
url?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class HttpResponse<T = any> extends Response {
|
||||||
|
data?: T
|
||||||
|
ok!: boolean;
|
||||||
|
redirected!: boolean;
|
||||||
|
type!: ResponseType;
|
||||||
|
url!: string;
|
||||||
|
|
||||||
|
constructor(resp: Response, stream: ReadableStream) {
|
||||||
|
super(stream, {headers: resp.headers, status: resp.status, statusText: resp.statusText});
|
||||||
|
this.ok = resp.ok;
|
||||||
|
this.redirected = resp.redirected;
|
||||||
|
this.type = resp.type;
|
||||||
|
this.url = resp.url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export class Http {
|
export class Http {
|
||||||
private static interceptors: {[key: string]: HttpInterceptor} = {};
|
private static interceptors: {[key: string]: HttpInterceptor} = {};
|
||||||
|
|
||||||
@ -101,18 +117,17 @@ export class Http {
|
|||||||
push();
|
push();
|
||||||
}).catch((error: any) => controller.error(error));
|
}).catch((error: any) => controller.error(error));
|
||||||
}
|
}
|
||||||
|
|
||||||
push();
|
push();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
resp.data = new Response(stream);
|
resp = new HttpResponse<T>(resp, stream);
|
||||||
if(opts.decode == null || opts.decode) {
|
if(opts.decode !== false) {
|
||||||
const content = resp.headers.get('Content-Type')?.toLowerCase();
|
const content = resp.headers.get('Content-Type')?.toLowerCase();
|
||||||
if(content?.includes('form')) resp.data = <T>await resp.data.formData();
|
if(content?.includes('form')) resp.data = <T>await resp.formData();
|
||||||
else if(content?.includes('json')) resp.data = <T>await resp.data.json();
|
else if(content?.includes('json')) resp.data = <T>await resp.json();
|
||||||
else if(content?.includes('text')) resp.data = <T>await resp.data.text();
|
else if(content?.includes('text')) resp.data = <T>await resp.text();
|
||||||
else if(content?.includes('application')) resp.data = <T>await resp.data.blob();
|
else if(content?.includes('application')) resp.data = <T>await resp.blob();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(resp.ok) res(resp);
|
if(resp.ok) res(resp);
|
||||||
|
@ -142,8 +142,9 @@ export class PathEvent {
|
|||||||
const parsedFind = makeArray(filter).map(pe => new PathEvent(pe));
|
const parsedFind = makeArray(filter).map(pe => new PathEvent(pe));
|
||||||
return parsedTarget.filter(t => {
|
return parsedTarget.filter(t => {
|
||||||
if(!t.fullPath && t.all) return true;
|
if(!t.fullPath && t.all) return true;
|
||||||
return !!parsedFind.find(f => f.fullPath.startsWith(t.fullPath)
|
return !!parsedFind.find(f =>
|
||||||
&& (f.all || t.all || t.methods.intersection(f.methods).length));
|
(t.fullPath.startsWith(f.fullPath) || f.fullPath.startsWith(t.fullPath)) &&
|
||||||
|
(f.all || t.all || t.methods.intersection(f.methods).length));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user