![Avatar](https://secure.gravatar.com/avatar/109fa713caf4e083c57622b7c6dad365.jpg?s=200&d=identicon)
neverstew
Twice called wise. 🧐
Building a better world at https://equalcare.coop.
Joined January 12, 2023
Public vals
122
![neverstew avatar](https://secure.gravatar.com/avatar/109fa713caf4e083c57622b7c6dad365.jpg?s=200&d=identicon)
readableHtml
@neverstew
Script
Get a readable representation of an HTML page console.log(await readableHtml("<html><body><h1>Main title</h1><p>Some content</p></body></html>"));
// Main titleSome content
console.log(await readableHtml(new URL("https://en.wikipedia.org/wiki/Special:Random")));
// From Wikipedia, the free encyclopedia
// George Miles ChilcottUnited States Senatorfrom ColoradoIn officeApril 17, 1882 – January 27,...
![neverstew avatar](https://secure.gravatar.com/avatar/109fa713caf4e083c57622b7c6dad365.jpg?s=200&d=identicon)
cors_example
@neverstew
HTTP
CORS issues are the bane of frontend engineers. In Val Town, if you don't customize any CORS headers, we add these defaults: Access-Control-Allow-Origin: "*"
Access-Control-Allow-Methods: "GET,HEAD,PUT,PATCH,POST,DELETE" You can override them if you wish to disallow CORS. Check out @neverstew/setCorsHeaders for the easiest way to do this in your code. This val is a client-side-rendered React app that makes requests to @stevekrouse/cors_example_backend. The backend is in a different val because CORS applies to requests on different domains. The backend has examples of the default permissive CORS behavior and disabled CORS.
![neverstew avatar](https://secure.gravatar.com/avatar/109fa713caf4e083c57622b7c6dad365.jpg?s=200&d=identicon)
blobDirList
@neverstew
Script
List things in a blob directory Blobs can be organised using "directories" e.g. /animals
all-animals.txt
/dogs
sausage.txt
/cats
tom.txt is really only three files: /animals/all-animals.txt , /animals/dogs/sausage.txt and /animals/cats/tom.txt because directories don't really exist, we're just making longer filenames. When you want to list things only "in a directory" and none of the child "directories", you can use this val. import { blobDirList } from "https://esm.town/v/neverstew/blobDirList";
console.log(await blobDirList("/animals"));
// returns only "/animals/all-animals.txt"