1# Empty Val Utils
2
3Handy utility functions to see if you have vals with no code lying around your account and to delete them (if you want to).
4
5## Usage
9const id = ({ userHandle, valName }) => `${userHandle}/${valName}`;
10
11export const reloadOnVals = async function(vals: { userHandle: string; valName: string }[], delay = 500) {
12 const initialVersions = Object.fromEntries(
13 await Promise.all(vals.map(async (val) => {
6import { html } from "https://esm.town/v/stevekrouse/html?v=5";
7
8export async function examplePost(req: Request) {
9 const { author, name } = extractValInfo(import.meta.url);
10
7};
8
9export function getSourceAST(source: string, parseOptions = {
10 syntax: "typescript",
11 tsx: true,
34}
35
36export function findASTNode(parent: Node | Node[], method: (node: Node) => Node, recursive = false) {
37 const nodes = parent instanceof Array
38 ? parent
54}
55
56export function findASTNodes<T>(parent: Node | Node[], method: (node: Node) => T | T[] | undefined, recursive = false) {
57 const nodes = parent instanceof Array
58 ? parent
78}
79
80export function findASTValueDefinition(ast: Node | Node[], name: string) {
81 let check = (node: Node) => {
82 if (node.type === "ExportDeclaration") {
86 return findASTValueDefinition(node.declarations, name);
87 }
88 if (node.type === "FunctionDeclaration" && node.identifier?.value === name) {
89 return node;
90 }
106}
107
108export function findIndexLineNumber(source: string, index: number) {
109 return (source.slice(0, index).match(/\n/g)?.length ?? 0) + 1;
110}
111
112export function findSpanLocation(source: string, ast: Node, span: Span) {
113 const offset = offsetState.map.get(ast) ?? 1;
114 return {
2import { render } from "npm:preact-render-to-string";
3
4export default async function(req: Request) {
5 return new Response(
6 render(
2import { ValRef } from "https://esm.town/v/andreterron/ValRef?v=1";
3
4export function ribbonElement({ val, style }: { val?: ValRef; style?: string } = {}) {
5 const valRef = val?.handle && val?.name ? val : rootValRef();
6
9} from "https://esm.town/v/postpostscript/meta";
10
11export async function moduleHighlightValueLink(module: string, name: string, log = false) {
12 const { source, node: ast } = await getSourceAST(await moduleSource(module));
13 const node = findASTValueDefinition(ast, name);
37}
38
39export function getRedirectUrl(module: string, name: string, embed = false) {
40 const qs = new URLSearchParams();
41 if (embed) {
47}
48
49export default async function(req: Request) {
50 const qs = queryString.parse(req.url.split("?")[1] || "");
51
4import { html } from "https://esm.town/v/stevekrouse/html?v=5";
5
6async function handler(req: Request) {
7 const { data: vals } = await api(`/v1/search/vals?query=${encodeURIComponent("- [ ]")}`);
8
7};
8
9export default function Counter(props: Props) {
10 const [count, setCount] = useState(props.initialCount || 0);
11
1import { render } from "https://esm.town/v/ije/md?v=2";
2
3export default async function(req: Request): Promise<Response> {
4 const markdown = `
5 # Title
A helper function to build a file's email
Simple functional CSS library for Val Town
LangChain (https://langchain.com) Ambassador, KubeSphere (https://kubesphere.io) Ambassador, CNCF OpenFunction (https://openfunction.dev) TOC Member.
import { OpenAI } from "https://esm.town/v/std/openai";
export default async function(req: Request): Promise<Response> {
if (req.method === "OPTIONS") {
return new Response(null, {
headers: {
"Access-Control-Allow-Origin": "*",