cook-mcp-windy
Version:
HowToCook MCP Server - Intelligent Chinese recipe management and meal planning for AI assistants
100 lines • 2.86 kB
JavaScript
// Export all utility functions for easy importing
export * from './recipeUtils.js';
export * from './mealPlanUtils.js';
export * from './shoppingListUtils.js';
export * from './dishCombinationUtils.js';
// Common utility functions
export function generateId(prefix = 'id') {
return `${prefix}_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
}
export function formatDate(date) {
return date.toISOString().split('T')[0];
}
export function getCurrentTimestamp() {
return new Date().toISOString();
}
export function validateRequired(value, fieldName) {
if (value === undefined || value === null) {
throw new Error(`${fieldName} is required`);
}
return value;
}
export function safeParseInt(value, defaultValue = 0) {
const parsed = parseInt(value, 10);
return isNaN(parsed) ? defaultValue : parsed;
}
export function safeParseFloat(value, defaultValue = 0) {
const parsed = parseFloat(value);
return isNaN(parsed) ? defaultValue : parsed;
}
export function clamp(value, min, max) {
return Math.min(Math.max(value, min), max);
}
export function shuffleArray(array) {
const shuffled = [...array];
for (let i = shuffled.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
}
return shuffled;
}
export function groupBy(array, keyFn) {
return array.reduce((groups, item) => {
const key = keyFn(item);
if (!groups[key]) {
groups[key] = [];
}
groups[key].push(item);
return groups;
}, {});
}
export function unique(array, keyFn) {
if (!keyFn) {
return [...new Set(array)];
}
const seen = new Set();
return array.filter(item => {
const key = keyFn(item);
if (seen.has(key)) {
return false;
}
seen.add(key);
return true;
});
}
export function chunk(array, size) {
const chunks = [];
for (let i = 0; i < array.length; i += size) {
chunks.push(array.slice(i, i + size));
}
return chunks;
}
export function debounce(func, wait) {
let timeout;
return (...args) => {
clearTimeout(timeout);
timeout = setTimeout(() => func(...args), wait);
};
}
export function deepClone(obj) {
if (obj === null || typeof obj !== 'object') {
return obj;
}
if (obj instanceof Date) {
return new Date(obj.getTime());
}
if (obj instanceof Array) {
return obj.map(item => deepClone(item));
}
if (typeof obj === 'object') {
const cloned = {};
for (const key in obj) {
if (obj.hasOwnProperty(key)) {
cloned[key] = deepClone(obj[key]);
}
}
return cloned;
}
return obj;
}
//# sourceMappingURL=index.js.map