Air quality API examples & templates
Use these vals as a playground to view and fork Air quality API examples and templates on Val Town. Run any example below or find templates that can be used as a pre-built solution.
iamseeley
savePDF
🗃️ save your html as a pdf using html2pdf // Adjust the options
html2pdf(element, {
margin: 0.2,
filename: 'resume.pdf',
image: { type: 'jpeg', quality: 0.98 },
html2canvas: { scale: 2 },
jsPDF: { unit: 'in', format: 'letter', orientation: 'portrait' }
}) usage <!-- Add the button to your html -->
<body>
<button id="saveAsPDFButton">Save as PDF</button>
<!-- Import the module -->
<script type="module" src="https://esm.town/v/iamseeley/savePDF"></script>
</body>
Script
devonzuegel
subscribe_to_a_substack
// I was able to get this script to work from my browser console, but
Script

neverstew
superchargedQueryParams
⚡ Supercharge your query params Tired of the old x=y query param limitations?
Ever wished you could say x>y or x!=y as well? Now you can! Parse query params with superchargedQueryParams and you get an array of operations for each parameter instead: import { superchargeQueryParams } from "https://esm.town/v/neverstew/superchargeQueryParams";
console.log(superchargeQueryParams(new URL("https://example.com?a=b&c>d&e!=f&e>=g")))
// {"a":[{"eq":"b"}],"c":[{"gt":"d"}],"e":[{"ne":"f"},{"gte":"g"}]}
Script
drew_kuhn
inventiveVioletDinosaur
With our data designed, let’s build the email! Val Town makes this super easy since it provides a robust email package. The package exports a function by the same name (email) which consumes an object. When called with properly formatted parameters, an email will be sent to the address associated with your Val Town account. “Good” emails need some kind of hook to draw the reader’s attention. What better hook than our joke’s setup? Add an email() function call to your Val which sends an email with the setup as its subject and the punchline as its body text. import { email } from "https://esm.town/v/std/email?v=9"; // Fetches a random joke.
function fetchRandomJoke() {
const SAMPLE_JOKE = {
"setup": "What do you call a group of disorganized cats?",
"punchline": "A cat-tastrophe.",
};
return SAMPLE_JOKE;
} const randomJoke = fetchRandomJoke();
const setup = randomJoke.setup;
const punchline = randomJoke.punchline; // Sends an email with the joke.
export const emailRandomJoke = email({
text: punchline,
subject: setup,
});
Notice that this data is being passed in as key-value pairs since it is inside of an object. There is only one parameter (that object) passed into the function. Save and evaluate your val by clicking the “Run” button at the top right.
Script