Avatar

postpostscript

he/him
57 public vals
Joined February 22, 2024
postpostscript avatar
MyFooter
@postpostscript
HTTP
@postpostscript/MyFooter: my footer component which shares random vals I've liked!
postpostscript avatar
moduleHighlightValueLink
@postpostscript
HTTP
moduleHighlightValueLink: Link to a Val With a Value or Method's Code Highlighted Examples: import { moduleHighlightValueLink, getRedirectUrl } from "https://esm.town/v/postpostscript/moduleHighlightValueLink"; console.log(await moduleHighlightValueLink("@std/email", "email")) // https://val.town/v/std/email#L6-42 console.log(await moduleHighlightValueLink("@postpostscript/moduleHighlightValueLink", "moduleHighlightValueLink")) // https://val.town/v/postpostscript/moduleHighlightValueLink#L6-20 // get URL you can imbed in an iframe console.log(getRedirectUrl("@postpostscript/moduleHighlightValueLink", "getRedirectUrl", true)); // https://postpostscript-modulehighlightvaluelink.web.val.run/?embed=1&module=%40postpostscript%2FmoduleHighlightValueLink&name=getRedirectUrl Iframe example: import { htmlResponse } from "https://esm.town/v/postpostscript/html"; import { getRedirectUrl } from "https://esm.town/v/postpostscript/moduleHighlightValueLink"; export default async function(req: Request): Promise<Response> { return htmlResponse` <iframe src="${getRedirectUrl(import.meta.url, "default", true)}" width="100%" height="100%"> </iframe> `; }
postpostscript avatar
sqliteBuilderTyped
@postpostscript
Script
Example
postpostscript avatar
sqliteBlob
@postpostscript
Script
sqliteBlob: make sqlite queries against your blobs!* does not include blob values
postpostscript avatar
sqliteUniverse
@postpostscript
Script
sqliteUniverse: make queries against multiple vals or endpoints at the same time! Example: @postpostscript/sqliteUniverseExample Todo [ ] tests‼️ [ ] update to support following syntax: SELECT * FROM "@example/endpoint".someTable or SELECT * FROM "@example/endpoint:::someTable"
postpostscript avatar
sqliteUniverseExample
@postpostscript
Script
An interactive, runnable TypeScript val by postpostscript
postpostscript avatar
sqlitePublic
@postpostscript
HTTP
An interactive, runnable TypeScript val by postpostscript
postpostscript avatar
recommends
@postpostscript
Script
An interactive, runnable TypeScript val by postpostscript
postpostscript avatar
valTownLogo
@postpostscript
Script
// let me know if this is an issue :)
postpostscript avatar
htmlAsync
@postpostscript
Script
htmlAsync: async fork of @postpostscript/html supporting Promises as replacements Examples import { delay } from "https://deno.land/x/delay@v0.2.0/mod.ts"; import { html, htmlResponseAsync } from "https://esm.town/v/postpostscript/htmlAsync"; export default function(req: Request) { return htmlResponseAsync` ${(async () => { await delay(1000); return `<script>console.log("sanitized")</script>`; })()} ${(async () => { await delay(1000); return html`<script>console.log("unsanitized")</script>`; })()} `; } Tests: @postpostscript/htmlAsyncTest
postpostscript avatar
hash
@postpostscript
Script
An interactive, runnable TypeScript val by postpostscript
postpostscript avatar
sqliteBuilder
@postpostscript
Script
sqliteBuilder: Opinionated safe(r) query builder using tagged templates import { Statement } from "https://esm.town/v/postpostscript/sqliteBuilder"; const unsafeId = "1234 or TRUE" console.log(Statement` SELECT * FROM table WHERE id = ${unsafeId} ${Statement`AND otherCondition`} `) // StatementInstance { // sql: "\nSELECT *\nFROM table\nWHERE id = ?\nAND otherCondition\n", // args: [ "1234 or TRUE" ], // log: false // } const results = await Statement`SELECT ...`.execute() // [ { key: "value", anotherKey: "anotherValue" }, ... ] Or you can pass it directly to @std/sqlite.execute : import { sqlite } from "https://esm.town/v/std/sqlite" await sqlite.execute(Statement`Select ...`) You can combine multiple statements using Statement.prototype.combineWith : Statement`...`.combineWith(Statement`...`, " AND ") [ Statement`fieldA`, Statement`fieldB`, Statement`fieldC`, ].reduce((a, b) => a.combineWith(b, ", "))
postpostscript avatar
html
@postpostscript
Script
html: create sanitized HTML using tagged templates Examples import { html } from "https://esm.town/v/postpostscript/html" const unsafeInput = "<script>alert(1)</script>" console.log(html`Value: ${unsafeInput}`) // Value: &lt;script&gt;alert(1)&lt;/script&gt; These can be combined -- HTML marked as safe (instance is RawHTML ) will be directly inserted: const scripts = html`<script>alert(1)</script>` console.log(html`<head> ${scripts} </head>`.toString()) // <head> // <script>alert(1)</script> // </head> To easily create HTTP Response outputs like @stevekrouse/html, use the htmlResponse utility: import { html, htmlResponse } from "https://esm.town/v/postpostscript/html"; export default function(req: Request) { return htmlResponse` Request URL: ${decodeURIComponent(req.url)} `; } Tests: @postpostscript/htmlTest
postpostscript avatar
fetchWorker
@postpostscript
Script
fetchWorker: communicate with a worker over a fetch -like interface! Example: import { fetchWorker } from "https://esm.town/v/postpostscript/fetchWorker"; using worker = await fetchWorker({ url: "https://esm.town/v/postpostscript/fetchWorkerExample", handler: "handler", }); const res = await worker.fetch("/", { method: "POST", body: JSON.stringify({ test: 1, }), headers: { "Content-Type": "application/json", }, }); console.log(await res.json()); // { // method: "POST", // url: "https://7ae81ab0-04cf-485a-ae09-054c4d3be6b3.val.town/", // text: { test: 1 }, // headers: { "content-type": "application/json" } // } Full Example Options: url ( string , required): URL that the worker will fetch the handler from handler ( string , defaults to default ): name of export that will execute the request
postpostscript avatar
lock
@postpostscript
Script
lock: distributed lock Forked from @stevekrouse/dlock ! 🙏 Example: import { acquireLock } from "https://esm.town/v/postpostscript/lock"; using exampleLock = await acquireLock(); // lock will be released when it goes out of context Full Example Options: using exampleLock = await acquireLock({ id: "lockExample", retries: 0, ttl: 5, // seconds retryTimeout: 1000, // ms });
postpostscript avatar
disposable
@postpostscript
Script
disposable: wrapper to make an object disposable with the using keyword using feature explanation in TypeScript 5.2 docs Example: import { disposable } from "https://esm.town/v/postpostscript/disposable"; using state = disposable( { x: 1, y: 2, }, (value) => console.log("state disposed", value), ); // state disposed { x: 1, y: 2, [Symbol(Symbol.dispose)]: [Function (anonymous)] } or, to use a proxy instead of modifying the original object: using state = disposable( { x: 1, y: 2, }, (value) => console.log("proxyState disposed", value), true, ); // proxyState disposed { x: 1, y: 2 } Full Example