Likes
63
valTownUser
@iamseeley
Script
π€ valTownUser The valTownUser object provides a convenient interface to interact with Val Town's API and access user-specific information and functionalities. User Information getUserInfo() Fetches and caches the user's information. Use case: Retrieving all user details at once. import { valTownUser } from "https://esm.town/v/iamseeley/valTownUser";
export const getUserInfo = () => valTownUser.getUserInfo();
// Example usage:
const userInfo = await getUserInfo();
console.log('User Information:', userInfo);
// You can also destructure specific properties you need:
const { username, id, email, tier } = await getUserInfo();
console.log(`Username: ${username}`);
console.log(`User ID: ${id}`);
console.log(`Email: ${email}`);
console.log(`Account Tier: ${tier}`); getUsername() Retrieves the user's username. Use case: Displaying the current user's name in a val. import { valTownUser } from "https://esm.town/v/iamseeley/valTownUser";
export const getUsername = () => valTownUser.getUsername();
// Example usage:
const username = await getUsername();
console.log(`Current user: ${username}`); getId() Retrieves the user's ID. Use case: Using the user ID for database queries or API calls. import { valTownUser } from "https://esm.town/v/iamseeley/valTownUser";
export const getId = () => valTownUser.getId();
// Example usage:
const userId = await getId();
console.log(`User ID: ${userId}`); getBio() Retrieves the user's biography. Use case: Displaying the user's bio on a profile page. import { valTownUser } from "https://esm.town/v/iamseeley/valTownUser";
export const getBio = () => valTownUser.getBio();
// Example usage:
const bio = await getBio();
console.log(`User bio: ${bio || 'Not set'}`); getProfileImageUrl() Retrieves the URL of the user's profile image. Use case: Showing the user's avatar in a val. import { valTownUser } from "https://esm.town/v/iamseeley/valTownUser";
export const getProfileImageUrl = () => valTownUser.getProfileImageUrl();
// Example usage:
const profileImageUrl = await getProfileImageUrl();
console.log(`Profile image URL: ${profileImageUrl || 'Not set'}`); getEmail() Retrieves the user's email address. Use case: Sending notifications or verifications. import { valTownUser } from "https://esm.town/v/iamseeley/valTownUser";
export const getEmail = () => valTownUser.getEmail();
// Example usage:
const email = await getEmail();
console.log(`User email: ${email}`); getTier() Retrieves the user's account tier. Use case: Implementing tier-specific features. import { valTownUser } from "https://esm.town/v/iamseeley/valTownUser";
export const getTier = () => valTownUser.getTier();
// Example usage:
const tier = await getTier();
console.log(`User tier: ${tier}`); URL Generation getEndpointUrl(valName) Generates the endpoint URL for a specified val. Use case: Creating links to val endpoints in your application. import { valTownUser } from "https://esm.town/v/iamseeley/valTownUser";
export const getEndpointUrl = (valName: string) => valTownUser.getEndpointUrl(valName);
// Example usage:
const endpointUrl = await getEndpointUrl('mySitesServer');
console.log(`Endpoint URL: ${endpointUrl}`); getValUrl(valName) Generates the Val Town URL for a specified val. Use case: Creating links to val pages in Val Town. import { valTownUser } from "https://esm.town/v/iamseeley/valTownUser";
export const getValUrl = (valName: string) => valTownUser.getValUrl(valName);
// Example usage:
const valUrl = await getValUrl('myVal');
console.log(`Val URL: ${valUrl}`); User Activity getLikedVals(options) Retrieves the vals liked by the user. Use case: Displaying a list of the user's favorite vals. import { valTownUser } from "https://esm.town/v/iamseeley/valTownUser";
export const getLikedVals = (options = {}) => valTownUser.getLikedVals(options);
// Example usage:
const likedVals = await getLikedVals({ limit: 5 });
console.log('Liked vals:', likedVals.data); getComments(options) Retrieves comments related to the user. Use case: Showing a user's comment history. import { valTownUser } from "https://esm.town/v/iamseeley/valTownUser";
export const getComments = (options = {}) => valTownUser.getComments(options);
// Example usage:
const comments = await getComments({ limit: 10, relationship: 'given' });
console.log('User comments:', comments.data); getReferences(options) Retrieves references to the user's vals. Use case: Tracking how often a user's vals are used by others. import { valTownUser } from "https://esm.town/v/iamseeley/valTownUser";
export const getReferences = (options = {}) => valTownUser.getReferences(options);
// Example usage:
const references = await getReferences({ limit: 5 });
console.log('Val references:', references.data); Blob Management listBlobs(prefix) Lists the user's blobs. Use case: Displaying a file manager for the user's stored data. import { valTownUser } from "https://esm.town/v/iamseeley/valTownUser";
export const listBlobs = (prefix?: string) => valTownUser.listBlobs(prefix);
// Example usage:
const blobs = await listBlobs();
console.log('User blobs:', blobs); storeBlob(key, data) Stores a new blob or updates an existing one. Use case: Uploading user files or storing large datasets. import { valTownUser } from "https://esm.town/v/iamseeley/valTownUser";
export const storeBlob = (key: string, data: any) => valTownUser.storeBlob(key, data);
// Example usage:
await storeBlob('myFile.txt', 'Hello, World!');
console.log('Blob stored successfully'); getBlob(key) Retrieves a specific blob. Use case: Downloading a user's stored file. import { valTownUser } from "https://esm.town/v/iamseeley/valTownUser";
export const getBlob = async (key: string) => {
const blobData = await valTownUser.getBlob(key);
return new TextDecoder().decode(new Uint8Array(blobData));
};
// Example usage:
const blobContent = await getBlob('myFile.txt');
console.log('Blob content:', blobContent); deleteBlob(key) Deletes a specific blob. Use case: Removing old or unnecessary files. import { valTownUser } from "https://esm.town/v/iamseeley/valTownUser";
export const deleteBlob = (key: string) => valTownUser.deleteBlob(key);
// Example usage:
await deleteBlob('myFile.txt');
console.log('Blob deleted successfully'); Val Management listVals(options) Lists the user's vals. Use case: Displaying a dashboard of the user's created vals. import { valTownUser } from "https://esm.town/v/iamseeley/valTownUser";
export const listVals = (options = {}) => valTownUser.listVals(options);
// Example usage:
const userVals = await listVals({ limit: 5 });
console.log('User vals:', userVals.data); createVal(valInfo) Creates a new val. Use case: Programmatically creating vals based on user input. import { valTownUser } from "https://esm.town/v/iamseeley/valTownUser";
export const createVal = (valInfo: any) => valTownUser.createVal(valInfo);
// Example usage:
const newVal = await createVal({ name: 'myNewVal', code: 'console.log("Hello, World!");' });
console.log('Created val:', newVal); updateVal(valId, updates) Updates an existing val. Use case: Implementing an "edit val" feature in your application. deleteVal(valId) Deletes a specific val. Use case: Allowing users to remove their vals through your interface. SQLite Database Operations executeSqlite(statement) Executes a SQLite statement. Use case: Running custom queries on the user's database. listTables() Lists all tables in the user's SQLite database. Use case: Displaying the structure of a user's database. getTableSchema(tableName) Retrieves the schema of a specific table. Use case: Showing the structure of a particular table. getTableContent(tableName, limit) Retrieves the content of a specific table. Use case: Displaying the data stored in a user's table.
neverthrow
@pomdtr
Script
Usage import { Failure, Success } from "https://esm.town/v/pomdtr/neverthrow?v=5";
const demoFunction = () => {
const result = Math.random();
if (result > 0.5) {
return Failure(
"Math. random produced too high a number",
);
}
return Success(result);
};
const res = demoFunction();
if (res.ok) {
console.log(res.value);
} else {
console.error(res.error);
}
bedtimeStoryMaker
@dthyresson
HTTP (deprecated)
Bedtime Story Maker Inspired from a RedwoodJS demo I mde last year, this adds generative art powered by Fal to the bedtime story maker. Start writing a story by picking a style (spooky, colofrol, adventurous an animal (penguin, mouse, unicorn, whale ...) a color for the animal and activity (befriends aliens, goes to the doctor, rides a rollercoaster, bakes a cake for friends) It uses OpenAI to write a children's bedtime story title summary story for a "fantastical story about a green whale who rides the bus" or the "spooky story about the tomato fox who explores a cave". Then using the summary, OpenAI geenrates another prompt to describe the instructions to geneate a childrens story book image. That's sent to Fal to generate an image. Stories get saved to bedtime_stories in SQLite for viewing, searching and maybe sharing. You then get a bedtime story to enjoy!
vimarkdown
@jxnblk
HTTP
vimarkdown Try it now A VIM-mode markdown editor built with Val Town . Features Write markdown in the browser with VIM keybindings Minimal, focused UI Saves to localStorage Multiple color modes Markdown -> HTML preview (β+P) NOT mobile-friendly Fork this editor on Val Town to make it your own Inspired by iA Writer
Made by Jxnblk TODO [ ] Add syntax highlighting to frontmatter block [ ] Support multiple fonts
tomatoMinnow
@nicoalbanese
HTTP (deprecated)
Vercel AI SDK with Val Town! Use the Vercel AI SDK in your Vals. Note : you must add your OpenAI key to your Val Town Env variables under OPENAI_API_KEY . If you would like to specify a different name for your API Key, you can create a custom OpenAI provider with the createOpenAI function. Prefer another AI provider? Use any supported provider by changing just two lines of code!
SidebarToArchive
@yawnxyz
HTTP (deprecated)
Sidebar.io Archiver Sidebar's been one of my biggest design resources for the last decade. Since sidebar.io's break announcement this morning (https://sidebar.io/break/) I've set out to mess around with using Val.town to archive sidebar.
The Google Sheet can be found here: https://docs.google.com/spreadsheets/d/1RghvMfPTR5xvHMAk1pKYuH2pFYYKOJ6bH0LLkHNZiuc/edit?usp=sharing Initially I was just piping data to Google Sheets but that's slow, wasteful and kind of dumb... instead I just wrapped Hono around the code to provide a download the CSV to browser.
importValInChromeConsole
@stevekrouse
Script
Import a val script in the chrome console Say you're developing a chrome extension or some other little script and you're iterating in the chrome console. Over time you may write larger pieces of code that you want to save as a group. Or maybe you want to use TypeScript, which isn't supported in browsers natively. Val Town can provide a decent workflow here. Save your code in a Script val Ensure the val is Public or Unlisted In the chrome console, import your val's module url. For example, for this val it would look like this: let {test} = await import(`https://esm.town/v/stevekrouse/importValInChromeConsole?${Math.random()}`) I added a random number to the end of the string to prevent your browser from caching the import. So now you can save in Val Town and then re-run your import line in the Chrome console and the script will re-run in the Chrome console.
caviar
@jxnblk
Script
Simple CSS Vars library import { caviar } from "https://esm.town/v/jxnblk/caviar";
const vars = caviar({
dark: {
text: "#000",
bg: "#fff",
},
light: {
text: "#fff",
bg: "#000",
},
}); // JSX example
<div style={vars.style.light}>
<h1
style={{
color: vars.text,
backgroundColor: vars.bg,
}}>
Hello
</h1>
</div> Can also be used for non-dynamic CSS vars import { caviar } from "https://esm.town/v/jxnblk/caviar";
const vars = caviar({
blue: "#0cf",
});
// <div style={vars.style} /> Tests: https://www.val.town/v/jxnblk/caviar_tests TODO [ ] Fallback for missing mode keys