mirror of
https://github.com/oven-sh/bun
synced 2026-02-12 20:09:04 +00:00
* More fixes for dap * More changes * More changes 2 * More fixes * Fix debugger.ts * Bun Terminal
47 lines
703 B
TypeScript
47 lines
703 B
TypeScript
export default {
|
|
fetch(request: Request): Response {
|
|
const animal = getAnimal(request.url);
|
|
const voice = animal.talk();
|
|
return new Response(voice);
|
|
},
|
|
};
|
|
|
|
function getAnimal(query: string): Animal {
|
|
switch (query.split("/").pop()) {
|
|
case "dog":
|
|
return new Dog();
|
|
case "cat":
|
|
return new Cat();
|
|
}
|
|
return new Bird();
|
|
}
|
|
|
|
interface Animal {
|
|
readonly name: string;
|
|
talk(): string;
|
|
}
|
|
|
|
class Dog implements Animal {
|
|
name = "dog";
|
|
|
|
talk(): string {
|
|
return "woof";
|
|
}
|
|
}
|
|
|
|
class Cat implements Animal {
|
|
name = "cat";
|
|
|
|
talk(): string {
|
|
return "meow";
|
|
}
|
|
}
|
|
|
|
class Bird implements Animal {
|
|
name = "bird";
|
|
|
|
talk(): string {
|
|
return "chirp";
|
|
}
|
|
}
|