Avatar

@neverstew

8 likes93 public vals
Joined January 12, 2023
Twice called wise. 🧐 Building a better world at https://equalcare.coop.

This Val URL

Returns the URL of the val that calls this function.

See https://www.val.town/v/neverstew.thisValUrlExample

Readme
1
2
3
4
let thisValUrl = () => {
let { userHandle, valName } = @stevekrouse.parentReference();
return `https://val.town/v/${userHandle}.${valName}`;
};
0
4

This val allows you to send me an email at a certain datetime. Fun!

Readme
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
let scheduleEmail = async (req: express.Request, res: express.Response) => {
const z = await import("npm:zod");
const params = z.object({
sendAt: z.string().datetime(),
content: z.string(),
});
const sendAt = req.query.sendAt;
const content = req.query.content;
const parsedParams = params.safeParse({ sendAt, content });
if (parsedParams.success) {
await @me.emailServiceCreate(parsedParams.data);
res.send(`Scheduled for ${sendAt}`);
}
else {
res.send(JSON.stringify(parsedParams.error.format()));
}
};
0
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const renderFormAndSaveData = async (req: Request) => {
// A visit from a web browser? Serve a HTML page with a form
if (req.method === "GET") {
return new Response(
`
<!DOCTYPE html>
<html>
<head>
<title>Email Form</title>
</head>
<body>
<!-- Change the action here to THIS val's Express endpoint! -->
<form action="https://neverstew-renderFormAndSaveData.web.val.run" method="post">
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<br>
<input type="submit" value="Submit">
</form>
</body>
</html>
`,
{ headers: { "Content-Type": "text/html" } },
);
}
// Otherwise, someone has submitted a form so let's handle that
if (@me.submittedEmailAddresses === undefined) {
@me.submittedEmailAddresses = [];
}
const formData = await req.formData();
const emailAddress = formData.get("email");
if (@me.submittedEmailAddresses.includes(emailAddress)) {
return new Response("you're already signed up!");
}
console.email(`${emailAddress} just signed up!`, "new sign up");
@me.submittedEmailAddresses.push(emailAddress);
return new Response("thanks! you're signed up!");
};
0
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
const saveFormData = async (req: Request) => {
// Create somewhere to store data if it doesn't already exist
if (@me.submittedEmailAddresses === undefined) {
@me.submittedEmailAddresses = [];
}
// Pick out the form data
const formData = await req.formData();
const emailAddress = formData.get("email");
if (@me.submittedEmailAddresses.includes(emailAddress)) {
return new Response("you're already signed up!");
}
console.email(`${emailAddress} just signed up!`, "new sign up");
// Store form data
@me.submittedEmailAddresses.push(emailAddress);
return new Response("thanks! you're signed up!");
};
0
0
1
2
3
4
5
6
let manchesterBerylStationsGeojson = @neverstew
.geojsonFeatureCollection(
@neverstew.manchesterBerylStations.map(
@neverstew.toGeojsonPoint,
),
);
0
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**
* This val embeds itself in the web page created by hitting it's Web Endpoint!
*/
let embedSelf = async (request: Request): Promise<Response> => {
return new Response(
`
<style>
:root { background: "white"; font-family: sans-serif; }
</style>
<h1>My cool new val</h1>
<iframe
id="val_embedded"
title="Embedded Val Example"
width="100%"
height="500"
src="https://www.val.town/embed/neverstew.embedSelf"
/>
`,
{ headers: { "Content-Type": "text/html" } },
);
};
0
0
1
const embedded = "Hello, from Val Town!";
0
0
1
2
3
4
5
6
const runPostExample = @neverstew.run({
username: "neverstew",
valName: "uppercase",
// pass each argument the function accepts as an item in this array
data: ["hello"],
});
0
0
1
const uppercase = (s: string) => s.toUpperCase();
0
0
1
2
3
4
const runGetExample = @neverstew.run({
username: "neverstew",
valName: "publicKey",
});
0
0