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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@a15-ghm/gh-cart

v1.0.0

Published

This library for interacting with app state. Contains:

Downloads

8

Readme

GhCart

This library for interacting with app state. Contains:

  1. cart

To use the gh-cart library in your Angular project, follow these steps:

Installation

Install the gh-cart library by running the following command npm install --save @a15-ghm/gh-cart

Importing

import { StoreModule } from '@ngrx/store';
import { GhCartModule } from '@a15-ghm/gh-cart';

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule, AppRoutingModule, StoreModule.forRoot({}), GhCartModule],
  providers: [],
  bootstrap: [AppComponent],
})

Pass env variables to the a15-ghm/gh-utils library. This is necessary to add a products

import Environment from '@a15-ghm/gh-utils/environment';
import { environment } from '../environments/environment';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss'],
})
export class AppComponent implements OnInit {
  public ngOnInit() {
    Environment.setEnvVariables(environment);
  }
}

Using

Use getCart method to get cart state

import { GhCartService } from '@a15-ghm/gh-cart';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss'],
})
export class AppComponent implements OnInit {
  private cart;

  constructor(private ghCartService: GhCartService) {}
  //or
  private ghCartService: GhCartService = inject(GhCartService);

  public ngOnInit() {
    this.ghCartService.getCart().subscribe((cart) => {
      this.cart = cart;
    });
  }
}

Use addUrlProducts method to add products

Note that you need to pass a method that shows an error to the user when adding a product, and parameters for this method if needed

@Component({
  selector: 'page-cart',
  templateUrl: './cart.html',
  styleUrls: ['./cart.scss'],
})
export class CartPageComponent {
  constructor(private ghCartService: GhCartService) {}
  //or
  private ghCartService: GhCartService = inject(GhCartService);

  ngOnInit(): void {
    this.ghCartService.addUrlProducts(
      this.toastService.pop.bind(this.toastService, 'something went wrong', SnackbarType.error, 5, SnackbarPosition.topCenter)
    );
  }
}

Use removeProduct method to remove product

@Component({
  selector: 'page-cart',
  templateUrl: './cart.html',
  styleUrls: ['./cart.scss'],
})
export class CartPageComponent {
  constructor(private ghCartService: GhCartService) {}
  //or
  private ghCartService: GhCartService = inject(GhCartService);

  removeProduct(productId: string): void {
    this.ghCartService.removeProduct(productId);
  }
}

Use incrementProductCount method to increment product

@Component({
  selector: 'page-cart',
  templateUrl: './cart.html',
  styleUrls: ['./cart.scss'],
})
export class CartPageComponent {
  constructor(private ghCartService: GhCartService) {}
  //or
  private ghCartService: GhCartService = inject(GhCartService);

  incrementProductCount(sfid: string): void {
    this.ghCartService.incrementProductCount(sfid);
  }
}

Use decrementProductCount method to decrement product

@Component({
  selector: 'page-cart',
  templateUrl: './cart.html',
  styleUrls: ['./cart.scss'],
})
export class CartPageComponent {
  constructor(private ghCartService: GhCartService) {}
  //or
  private ghCartService: GhCartService = inject(GhCartService);

  decrementProductCount(sfid: string): void {
    this.ghCartService.decrementProductCount(sfid);
  }
}

Use getCartProductsCount method to get products count

@Component({
  selector: 'page-cart',
  templateUrl: './cart.html',
  styleUrls: ['./cart.scss'],
})
export class CartPageComponent {
  private cartProductsCount;

  constructor(private ghCartService: GhCartService) {}
  //or
  private ghCartService: GhCartService = inject(GhCartService);

  getCartProductsCount(): void {
    this.ghCartService.getCartProductsCount().subscribe((cartProductsCount) => {
      this.cartProductsCount = cartProductsCount;
    });
  }
}

Use getCartSubtotalBeforeDiscount method to get cart subtotal before discount

@Component({
  selector: 'page-cart',
  templateUrl: './cart.html',
  styleUrls: ['./cart.scss'],
})
export class CartPageComponent {
  private cartSubtotalBeforeDiscount;

  constructor(private ghCartService: GhCartService) {}
  //or
  private ghCartService: GhCartService = inject(GhCartService);

  getCartSubtotalBeforeDiscount(): void {
    this.ghCartService.getCartSubtotalBeforeDiscount().subscribe((cartSubtotalBeforeDiscount) => {
      this.cartSubtotalBeforeDiscount = cartSubtotalBeforeDiscount;
    });
  }
}

Use getCartSubtotal method to get cart subtotal

@Component({
  selector: 'page-cart',
  templateUrl: './cart.html',
  styleUrls: ['./cart.scss'],
})
export class CartPageComponent {
  private cartSubtotal;

  constructor(private ghCartService: GhCartService) {}
  //or
  private ghCartService: GhCartService = inject(GhCartService);

  getCartSubtotal(): void {
    this.ghCartService.getCartSubtotal().subscribe((cartSubtotal) => {
      this.cartSubtotal = cartSubtotal;
    });
  }
}

Use getCartTotalAmount method to get cart total amount

@Component({
  selector: 'page-cart',
  templateUrl: './cart.html',
  styleUrls: ['./cart.scss'],
})
export class CartPageComponent {
  private cartTotalAmount;

  constructor(private ghCartService: GhCartService) {}
  //or
  private ghCartService: GhCartService = inject(GhCartService);

  getCartTotalAmount(): void {
    this.ghCartService.getCartTotalAmount().subscribe((cartTotalAmount) => {
      this.cartTotalAmount = cartTotalAmount;
    });
  }
}

Use clearCart method to remove all products and variants

@Component({
  selector: 'page-cart',
  templateUrl: './cart.html',
  styleUrls: ['./cart.scss'],
})
export class CartPageComponent {
  constructor(private ghCartService: GhCartService) {}
  //or
  private ghCartService: GhCartService = inject(GhCartService);

  clearCart(): void {
    this.ghCartService.clearCart();
  }
}

Use getCartProducts method to get cart products and variants

@Component({
  selector: 'page-cart',
  templateUrl: './cart.html',
  styleUrls: ['./cart.scss'],
})
export class CartPageComponent {
  private productsAndVariants;

  constructor(private ghCartService: GhCartService) {}
  //or
  private ghCartService: GhCartService = inject(GhCartService);

  getCartProducts(): void {
    this.ghCartService.getCartProducts().subscribe((productsAndVariants) => {
      this.productsAndVariants = productsAndVariants;
    });
  }
}

Use getCartProductIds method to get cart product IDs

@Component({
  selector: 'page-cart',
  templateUrl: './cart.html',
  styleUrls: ['./cart.scss'],
})
export class CartPageComponent {
  private cartProductIds;

  constructor(private ghCartService: GhCartService) {}
  //or
  private ghCartService: GhCartService = inject(GhCartService);

  getCartProductIds(): void {
    this.ghCartService.getCartProductIds().subscribe((cartProductIds) => {
      this.cartProductIds = cartProductIds;
    });
  }
}