peet86 / cart-localstorage

JavaScript Shopping Cart library on top of localStorage
https://peet86.github.io/cart-localstorage/
MIT License
91 stars 18 forks source link

Cant use in browser via cdn #6

Closed omkar-tenkale closed 4 years ago

omkar-tenkale commented 4 years ago

When using

const myproduct = {id: 3, name: "Vans", price: 75}
add(myproduct, 2);

ReferenceError: _typeof is not definedcart-localstorage.min.js:1:12

https://unpkg.com/cart-localstorage@1.1.2/dist/cart-localstorage.min.js:1 Imported in html as
peet86 commented 4 years ago

Hey omkar-tenkale,

If you include the lib directly (via cdn) you need to use the cartLS instance. Here is a working example:

document.addEventListener("DOMContentLoaded", function(){
    const myproduct = {id: 3, name: "Vans", price: 75}
    cartLS.add(myproduct, 2);
    console.log(cartLS.total())
})

Also please use the latest version (1.1.4):

<script src="https://unpkg.com/cart-localstorage@1.1.4/dist/cart-localstorage.min.js" type="text/javascript"></script>