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

qansigliere-cart

v1.0.0

Published

This library is based on Javascript language and it contains methods that emulate the behavior of the cart when adding or changing items in it

Downloads

110

Readme

Cart

This library is based on Javascript language and it contains methods that emulate the behavior of the cart when adding or changing items in it

Author

https://www.youtube.com/@QANSIGLIERE/

???

Installing

Using npm:

npm i qansigliere-cart

Models

Tax

Tax is an object to emulate the tax behavior. The tax structure has the following fields:

  • name
  • type ** amount ** percent
  • taxRatePercentValue
  • taxRate
  • taxAmount

Common JS

var { Tax } = require('qansigliere-cart');
// Create a tax with the percent amount
let newPrevailingTax = new Tax('prevailing', 'percent', 8.875);

ES Module

import { Tax } from 'qansigliere-cart';
// Create a tax with the fixed amount
let newPrevailingTax = new Tax('tabaco', 'amount', 1.01);

Modifier

The modifier, as in real life, is used to change the original price of the product. The modifier structure has the following fields:

  • price
  • name
  • createdDate
  • updatedDate

Common JS

var { Modifier } = require('qansigliere-cart');

let newModifier = new Modifier('sugar', 0.99);

ES Module

import { Modifier } from 'qansigliere-cart';

let newModifier = new Modifier('water', 0);

Product

The product is the object that we are going to put in the cart and for which all the necessary taxes will be calculated.. The product structure has the following fields:

  • price
  • name
  • cost
  • appliedTaxes
  • appliedModifiers
  • appliedDiscounts
  • appliedServiceFees
  • isUntaxed
  • taxIncluded
  • createdDate
  • updatedDate

Common JS

var { Product } = require('qansigliere-cart');

new Product(5.99, 'Brownie');

ES Module

import { Product } from 'qansigliere-cart';

new Product(5.99, 'Brownie');

Discount

Service Fee

Cart

Example

CommonJS

var { Tax, Product, Modifier, Discount, ServiceFee, Cart } = require('qansigliere-cart');

// Create a new empty cart
let newCart = new Cart([], false, [], [], []);
// Create a new item
let newItem = new Product(5.99, 'Brownie');
// Add the item to the cart
newCart.applyProductToCart(newItem, 3);
// Create a new percent type tax
let newPercentTax = new Tax('Regular', 'percent', 8.875);
// Apply the tax to the item
newCart.applyTaxToItem(0, newPercentTax);
// Create a new percent type tax
let newCartPercentTax = new Tax('Local', 'percent', 1.25);
// Apply the percent tax to the cart
newCart.applyTaxToCart(newCartPercentTax);

JSON.stringify(newCart);

Output

{
"appliedTaxes":[
{
"name":"Regular",
"type":"percent",
"taxRatePercentValue":8.875,
"taxRate":0.08875,
"taxAmount":0
}
],
"taxIncluded":false,
"appliedProducts":[
{
"cost":0,
"price":5.99,
"name":"Brownie",
"appliedTaxes":[
],
"appliedModifiers":[
],
"appliedDiscounts":[
],
"appliedServiceFees":[
],
"isUntaxed":false,
"taxIncluded":false,
"createdDate":"2024-10-08T15:05:28.278Z",
"updatedDate":"2024-10-08T15:05:28.278Z",
"quantity":1,
"sort":1,
"totalValues":{
"totalPrice":5.99,
"totalItemModifierPrice":0,
"itemTaxIncludedAmount":0,
"itemTaxExcludedAmount":0.5316125,
"totalItemTaxRate":0.08875
}
},
{
"cost":0,
"price":5.99,
"name":"Brownie",
"appliedTaxes":[
],
"appliedModifiers":[
],
"appliedDiscounts":[
],
"appliedServiceFees":[
],
"isUntaxed":false,
"taxIncluded":false,
"createdDate":"2024-10-08T15:05:28.278Z",
"updatedDate":"2024-10-08T15:05:28.278Z",
"quantity":1,
"sort":1,
"totalValues":{
"totalPrice":5.99,
"totalItemModifierPrice":0,
"itemTaxIncludedAmount":0,
"itemTaxExcludedAmount":0.5316125,
"totalItemTaxRate":0.08875
}
}
],
"appliedDiscounts":[
],
"appliedServiceFees":[
],
"isClosed":false,
"currency":"$",
"createdDate":"2024-10-08T15:05:28.277Z",
"updatedDate":"2024-10-08T15:05:28.278Z",
"uuid":"aef19030-bca4-961a-bdcd-6e7df7a04e9f",
"isUntaxed":false,
"taxIncludedAmount":0,
"taxExcludedAmount":1.063225,
"totalDiscountsAmount":0,
"totalServiceFeesAmount":0,
"totalAmount":11.98,
"totalTaxAmount":1.063225,
"finalTotalAmount":13.043225
}

ES Module

import { Tax, Product, Modifier, Discount, ServiceFee, Cart } from 'qansigliere-cart';

// Create a new empty cart
let newCart = new Cart([], false, [], [], []);
// Create a new item
let newItem = new Product(5.99, 'Brownie');
// Add the item to the cart
newCart.applyProductToCart(newItem, 3);
// Create a new percent type tax
let newPercentTax = new Tax('Regular', 'percent', 8.875);
// Apply the tax to the item
newCart.applyTaxToItem(0, newPercentTax);
// Create a new percent type tax
let newCartPercentTax = new Tax('Local', 'percent', 1.25);
// Apply the percent tax to the cart
newCart.applyTaxToCart(newCartPercentTax);

JSON.stringify(newCart);

Output

{
"appliedTaxes":[
{
"name":"Regular",
"type":"percent",
"taxRatePercentValue":8.875,
"taxRate":0.08875,
"taxAmount":0
}
],
"taxIncluded":false,
"appliedProducts":[
{
"cost":0,
"price":5.99,
"name":"Brownie",
"appliedTaxes":[
],
"appliedModifiers":[
],
"appliedDiscounts":[
],
"appliedServiceFees":[
],
"isUntaxed":false,
"taxIncluded":false,
"createdDate":"2024-10-08T15:05:28.278Z",
"updatedDate":"2024-10-08T15:05:28.278Z",
"quantity":1,
"sort":1,
"totalValues":{
"totalPrice":5.99,
"totalItemModifierPrice":0,
"itemTaxIncludedAmount":0,
"itemTaxExcludedAmount":0.5316125,
"totalItemTaxRate":0.08875
}
},
{
"cost":0,
"price":5.99,
"name":"Brownie",
"appliedTaxes":[
],
"appliedModifiers":[
],
"appliedDiscounts":[
],
"appliedServiceFees":[
],
"isUntaxed":false,
"taxIncluded":false,
"createdDate":"2024-10-08T15:05:28.278Z",
"updatedDate":"2024-10-08T15:05:28.278Z",
"quantity":1,
"sort":1,
"totalValues":{
"totalPrice":5.99,
"totalItemModifierPrice":0,
"itemTaxIncludedAmount":0,
"itemTaxExcludedAmount":0.5316125,
"totalItemTaxRate":0.08875
}
}
],
"appliedDiscounts":[
],
"appliedServiceFees":[
],
"isClosed":false,
"currency":"$",
"createdDate":"2024-10-08T15:05:28.277Z",
"updatedDate":"2024-10-08T15:05:28.278Z",
"uuid":"aef19030-bca4-961a-bdcd-6e7df7a04e9f",
"isUntaxed":false,
"taxIncludedAmount":0,
"taxExcludedAmount":1.063225,
"totalDiscountsAmount":0,
"totalServiceFeesAmount":0,
"totalAmount":11.98,
"totalTaxAmount":1.063225,
"finalTotalAmount":13.043225
}

Improvements and Suggestions

https://forms.gle/wBX3TDesi2Xv3Zjr9

TO DO List

  1. Voided items
  2. Remove any item from the cart
  3. Item discount amount calculation
  4. Item service fee calculation
  5. Inventory
  6. Send a receipt by email
  7. Show the currency in totals
  8. Support item discounts
  9. Support item service fees
  10. Support order discounts
  11. Support order service fees
  12. Support order id
  13. Implement untaxed logic

TO DO:

Possible scenarios Cart level:

  • Create a blank card
  • Add additional tax to the Cart
  • Add Item to the Cart
  • Add Discount to the Cart
  • Add Service Fee to the Cart

Service Fee level:

  • Add service fee to the Cart (amount / percent)
  • Add service fee to the Item (amount / percent)
  • Remove service fee from the Cart
  • Remove service fee from teh item

Discount level:

  • Add discount to the Cart (amount / percent)
  • Add discount to the Item (amount / percent)
  • Remove discount from the Cart
  • Remove discount from teh item

Taxes level:

  • Add a tax to the Cart
  • Add a tax to the Item
  • Remove a tax from the Cart
  • Remove a tax from teh item

Tax Countries level:

  • Tax Included
  • Tax Excluded

Product level:

  • Zero price
  • Change quantity
  • Tax included item
  • Untaxed item

Modifier level:

  • Add a modifier to the product
  • Change quantity value for any modifier
  • Remove modifier from the product

For taxes: Support taxes with $ and % value types

For cart: Show the currency icon in total values