### Run Node.js Example Source: https://github.com/supermarkt/checkjebon-js/blob/main/README.md Execute the Node.js example file to test the library's programmatic usage. ```powershell node example.node.js ``` -------------------------------- ### Run Tests with Mocha Source: https://github.com/supermarkt/checkjebon-js/blob/main/README.md Execute the project's tests using Mocha. Ensure Node.js is installed. ```powershell node test ``` -------------------------------- ### Get Prices for Multiple Products Source: https://github.com/supermarkt/checkjebon-js/blob/main/README.md Retrieves price information for a list of products across all available supermarkets. Useful for comparing prices of specific items. ```javascript const products = await getPricesForProducts([ "1,5 liter halfvolle melk", "250 gram roomboter", "6 eieren" ]); for (const supermarket of products) { console.log(`${supermarket.name}: €${supermarket.products[0].price}`); } ``` -------------------------------- ### Get List of Available Supermarkets Source: https://github.com/supermarkt/checkjebon-js/blob/main/README.md Fetches a list of all supermarkets supported by the service, including their codes, names, and icons. Use this to populate UI elements or for reference. ```javascript const supermarkets = await getSupermarkets(); console.log("Available supermarkets:"); for (const store of supermarkets) { console.log(`${store.code}: ${store.name}`); } ``` -------------------------------- ### Get Price Update Timestamp Source: https://github.com/supermarkt/checkjebon-js/blob/main/README.md Retrieves the date and time when the price data was last updated. Helps in understanding the freshness of the price information. ```javascript const lastUpdate = pricesLastUpdated(); if (lastUpdate) { console.log(`Prices last updated: ${lastUpdate.toLocaleString()}`); } else { console.log('Prices last updated: Unknown'); } ``` -------------------------------- ### getOptimalShoppingPlan Source: https://github.com/supermarkt/checkjebon-js/blob/main/README.md Calculates the most cost-effective way to purchase a list of products by selecting a combination of supermarkets, up to a specified visit limit. Returns a promise with the total cost and a breakdown of products per store. ```APIDOC ## getOptimalShoppingPlan(productNames, maxSupermarketVisitCount, selectedSupermarketCodes) ### Description Find the optimal combination of supermarkets to buy products from, minimizing total cost while respecting the maximum number of stores you want to visit. ### Parameters #### Path Parameters - `productNames` (string[]): Array of product names to buy - `maxSupermarketVisitCount` (number): Maximum number of supermarkets to visit - `selectedSupermarketCodes` (string[]): Array of supermarket codes to choose from (e.g., ["ah", "jumbo", "lidl"]) ### Returns `Promise` - Object containing: - `totalCost` (number): Total cost in euros for all products - `supermarkets` (Array): Array of selected supermarket objects with: - `code` (string): Supermarket code - `name` (string): Supermarket name - `icon` (string|null): Supermarket icon URL - `products` (Array): Products to buy at this supermarket ### Request Example ```javascript const result = await getOptimalShoppingPlan( ["melk", "brood", "kaas"], 3, // Visit maximum 3 stores ["ah", "dirk", "jumbo", "vomar", "lidl", "aldi"] ); console.log(`Total cost: €${result.totalCost}`); console.log(`Stores to visit: ${result.supermarkets.length}`); for (const store of result.supermarkets) { console.log(`\nBuy at ${store.name}:`); for (const product of store.products) { console.log(` - ${product.name}: €${product.price}`); } } ``` ``` -------------------------------- ### Display Supermarket Data and Product List Source: https://github.com/supermarkt/checkjebon-js/blob/main/example.browser.html This snippet fetches supermarket data, calculates the total price for each store, and dynamically generates HTML to display the store name, code, total price, and a list of products. It handles different product types, including those with links, estimated prices, and missing price information. Error handling is included for the API request. ```javascript const optimizeResult = document.getElementById('optimizeResult'); try { const result = await fetch('/supermarkt/checkjebon-js').then(res => res.json()); let html = `

${result.supermarkets.length} ${result.supermarkets.length === 1 ? 'supermarket' : 'supermarkets'} found

`; for (const store of result.supermarkets) { const storeTotal = store.products.reduce((sum, p) => sum + (typeof p.price === 'number' ? p.price : 0), 0); let iconHtml = store.icon ? `icon` : ''; html += `

${iconHtml}${store.name} (${store.code}) - €${storeTotal.toFixed(2)}

`; html += ''; } optimizeResult.innerHTML = html; } catch (e) { optimizeResult.innerHTML = `

Error: ${e.message}

`; } ``` -------------------------------- ### Basic Price Comparison with Checkjebon.js Source: https://github.com/supermarkt/checkjebon-js/blob/main/README.md Compares prices for a list of products across supermarkets and generates a comparison link. Also retrieves the last update time for price data. ```javascript const cjb = require('./checkjebon'); const shoppingList = [ "1,5 liter halfvolle melk", "250 gram roomboter", "1 liter cola" ]; cjb.getPricesForProducts(shoppingList).then(result => { console.log(JSON.stringify(result, null, 2)); const link = cjb.getCheckjebonLink(shoppingList); console.log(link); const lastUpdate = cjb.pricesLastUpdated(); console.log(lastUpdate); }); ``` -------------------------------- ### getSupermarkets Source: https://github.com/supermarkt/checkjebon-js/blob/main/README.md Fetches a list of all supermarkets supported by the service. The returned promise resolves to an array of supermarket objects, each including their code, name, and an optional icon URL. ```APIDOC ## getSupermarkets() ### Description Get a list of all available supermarkets with their codes, names, and icons. ### Returns `Promise` - Array of supermarket objects with: - `code` (string): Supermarket code (e.g., "ah", "jumbo") - `name` (string): Full supermarket name - `icon` (string|null): URL to supermarket icon ### Request Example ```javascript const supermarkets = await getSupermarkets(); console.log("Available supermarkets:"); for (const store of supermarkets) { console.log(`${store.code}: ${store.name}`); } ``` ``` -------------------------------- ### getPricesForProducts Source: https://github.com/supermarkt/checkjebon-js/blob/main/README.md Retrieves price information for a given list of products across all available supermarkets. It returns a promise that resolves to an array of supermarket objects, each containing details about the products available there. ```APIDOC ## getPricesForProducts(productNames) ### Description Get price information for a list of products across all available supermarkets. ### Parameters #### Path Parameters - `productNames` (string[]): Array of product names to search for ### Returns `Promise` - Array of supermarket objects, each containing: - `code` (string): Supermarket code (e.g., "ah", "jumbo") - `name` (string): Supermarket display name - `icon` (string|null): URL to supermarket icon - `totalProducts` (number): Total products available at this supermarket - `products` (Array): Array of product objects with: - `name` (string|null): Product name - `link` (string|null): Link to product page - `price` (number|null): Price in euros - `amount` (string|null): Product size/amount - `isEstimate` (boolean): Whether price is estimated - `originalQuery` (string): Original search query ### Request Example ```javascript const products = await getPricesForProducts([ "1,5 liter halfvolle melk", "250 gram roomboter", "6 eieren" ]); for (const supermarket of products) { console.log(`${supermarket.name}: €${supermarket.products[0].price}`); } ``` ``` -------------------------------- ### Multi-Supermarket Shopping Optimizer with Checkjebon.js Source: https://github.com/supermarkt/checkjebon-js/blob/main/README.md Optimizes a shopping list across multiple supermarkets to find the lowest total cost within a specified number of stores. It also lists available supermarkets. ```javascript const cjb = require('./checkjebon'); const products = [ "1,5 liter halfvolle melk", "250 gram roomboter", "6 eieren", "1 kilo bananen" ]; // Get list of available supermarkets cjb.getSupermarkets().then(supermarkets => { console.log("Available supermarkets:"); supermarkets.forEach(s => console.log(` ${s.code}: ${s.name}`)); }); // Optimize shopping across multiple stores const maxStores = 3; const selectedStores = ["ah", "dirk", "jumbo", "vomar", "lidl", "aldi"]; cjb.getOptimalShoppingPlan(products, maxStores, selectedStores) .then(result => { console.log(`Total Cost: €${result.totalCost.toFixed(2)}`); console.log(`Stores to Visit: ${result.supermarkets.length}\n`); result.supermarkets.forEach(store => { console.log(`${store.name}: `); store.products.forEach(p => { console.log(` - ${p.name}: €${p.price.toFixed(2)}`); }); }); }); ``` -------------------------------- ### Generate Checkjebon.nl Shopping Link Source: https://github.com/supermarkt/checkjebon-js/blob/main/README.md Creates a URL that opens the Checkjebon.nl website with a pre-filled shopping list. Useful for sharing shopping lists or creating direct links. ```javascript const url = getCheckjebonLink([ "melk", "brood", "kaas" ]); console.log(url); // Opens: https://www.checkjebon.nl/#melk%0Abrood%0Akaas ``` -------------------------------- ### Find Optimal Shopping Plan Source: https://github.com/supermarkt/checkjebon-js/blob/main/README.md Determines the most cost-effective combination of supermarkets to purchase a list of products, with an option to limit the number of stores visited. Ideal for planning efficient grocery trips. ```javascript const result = await getOptimalShoppingPlan( ["melk", "brood", "kaas"], 3, // Visit maximum 3 stores ["ah", "dirk", "jumbo", "vomar", "lidl", "aldi"] ); console.log(`Total cost: €${result.totalCost}`); console.log(`Stores to visit: ${result.supermarkets.length}`); for (const store of result.supermarkets) { console.log(` Buy at ${store.name}: `); for (const product of store.products) { console.log(` - ${product.name}: €${product.price}`); } } ``` -------------------------------- ### getCheckjebonLink Source: https://github.com/supermarkt/checkjebon-js/blob/main/README.md Generates a shareable URL for Checkjebon.nl that pre-populates a shopping list. Accepts the shopping list as either a single string with items on new lines or an array of strings. ```APIDOC ## getCheckjebonLink(shoppingList) ### Description Generate a Checkjebon.nl URL with a pre-filled shopping list. ### Parameters #### Path Parameters - `shoppingList` (string|string[]): Shopping list as a string (one item per line) or array of items ### Returns `string` - URL to open on Checkjebon.nl with the shopping list ### Request Example ```javascript const url = getCheckjebonLink([ "melk", "brood", "kaas" ]); console.log(url); // Opens: https://www.checkjebon.nl/#melk%0Abrood%0Akaas ``` ``` -------------------------------- ### pricesLastUpdated Source: https://github.com/supermarkt/checkjebon-js/blob/main/README.md Retrieves the timestamp indicating when the price data was last updated. Returns a Date object or null if the information is unavailable. ```APIDOC ## pricesLastUpdated() ### Description Get the timestamp when price data was last updated. ### Returns `Date|null` - Date object representing when prices were last fetched, or null if not available ### Request Example ```javascript const lastUpdate = pricesLastUpdated(); if (lastUpdate) { console.log(`Prices last updated: ${lastUpdate.toLocaleString()}`); } else { console.log('Prices last updated: Unknown'); } ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.