npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

fff-cart

v2.0.3

Published

fabfitfun cart service

Readme

cart

cart is the application that supports shopping cart include calculating remove/add items, total, shipping fee and etc from your cart, customize and shop. The front end is built in react supported by webpack and backend is supported with ace api built injava.

Example Usage

import GlobalCart from 'fff-cart' 
  
<GlobalCart
  cartData={cartData}
  receiveUpdateCart={receiveUpdateCart}
  env="dev"
/>

Props

This is the list of props you can pass to the cart.

receiveUpdateCart

function(variantId: number, cartDetails: object) | optional

Called when the cart is successfully updated. It should accept the variantId that was updated, as well as the updated cartDetails as parameters. This function is intended to be used in Pandora, so that the sale page containing the cart will reflect the changes made to the cart.

cartData

{ cartVariants: array, cartDetails: object, initialCredits: object, itemsCount: number } | optional

Passed to the cart if available. Otherwise, the cart will make a request to ace-api to get cart data.

  • cartVariants must be flattened and formatted correctly using the utility functions exported from the cart, using flattenProducts and getCartVariants
  • initialCredits and cartDetails must match the API response to fetch the cart from ace-api (1/carts/campaigns?type=SHOP)
  • itemsCount is the total number of items in the cart

env

string | required

options: ["dev", "load", "load01", "qa", "staging", "prod"]

Must be passed to the cart so the cart knows which env it is running in. It is up to you to determine which env your application is running in and pass appropriately. If no env prop is passed, cart will throw and console.log an error.

Exports

flattenProducts

function(products: object)

Accepts an object with product IDs as keys. Returns products, an array of products, and variants, an array of variants. This is used to format the response from ace-api to get the cart.

getCartVariants

function(cartDetails: object, variants: array, products: array)

Maps through list of variants from flattenProducts and adds applicable fields to variants from products and cartDetails. Returns cartVariants.

getCount

function(cartVariants: object)

Accepts list of cart variants and returns count, the total number of items in the cart.

getCartSubtotal

function(cartVariants: array)

Accepts array of cart variants and returns cart subtotal (does not include shipping and tax).

getAllCreditValues

function(subtotal: number, initialCredits: object)

Accepts calculated subtotal from getCartSubtotal and intialCredits from API response. Returns:

  • hasInitialPurchaseCredit: boolean: indicates whether or not the user had an intial purchase credit
  • remainingCredit: string: amount of purchase credit user has remaining
  • initialPurchaseCredit: string amount of purchase credit user had to begin with
  • appliedPurchaseCredit: string: amount of purchase credit user has applied to their cart

getShippingAndTax

function(cartVariants: array, cartDetails: object, subtotal: number, initialCredits: object)

Returns:

  • hasFreeShipping: boolean indicates whether or not the user has free shipping
  • shippingAmount: string shipping amount the user owes
  • hasAdditionalShipping: boolean indicates whether or not the user has an additional shipping fee
  • remainingSpendToFreeShipping: string amount user has to add to cart to get free shipping
  • showShipping: boolean indicates whether or not shipping should be displayed in cart (false if all items in the cart are shipping exempt)
  • hasTax: boolean indicates whether or not tax should be display in cart, only true for UK users
  • taxLabel: string label to display tax
  • taxAmount: string amount of tax the user owes
  • total: string total amount the user owes

formatCurrency

function(cents: number)

Formats a number in cents to a string with two decimal points.

develop / getting started

npm dependencies must be installed with the installation script. node and npm can be installed with a command line tool such as homebrew or can be downloaded directly. For the installation script to run successfully you need access to bitsrc.

$ npm install

Run the start script to serve the application in the browser at local.fff-dev.com:80. The port is configurable via webpack if needed.

$ sudo npm start

In your browser, you can now access cart by pointing towards local.fff-dev.com:80

To point the cart to your local ace-api, in src/index.js change

if (process.env.APP_ENV === 'local') {
  ReactDOM.render(<CartContainer env="dev" />, document.getElementById('root'));
}

to

if (process.env.APP_ENV === 'local') {
  ReactDOM.render(<CartContainer env="local" />, document.getElementById('root'));
}

In src/services/apis/request.js, add an authorization header to the request headers: Authorization: 'Bearer [jwtToken]' and comment out the line credentials: include`

publishing

Run the build script to generate the bundle

$ npm run build

To test package locally, run npm link. Then, in the root directory of the application you would like to import the cart into, run npm link fff-cart You may need to run the following commands (with the correct path) to link the cart to the instances of react and react-dom in the application you are importing the cart into. This is to avoid having duplicate versions of React in the same application.

$ npm link /Users/${username}/code/pandora/node_modules/react
$ npm link /Users/${username}/code/pandora/node_modules/react-dom

To test publishing the package and importing it locally:

//in cart
$ npm pack
$ cp fff-cart-<version>.tgz ~
//in application you are importing cart into
$ npm install ~/fff-cart-<version>.tgz

ES6+

If an ES6+ feature breaks compilation, then that particular feature may need an additional babel dependency requiring both installation and webpack configuration.

Webpack

Webpack configuration can become quite advanced and the best resource will be to refer directly to the webpack configuration documentation.

Integration with FFF Apps

The cart can integarted with the Shop, Customize and Pandora applications.

npm install --save fff-cart

importing into legacy WP Shop

Generate the bundle for the shop by running npm run build:shop. You will have to copy and paste the generated bundle in dist/bundle.js into the wp-content/react/global-cart-webpack-bundle/dist/bundle.js file in the shop repo: https://github.com/fabfitfun/shop-fabfitfun. This needs to be done every time the cart is republished.