@haatlabs-core/storefront
v0.18.5
Published
Read a product's price from a shop page in the browser: Amazon product pages and Shopify products.
Maintainers
Readme
@haatlabs-core/storefront
Read a product's price from a shop page, in the browser (an extension's side panel): Amazon
product pages (title, price, images, variations) and Shopify products (/products/<handle>.js).
Install
pnpm add @haatlabs-core/storefrontUse
import {
amazonMarketOf,
amazonPagePrice,
parseAmazonProduct,
parseHtml,
} from '@haatlabs-core/storefront';
const market = amazonMarketOf('www.amazon.in');
const page = market ? parseAmazonProduct(parseHtml(html), market) : null;
const price = page ? amazonPagePrice(page) : null; // { title, amountMinor, currency, image, source }import { shopifyPagePrice, shopifyProductPath } from '@haatlabs-core/storefront';
const path = shopifyProductPath(location.href); // '/products/lamp.js'
const price = path ? shopifyPagePrice(await (await fetch(path)).json(), 'INR', null) : null;Parsing needs a DOM (DOMParser): run it in a page or panel, or under jsdom in tests.
