energeticLimeStoatmain.tsx1 match
23// Fetches a random joke.
4async function fetchRandomJoke() {
5const response = await fetch(
6"https://official-joke-api.appspot.com/random_joke",
balancedYellowMousemain.tsx1 match
23// Fetches a random joke.
4function fetchRandomJoke() {
5const SAMPLE_JOKE = {
6"setup": "What do you call a group of disorganized cats?",
56// Fetches a random joke.
7function fetchRandomJoke() {
8const SAMPLE_JOKE = {
9"setup": "What do you call a group of disorganized cats?",
Joke_Generatormain.tsx1 match
1import { email } from "https://esm.town/v/std/email?v=9";
2// Fetches a random joke.
3async function fetchRandomJoke() {
4const response = await fetch(
5"https://official-joke-api.appspot.com/random_joke",
23// Fetches a random joke.
4async function fetchRandomJoke() {
5const response = await fetch(
6"https://official-joke-api.appspot.com/random_joke",
curiousMagentaFalconmain.tsx1 match
23// Fetches a random joke.
4function fetchRandomJoke() {
5const SAMPLE_JOKE = {
6"setup": "What do you call a group of disorganized cats?",
1011type DataFormat = 'object' | 'json' | 'yaml' | 'csv' | 'toml';
12type SelectorType = 'property' | 'index' | 'search' | 'dynamic' | 'append' | 'function';
1314interface Selector {
40selectors.push(this.parseAppend());
41} else if (part.includes('(')) {
42selectors.push(this.parseFunction(part));
43} else {
44// Handle top-level properties without a leading dot
112}
113114private parseFunction(part: string): Selector {
115const [funcName, argsString] = part.split('(');
116const args = argsString.slice(0, -1).split(',').map(arg => arg.trim());
117return { type: 'function', value: funcName, args };
118}
119128129130type FunctionHandler = (data: any, args: string[]) => any;
131132const functions: Record<string, FunctionHandler> = {
133length: (data) => Array.isArray(data) ? data.length : Object.keys(data).length,
134keys: (data) => Object.keys(data),
145146147function applyFunction(funcName: string, data: any, args: string[] = []): any {
148const func = functions[funcName];
149if (!func) {
150throw new Error(`Unknown function: ${funcName}`);
151}
152200201private async stringifyData(data: any, format: DataFormat): Promise<string> {
202// Function to remove undefined values
203const removeUndefined = (obj: any): any => {
204if (Array.isArray(obj)) {
273274275case 'function':
276// If the function is 'length' and current is an array, apply it directly
277if (selector.value === 'length' && Array.isArray(current)) {
278return current.length;
279}
280// Otherwise, apply the function normally
281current = applyFunction(selector.value as string, current, selector.args || []);
282break;
283336result.push(this.traverseSelectorsForPut({}, remainingSelectors, value));
337break;
338case 'function':
339throw new Error('Cannot put to a function selector');
340}
341383case 'append':
384return data;
385case 'function':
386throw new Error('Cannot delete from a function selector');
387}
388
23// Fetches a random joke.
4async function fetchRandomJoke() {
5const response = await fetch(
6"https://official-joke-api.appspot.com/random_joke",
1011type DataFormat = 'object' | 'json' | 'yaml' | 'csv' | 'toml';
12type SelectorType = 'property' | 'index' | 'search' | 'dynamic' | 'append' | 'function';
1314interface Selector {
40selectors.push(this.parseAppend());
41} else if (part.includes('(')) {
42selectors.push(this.parseFunction(part));
43} else {
44// Handle top-level properties without a leading dot
112}
113114private parseFunction(part: string): Selector {
115const [funcName, argsString] = part.split('(');
116const args = argsString.slice(0, -1).split(',').map(arg => arg.trim());
117return { type: 'function', value: funcName, args };
118}
119128129130type FunctionHandler = (data: any, args: string[]) => any;
131132const functions: Record<string, FunctionHandler> = {
133length: (data) => Array.isArray(data) ? data.length : Object.keys(data).length,
134keys: (data) => Object.keys(data),
145146147function applyFunction(funcName: string, data: any, args: string[] = []): any {
148const func = functions[funcName];
149if (!func) {
150throw new Error(`Unknown function: ${funcName}`);
151}
152200201private async stringifyData(data: any, format: DataFormat): Promise<string> {
202// Function to remove undefined values
203const removeUndefined = (obj: any): any => {
204if (Array.isArray(obj)) {
273274275case 'function':
276// If the function is 'length' and current is an array, apply it directly
277if (selector.value === 'length' && Array.isArray(current)) {
278return current.length;
279}
280// Otherwise, apply the function normally
281current = applyFunction(selector.value as string, current, selector.args || []);
282break;
283336result.push(this.traverseSelectorsForPut({}, remainingSelectors, value));
337break;
338case 'function':
339throw new Error('Cannot put to a function selector');
340}
341383case 'append':
384return data;
385case 'function':
386throw new Error('Cannot delete from a function selector');
387}
388
9- **Multi-format Support**: Works with JSON, YAML, CSV, and TOML.
10- **Dynamic Selectors**: Use conditions to filter data dynamically.
11- **Function Support**: Built-in functions for data manipulation (e.g., length, sum, avg).
12- **Easy Integration**: Can be used in both Deno and Val Town environments.
1317import Diesel from "https://esm.town/v/yawnxyz/diesel";
1819async function main() {
20const jsonData = `
21{