Cookpad の非公開 API を叩く TypeScript クライアント。
Python 版 cookpad-py の TypeScript リライト。
- Node.js 18 以上(組み込み
fetchを使用)
npm install
npm run buildimport { Cookpad } from "cookpad-ts";
const client = new Cookpad();
// レシピ検索
const results = await client.searchRecipes("カレー", { perPage: 5 });
console.log(results.totalCount); // 98564
for (const r of results.recipes) {
console.log(r.title, r.id);
}
// レシピ詳細
const recipe = await client.getRecipe(25557685);
console.log(recipe.title);
console.log(recipe.ingredients.map((i) => i.name));
// ユーザー検索
const users = await client.searchUsers("cook");
for (const u of users.users) {
console.log(u.name, u.recipeCount);
}| オプション | 型 | デフォルト |
|---|---|---|
token |
string |
組み込みトークン |
country |
string |
"JP" |
language |
string |
"ja" |
timezoneId |
string |
"Asia/Tokyo" |
timezoneOffset |
string |
"+09:00" |
userAgent |
string |
組み込み UA |
providerId |
string |
"8" |
| メソッド | Python 版対応 | 戻り値 |
|---|---|---|
searchRecipes(query, options?) |
search_recipes() |
SearchResponse |
getRecipe(id) |
get_recipe() |
Recipe |
getSimilarRecipes(id, options?) |
get_similar_recipes() |
Recipe[] |
getComments(id, options?) |
get_comments() |
CommentsResponse |
searchUsers(query, options?) |
search_users() |
UsersResponse |
searchKeywords(query?) |
search_keywords() |
object |
getSearchHistory(localHistory?) |
get_search_history() |
object |
interface Recipe {
id: number;
title: string;
cookingTime: string | null;
serving: string;
imageUrl: string | null;
ingredients: Ingredient[];
steps: Step[];
user: User | null;
viewCount: number;
bookmarksCount: number;
// ...
}
interface User {
id: number;
name: string;
recipeCount: number;
followerCount: number;
// ...
}import { AuthenticationError, NotFoundError, RateLimitError, APIError } from "cookpad-ts";
try {
await client.getRecipe(999999999);
} catch (e) {
if (e instanceof NotFoundError) console.log("not found");
if (e instanceof APIError) console.log(e.statusCode);
}The Unlicense — 詳細は LICENSE を参照。