This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Silence globalThis.console for selected messages by substrings | |
* | |
* @param substringsToSkip {string[]} - substrings to skip | |
* @returns {Proxy} - a proxied console object | |
*/ | |
export const proxyConsole = (...substringsToSkip: string[]) => { | |
return new Proxy(console, { | |
get(target, prop, _receiver) { | |
const method = target[prop as keyof typeof console]; // intercept method calls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const errors: Record<string, { status: number; message: string }> = { | |
BadRequest: { status: 400, message: "Bad Request" }, | |
Unauthorized: { status: 401, message: "Unauthorized" }, | |
PaymentRequired: { status: 402, message: "Payment Required" }, | |
Forbidden: { status: 403, message: "Forbidden" }, | |
NotFound: { status: 404, message: "Not Found" }, | |
MethodNotAllowed: { status: 405, message: "Method Not Allowed" }, | |
InternalServerError: { status: 500, message: "Internal Server Error" }, | |
NotImplemented: { status: 501, message: "Not Implemented" }, | |
BadGateway: { status: 502, message: "Bad Gateway" }, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// adapted from https://stackoverflow.com/a/74202858 | |
import type { ComponentChildren, JSX } from "preact"; | |
export type FormFetchProps = JSX.IntrinsicElements["form"] & { | |
id: string; | |
method: "get" | "post" | "put" | "patch" | "delete"; | |
action: string; | |
children?: ComponentChildren; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default () => { | |
const data = [...]; | |
return ( | |
<Plot.Figure | |
options={{ | |
x: { tickFormat: Plot.formatMonth(), ticks: 12 }, | |
marks: [ | |
Plot.barY(data, { x: "month", y: "amount", tip: true }), | |
Plot.ruleY([0]), | |
], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { setup } from "./shared.ts"; | |
export default function hydrate() { | |
setup(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const providerHandler = { | |
get: async(target, name) => { | |
console.log('load someting from remote...') | |
return new Promise( (res, rej) => { | |
setTimeout(() => res(42), 4200) | |
}) | |
}, | |
set: function (obj, prop, value) { | |
return new Promise((res, rej) => { | |
console.log('save someting remotely...') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Ultra lightweight Github REST Client */ | |
const token = 'github-token-here' | |
const githubClient = generateAPI('https://api.github.com', { | |
headers: { | |
'User-Agent': 'xyz', | |
'Authorization': `bearer ${token}` | |
} | |
}) | |
async function getRepo() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Using a JavaScript proxy for a super low code REST client */ | |
// via https://dev.to/dipsaus9/javascript-lets-create-aproxy-19hg | |
// also see https://towardsdatascience.com/why-to-use-javascript-proxy-5cdc69d943e3 | |
// also see https://github.com/fastify/manifetch | |
// also see https://github.com/flash-oss/allserver | |
// and https://gist.github.com/v1vendi/75d5e5dad7a2d1ef3fcb48234e4528cb | |
const createApi = (url) => { | |
return new Proxy({}, { | |
get(target, key) { |