← All packages

@lacspace/shipping

v1.0.0Commerce & Ledger0 deps

Checkout-time shipping-rate calculator — flat / weight / price / item rate tables by zone, free-shipping thresholds, surcharges and handling, returning sorted method quotes. Integer minor units, zero-dependency, isomorphic.

npm i @lacspace/shipping

Usage

shipping.ts
import { quoteShipping, cheapestQuote } from "@lacspace/shipping";

const methods = [
  { id: "std", label: "Standard", strategy: "weight", freeOver: 500000, bands: [
    { min: 0, max: 1000, cost: 8000 }, { min: 1000, cost: 12000 },
  ] },
  { id: "exp", label: "Express", strategy: "flat", flat: 25000, etaDays: [1, 2] },
];

const quotes = quoteShipping(methods, { weight: 750, subtotal: 300000 });
// sorted cheapest-first: [{ methodId: "std", cost: 8000 }, { methodId: "exp", cost: 25000 }]
const best = cheapestQuote(methods, { weight: 750, subtotal: 600000 }); // std, free (over 5,000)

Exports 6

resolveZonerateForMethodquoteShippingcheapestQuotefreeShippingRemainingShippingError

Keywords

shippingshipping-ratesecommercecheckoutfree-shippingdelivery

More in Commerce & Ledger