Public
Script
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Readme

filterVals

This val exports a utility function that returns a list of all a user's val, filtered by a callback function.

Example

Get the names of all your private vals:

import { filterVals } from "https://esm.town/v/nbbaier/filterVals"; const id = <user_id> const vals = await filterVals(id, (v) => v.privacy === "private") const privateValNames = vals.map(v => v.name);
1
2
3
4
5
6
7
8
9
import { fetchPaginatedData } from "https://esm.town/v/nbbaier/fetchPaginatedData";
export async function filterVals(id: string, filter: (value: any, index: number, array: any[]) => unknown) {
const token = Deno.env.get("valtown");
const res = await fetchPaginatedData(`https://api.val.town/v1/users/${id}/vals`, {
headers: { Authorization: `Bearer ${token}` },
});
return res.filter(filter);
}
March 3, 2024