{"id":18799883,"url":"https://github.com/mcnaveen/cart","last_synced_at":"2025-04-13T17:31:10.172Z","repository":{"id":196234361,"uuid":"695250800","full_name":"mcnaveen/cart","owner":"mcnaveen","description":"🛒 An Open Source Headless cart management library that does all the heavy lifting of managing the cart state, storing them in local storage, and even more.","archived":false,"fork":false,"pushed_at":"2023-10-27T06:32:28.000Z","size":370,"stargazers_count":15,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-09-19T14:19:09.607Z","etag":null,"topics":["cart","cart-functionality","cart-items","cart-management","hacktoberfest","headless","headless-cart","react-cart"],"latest_commit_sha":null,"homepage":"https://cart.js.org","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mcnaveen.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-09-22T17:29:04.000Z","updated_at":"2024-07-09T15:33:11.000Z","dependencies_parsed_at":"2024-06-19T06:18:32.967Z","dependency_job_id":"5f33baa0-67d1-416a-9c15-808e1e2c6d28","html_url":"https://github.com/mcnaveen/cart","commit_stats":null,"previous_names":["mcnaveen/cart"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcnaveen%2Fcart","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcnaveen%2Fcart/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcnaveen%2Fcart/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcnaveen%2Fcart/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mcnaveen","download_url":"https://codeload.github.com/mcnaveen/cart/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223291770,"owners_count":17120964,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cart","cart-functionality","cart-items","cart-management","hacktoberfest","headless","headless-cart","react-cart"],"created_at":"2024-11-07T22:16:57.522Z","updated_at":"2024-11-07T22:16:58.081Z","avatar_url":"https://github.com/mcnaveen.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003eCart\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003eHeadless cart management library\u003c/p\u003e\n\n![npm i cart](image/cover.png)\n\n\u003cp align=\"center\"\u003e\n\t\u003ca href=\"#contributors\" target=\"_blank\"\u003e\n\u003c!-- prettier-ignore-start --\u003e\n\u003c!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section --\u003e\n\u003cimg alt=\"All Contributors: 2\" src=\"https://img.shields.io/badge/all_contributors-2-21bb42.svg\" /\u003e\n\u003c!-- ALL-CONTRIBUTORS-BADGE:END --\u003e\n\u003c!-- prettier-ignore-end --\u003e\n\u003c/a\u003e\n\t\u003ca href=\"https://codecov.io/gh/mcnaveen/Cart\" target=\"_blank\"\u003e\n\t\t\u003cimg alt=\"Codecov Test Coverage\" src=\"https://codecov.io/gh/mcnaveen/Cart/branch/main/graph/badge.svg\"/\u003e\n\t\u003c/a\u003e\n\t\u003ca href=\"https://github.com/mcnaveen/Cart/blob/main/.github/CODE_OF_CONDUCT.md\" target=\"_blank\"\u003e\n\t\t\u003cimg alt=\"Contributor Covenant\" src=\"https://img.shields.io/badge/code_of_conduct-enforced-21bb42\" /\u003e\n\t\u003c/a\u003e\n\t\u003ca href=\"https://github.com/mcnaveen/Cart/blob/main/LICENSE.md\" target=\"_blank\"\u003e\n\t\t\u003cimg alt=\"License: MIT\" src=\"https://img.shields.io/github/license/mcnaveen/Cart?color=21bb42\"\u003e\n\t\u003c/a\u003e\n\t\u003cimg alt=\"Style: Prettier\" src=\"https://img.shields.io/badge/style-prettier-21bb42.svg\" /\u003e\n\t\u003cimg alt=\"TypeScript: Strict\" src=\"https://img.shields.io/badge/typescript-strict-21bb42.svg\" /\u003e\n\u003c/p\u003e\n\n\u003e ⚠️ Expect some breaking changes, Use at your own risk\n\n### 🛒 Demo\n\n- [View React Demo](https://stackblitz-starters-dt9zzc.stackblitz.io/)\n- [Nextjs App Directory Demo](https://stackblitzstarterskcruvd-uufb--3000--d6c42aca.local-credentialless.webcontainer.io/)\n\n### :package: Requirements\n\n- React or Nextjs Project ⚛️\n\n### :sparkles: Installation\n\n- Install using the below command (with your package manager of choice)\n\n```bash\n# npm\nnpm install cart --save\n\n# yarn\nyarn add cart\n\n#pnpm\npnpm add cart\n\n# bun\nbun install cart\n\n```\n\n---\n\n### :bulb: Usage Example\n\n```jsx\nimport React from \"react\";\nimport { useCart } from \"cart\";\n\nconst item = {\n  productId: \"123\",\n  name: \"Product 1\",\n  quantity: 1,\n  price: 10,\n};\n\nfunction Cart() {\n  const {\n    addToCart,\n    cartItems,\n    clearCart,\n    decreaseItem,\n    toggleCart,\n    isCartOpen,\n  } = useCart();\n\n  return (\n    \u003cdiv\u003e\n      \u003cp\u003e{isCartOpen ? \"Open\" : \"Closed\"}\u003c/p\u003e\n      \u003cbutton onClick={() =\u003e toggleCart()}\u003eToggle\u003c/button\u003e\n      \u003cbutton onClick={() =\u003e addToCart(item)}\u003eAdd\u003c/button\u003e\n\n      \u003cbutton onClick={() =\u003e clearCart()}\u003eClear\u003c/button\u003e\n      \u003cbutton onClick={() =\u003e decreaseItem(\"123\", 1)}\u003eDecrease\u003c/button\u003e\n\n      \u003cp\u003e{JSON.stringify(cartItems)}\u003c/p\u003e\n    \u003c/div\u003e\n  );\n}\n\nexport default Cart;\n```\n\n### :bulb: SSR Example\n\n```jsx\nimport { useCart, withSSR } from \"cart\";\nimport React from \"react\";\n\nconst item = {\n  productId: \"123\",\n  name: \"Product 1\",\n  quantity: 1,\n  price: 10,\n};\n\nfunction MyCart() {\n  const cart = withSSR(useCart, (state) =\u003e state);\n\n  const handleToggle = () =\u003e {\n    cart?.toggleCart();\n  };\n\n  const itemadd = () =\u003e {\n    cart?.addToCart(item);\n  };\n\n  return (\n    \u003cdiv\u003e\n      \u003cp\u003e{cart?.isCartOpen ? \"Open\" : \"Closed\"}\u003c/p\u003e\n      \u003cbutton onClick={() =\u003e handleToggle()}\u003eToggle\u003c/button\u003e\n      \u003cbutton onClick={() =\u003e itemadd()}\u003eAdd\u003c/button\u003e\n\n      \u003cbutton onClick={() =\u003e cart?.clearCart()}\u003eClear\u003c/button\u003e\n      \u003cbutton onClick={() =\u003e cart?.decreaseItem(\"123\", 1)}\u003eDecrease\u003c/button\u003e\n\n      \u003cp\u003e{JSON.stringify(cart?.cartItems)}\u003c/p\u003e\n    \u003c/div\u003e\n  );\n}\n\nexport default MyCart;\n```\n\n---\n\n### API Reference\n\n| Name             | Type       | Default Value | Description                                                                                        | Example                                                                                                                                          |\n| ---------------- | ---------- | ------------- | -------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |\n| `isCartOpen`     | `boolean`  | `false`       | Indicates whether the cart is open or not.                                                         | `isCartOpen ? \"Yes\" : \"No\"`                                                                                                                      |\n| `toggleCart`     | `function` | -             | Toggles the visibility of the shopping cart.                                                       | `toggleCart();`                                                                                                                                  |\n| `openCart`       | `function` | -             | Sets the cart open state to `true`.                                                                | `openCart();`                                                                                                                                    |\n| `closeCart`      | `function` | -             | Sets the cart open state to `false`.                                                               | `closeCart();`                                                                                                                                   |\n| `cartItems`      | `array`    | `[]`          | An array of items in the cart.                                                                     | `cartItems.map((item) =\u003e ( \u003cdiv key={item.productId}\u003e \u003cp\u003e{item.name}\u003c/p\u003e \u003cp\u003eQuantity: {item.quantity}\u003c/p\u003e \u003cp\u003ePrice: ${item.price}\u003c/p\u003e \u003c/div\u003e ))` |\n| `addToCart`      | `function` | -             | Adds an item to the shopping cart or updates its quantity if already in the cart.                  | `addToCart({ productId: 'product1', name: 'Product 1', quantity: 2, price: 20 });`                                                               |\n| `decreaseItem`   | `function` | -             | Decreases the quantity of an item in the shopping cart or removes it if the quantity becomes zero. | `decreaseItem('product1', 1);`                                                                                                                   |\n| `removeFromCart` | `function` | -             | Removes an item from the shopping cart.                                                            | `removeFromCart('product1');`                                                                                                                    |\n| `clearCart`      | `function` | -             | Clears all items from the shopping cart.                                                           | `clearCart();`                                                                                                                                   |\n\n#### :pray: Credits\n\nHuge thanks to [Peter Krumins](https://github.com/pkrumins) for the package name `cart`.\nPlease checkout [Browserling](https://www.browserling.com/) - Online cross-browser testing platform.\n\n(Btw, This is not a sponsored message, Just my way of saying thank you)\n\n#### Contributors\n\n\u003c!-- spellchecker: disable --\u003e\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\u003c!-- prettier-ignore-start --\u003e\n\u003c!-- markdownlint-disable --\u003e\n\u003ctable\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"14.28%\"\u003e\u003ca href=\"http://www.joshuakgoldberg.com/\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/3335181?v=4?s=100\" width=\"100px;\" alt=\"Josh Goldberg ✨\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eJosh Goldberg ✨\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#tool-JoshuaKGoldberg\" title=\"Tools\"\u003e🔧\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"14.28%\"\u003e\u003ca href=\"https://github.com/mcnaveen\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/8493007?v=4?s=100\" width=\"100px;\" alt=\"MC Naveen\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eMC Naveen\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/mcnaveen/Cart/commits?author=mcnaveen\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"#content-mcnaveen\" title=\"Content\"\u003e🖋\u003c/a\u003e \u003ca href=\"https://github.com/mcnaveen/Cart/commits?author=mcnaveen\" title=\"Documentation\"\u003e📖\u003c/a\u003e \u003ca href=\"#ideas-mcnaveen\" title=\"Ideas, Planning, \u0026 Feedback\"\u003e🤔\u003c/a\u003e \u003ca href=\"#infra-mcnaveen\" title=\"Infrastructure (Hosting, Build-Tools, etc)\"\u003e🚇\u003c/a\u003e \u003ca href=\"#maintenance-mcnaveen\" title=\"Maintenance\"\u003e🚧\u003c/a\u003e \u003ca href=\"#projectManagement-mcnaveen\" title=\"Project Management\"\u003e📆\u003c/a\u003e \u003ca href=\"#tool-mcnaveen\" title=\"Tools\"\u003e🔧\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n\u003c!-- markdownlint-restore --\u003e\n\u003c!-- prettier-ignore-end --\u003e\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n\u003c!-- spellchecker: enable --\u003e\n\n\u003c!-- You can remove this notice if you don't want it 🙂 no worries! --\u003e\n\n#### :green_heart: Message\n\nI hope you find this useful.\nIf you have any questions, please create an issue.\n\n---\n\n\u003e 💙 This package is based on [@JoshuaKGoldberg](https://github.com/JoshuaKGoldberg)'s [create-typescript-app](https://github.com/JoshuaKGoldberg/create-typescript-app).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcnaveen%2Fcart","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmcnaveen%2Fcart","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcnaveen%2Fcart/lists"}