├── .all-contributorsrc
├── .eslintignore
├── .eslintrc.cjs
├── .github
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── DEVELOPMENT.md
├── ISSUE_TEMPLATE.md
├── ISSUE_TEMPLATE
│ ├── 01-bug.yml
│ ├── 02-documentation.yml
│ ├── 03-feature.yml
│ └── 04-tooling.yml
├── PULL_REQUEST_TEMPLATE.md
├── SECURITY.md
├── actions
│ └── prepare
│ │ └── action.yml
├── renovate.json
└── workflows
│ ├── build.yml
│ ├── compliance.yml
│ ├── contributors.yml
│ ├── lint-knip.yml
│ ├── lint-markdown.yml
│ ├── lint-package-json.yml
│ ├── lint-packages.yml
│ ├── lint-spelling.yml
│ ├── lint.yml
│ ├── post-release.yml
│ ├── pr-review-requested.yml
│ ├── prettier.yml
│ ├── release.yml
│ └── tsc.yml
├── .gitignore
├── .husky
├── .gitignore
└── pre-commit
├── .markdownlint.json
├── .markdownlintignore
├── .npmpackagejsonlintrc.json
├── .nvmrc
├── .prettierignore
├── .prettierrc
├── .release-it.json
├── .vscode
├── extensions.json
├── launch.json
└── settings.json
├── CHANGELOG.md
├── LICENSE.md
├── README.md
├── cspell.json
├── docs
├── .gitignore
├── components
│ ├── floatingButton.tsx
│ └── mycart.tsx
├── next-env.d.ts
├── next.config.js
├── package.json
├── pages
│ ├── _app.tsx
│ ├── _meta.json
│ ├── api-reference.mdx
│ ├── index.mdx
│ ├── installation.mdx
│ └── usage
│ │ ├── nextjs.mdx
│ │ └── react.mdx
├── pnpm-lock.yaml
├── postcss.config.js
├── styles
│ └── globals.css
├── tailwind.config.js
├── theme.config.tsx
└── tsconfig.json
├── image
└── cover.png
├── knip.jsonc
├── package.json
├── pnpm-lock.yaml
├── src
├── cart.ts
└── index.ts
├── tsconfig.eslint.json
├── tsconfig.json
├── tsup.config.ts
└── vitest.config.ts
/.all-contributorsrc:
--------------------------------------------------------------------------------
1 | {
2 | "badgeTemplate": "\" src=\"https://img.shields.io/badge/all_contributors-<%= contributors.length %>-21bb42.svg\" />",
3 | "commit": false,
4 | "commitConvention": "angular",
5 | "contributors": [
6 | {
7 | "login": "mcnaveen",
8 | "name": "MC Naveen",
9 | "avatar_url": "https://avatars.githubusercontent.com/u/8493007?v=4",
10 | "profile": "https://github.com/mcnaveen",
11 | "contributions": [
12 | "code",
13 | "content",
14 | "doc",
15 | "ideas",
16 | "infra",
17 | "maintenance",
18 | "projectManagement",
19 | "tool"
20 | ]
21 | },
22 | {
23 | "login": "JoshuaKGoldberg",
24 | "name": "Josh Goldberg ✨",
25 | "avatar_url": "https://avatars.githubusercontent.com/u/3335181?v=4",
26 | "profile": "http://www.joshuakgoldberg.com/",
27 | "contributions": [
28 | "tool"
29 | ]
30 | }
31 | ],
32 | "contributorsPerLine": 7,
33 | "contributorsSortAlphabetically": true,
34 | "files": [
35 | "README.md"
36 | ],
37 | "imageSize": 100,
38 | "projectName": "Cart",
39 | "projectOwner": "mcnaveen",
40 | "repoHost": "https://github.com",
41 | "repoType": "github"
42 | }
43 |
--------------------------------------------------------------------------------
/.eslintignore:
--------------------------------------------------------------------------------
1 | !.*
2 | coverage
3 | lib
4 | node_modules
5 | pnpm-lock.yaml
6 | docs
--------------------------------------------------------------------------------
/.eslintrc.cjs:
--------------------------------------------------------------------------------
1 | /** @type {import("@types/eslint").Linter.Config} */
2 | module.exports = {
3 | env: {
4 | es2022: true,
5 | node: true,
6 | },
7 | extends: [
8 | "eslint:recommended",
9 | "plugin:eslint-comments/recommended",
10 | "plugin:n/recommended",
11 | "plugin:perfectionist/recommended-natural",
12 | "plugin:regexp/recommended",
13 | ],
14 | overrides: [
15 | {
16 | extends: ["plugin:markdown/recommended"],
17 | files: ["**/*.md"],
18 | processor: "markdown/markdown",
19 | },
20 | {
21 | extends: [
22 | "plugin:jsdoc/recommended-typescript-error",
23 | "plugin:@typescript-eslint/strict",
24 | "plugin:@typescript-eslint/stylistic",
25 | ],
26 | files: ["**/*.ts"],
27 | parser: "@typescript-eslint/parser",
28 | rules: {
29 | // These off-by-default rules work well for this repo and we like them on.
30 | "jsdoc/informative-docs": "error",
31 | "logical-assignment-operators": [
32 | "error",
33 | "always",
34 | { enforceForIfStatements: true },
35 | ],
36 | "operator-assignment": "error",
37 |
38 | // These on-by-default rules don't work well for this repo and we like them off.
39 | "jsdoc/require-jsdoc": "off",
40 | "jsdoc/require-param": "off",
41 | "jsdoc/require-property": "off",
42 | "jsdoc/require-returns": "off",
43 | },
44 | },
45 | {
46 | excludedFiles: ["**/*.md/*.ts"],
47 | extends: [
48 | "plugin:@typescript-eslint/strict-type-checked",
49 | "plugin:@typescript-eslint/stylistic-type-checked",
50 | ],
51 | files: ["**/*.ts"],
52 | parser: "@typescript-eslint/parser",
53 | parserOptions: {
54 | project: "./tsconfig.eslint.json",
55 | },
56 | rules: {
57 | // These off-by-default rules work well for this repo and we like them on.
58 | "deprecation/deprecation": "error",
59 | },
60 | },
61 | {
62 | excludedFiles: ["package.json"],
63 | extends: ["plugin:jsonc/recommended-with-json"],
64 | files: ["*.json", "*.jsonc"],
65 | parser: "jsonc-eslint-parser",
66 | rules: {
67 | "jsonc/sort-keys": "error",
68 | },
69 | },
70 | {
71 | files: ["*.jsonc"],
72 | rules: {
73 | "jsonc/no-comments": "off",
74 | },
75 | },
76 | {
77 | files: "**/*.test.ts",
78 | rules: {
79 | // These on-by-default rules aren't useful in test files.
80 | "@typescript-eslint/no-unsafe-assignment": "off",
81 | "@typescript-eslint/no-unsafe-call": "off",
82 | },
83 | },
84 | {
85 | extends: ["plugin:yml/standard", "plugin:yml/prettier"],
86 | files: ["**/*.{yml,yaml}"],
87 | parser: "yaml-eslint-parser",
88 | rules: {
89 | "yml/file-extension": ["error", { extension: "yml" }],
90 | "yml/sort-keys": [
91 | "error",
92 | {
93 | order: { type: "asc" },
94 | pathPattern: "^.*$",
95 | },
96 | ],
97 | "yml/sort-sequence-values": [
98 | "error",
99 | {
100 | order: { type: "asc" },
101 | pathPattern: "^.*$",
102 | },
103 | ],
104 | },
105 | },
106 | ],
107 | parser: "@typescript-eslint/parser",
108 | plugins: [
109 | "@typescript-eslint",
110 | "deprecation",
111 | "jsdoc",
112 | "no-only-tests",
113 | "perfectionist",
114 | "regexp",
115 | "vitest",
116 | ],
117 | reportUnusedDisableDirectives: true,
118 | root: true,
119 | rules: {
120 | // These off/less-strict-by-default rules work well for this repo and we like them on.
121 | "@typescript-eslint/no-unused-vars": ["error", { caughtErrors: "all" }],
122 | "no-only-tests/no-only-tests": "error",
123 |
124 | // These on-by-default rules don't work well for this repo and we like them off.
125 | "no-case-declarations": "off",
126 | "no-constant-condition": "off",
127 | "no-inner-declarations": "off",
128 | "no-mixed-spaces-and-tabs": "off",
129 |
130 | // Stylistic concerns that don't interfere with Prettier
131 | "@typescript-eslint/padding-line-between-statements": [
132 | "error",
133 | { blankLine: "always", next: "*", prev: "block-like" },
134 | ],
135 | "perfectionist/sort-objects": [
136 | "error",
137 | {
138 | order: "asc",
139 | "partition-by-comment": true,
140 | type: "natural",
141 | },
142 | ],
143 | },
144 | };
145 |
--------------------------------------------------------------------------------
/.github/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | We as members, contributors, and leaders pledge to make participation in our
6 | community a harassment-free experience for everyone, regardless of age, body
7 | size, visible or invisible disability, ethnicity, sex characteristics, gender
8 | identity and expression, level of experience, education, socio-economic status,
9 | nationality, personal appearance, race, caste, color, religion, or sexual
10 | identity and orientation.
11 |
12 | We pledge to act and interact in ways that contribute to an open, welcoming,
13 | diverse, inclusive, and healthy community.
14 |
15 | ## Our Standards
16 |
17 | Examples of behavior that contributes to a positive environment for our
18 | community include:
19 |
20 | - Demonstrating empathy and kindness toward other people
21 | - Being respectful of differing opinions, viewpoints, and experiences
22 | - Giving and gracefully accepting constructive feedback
23 | - Accepting responsibility and apologizing to those affected by our mistakes,
24 | and learning from the experience
25 | - Focusing on what is best not just for us as individuals, but for the overall
26 | community
27 |
28 | Examples of unacceptable behavior include:
29 |
30 | - The use of sexualized language or imagery, and sexual attention or advances of
31 | any kind
32 | - Trolling, insulting or derogatory comments, and personal or political attacks
33 | - Public or private harassment
34 | - Publishing others' private information, such as a physical or email address,
35 | without their explicit permission
36 | - Other conduct which could reasonably be considered inappropriate in a
37 | professional setting
38 |
39 | ## Enforcement Responsibilities
40 |
41 | Community leaders are responsible for clarifying and enforcing our standards of
42 | acceptable behavior and will take appropriate and fair corrective action in
43 | response to any behavior that they deem inappropriate, threatening, offensive,
44 | or harmful.
45 |
46 | Community leaders have the right and responsibility to remove, edit, or reject
47 | comments, commits, code, wiki edits, issues, and other contributions that are
48 | not aligned to this Code of Conduct, and will communicate reasons for moderation
49 | decisions when appropriate.
50 |
51 | ## Scope
52 |
53 | This Code of Conduct applies within all community spaces, and also applies when
54 | an individual is officially representing the community in public spaces.
55 | Examples of representing our community include using an official e-mail address,
56 | posting via an official social media account, or acting as an appointed
57 | representative at an online or offline event.
58 |
59 | ## Enforcement
60 |
61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be
62 | reported to the community leaders responsible for enforcement at
63 | 8493007+mcnaveen@users.noreply.github.com.
64 | All complaints will be reviewed and investigated promptly and fairly.
65 |
66 | All community leaders are obligated to respect the privacy and security of the
67 | reporter of any incident.
68 |
69 | ## Enforcement Guidelines
70 |
71 | Community leaders will follow these Community Impact Guidelines in determining
72 | the consequences for any action they deem in violation of this Code of Conduct:
73 |
74 | ### 1. Correction
75 |
76 | **Community Impact**: Use of inappropriate language or other behavior deemed
77 | unprofessional or unwelcome in the community.
78 |
79 | **Consequence**: A private, written warning from community leaders, providing
80 | clarity around the nature of the violation and an explanation of why the
81 | behavior was inappropriate. A public apology may be requested.
82 |
83 | ### 2. Warning
84 |
85 | **Community Impact**: A violation through a single incident or series of
86 | actions.
87 |
88 | **Consequence**: A warning with consequences for continued behavior. No
89 | interaction with the people involved, including unsolicited interaction with
90 | those enforcing the Code of Conduct, for a specified period of time. This
91 | includes avoiding interactions in community spaces as well as external channels
92 | like social media. Violating these terms may lead to a temporary or permanent
93 | ban.
94 |
95 | ### 3. Temporary Ban
96 |
97 | **Community Impact**: A serious violation of community standards, including
98 | sustained inappropriate behavior.
99 |
100 | **Consequence**: A temporary ban from any sort of interaction or public
101 | communication with the community for a specified period of time. No public or
102 | private interaction with the people involved, including unsolicited interaction
103 | with those enforcing the Code of Conduct, is allowed during this period.
104 | Violating these terms may lead to a permanent ban.
105 |
106 | ### 4. Permanent Ban
107 |
108 | **Community Impact**: Demonstrating a pattern of violation of community
109 | standards, including sustained inappropriate behavior, harassment of an
110 | individual, or aggression toward or disparagement of classes of individuals.
111 |
112 | **Consequence**: A permanent ban from any sort of public interaction within the
113 | community.
114 |
115 | ## Attribution
116 |
117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118 | version 2.1, available at
119 | [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120 |
121 | Community Impact Guidelines were inspired by
122 | [Mozilla's code of conduct enforcement ladder][mozilla coc].
123 |
124 | For answers to common questions about this code of conduct, see the FAQ at
125 | [https://www.contributor-covenant.org/faq][faq]. Translations are available at
126 | [https://www.contributor-covenant.org/translations][translations].
127 |
128 | [homepage]: https://www.contributor-covenant.org
129 | [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130 | [mozilla coc]: https://github.com/mozilla/diversity
131 | [faq]: https://www.contributor-covenant.org/faq
132 | [translations]: https://www.contributor-covenant.org/translations
133 |
--------------------------------------------------------------------------------
/.github/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | Thanks for your interest in contributing to `Cart`! 💖
4 |
5 | > After this page, see [DEVELOPMENT.md](./DEVELOPMENT.md) for local development instructions.
6 |
7 | ## Code of Conduct
8 |
9 | This project contains a [Contributor Covenant code of conduct](./CODE_OF_CONDUCT.md) all contributors are expected to follow.
10 |
11 | ## Reporting Issues
12 |
13 | Please do [report an issue on the issue tracker](https://github.com/mcnaveen/Cart/issues/new/choose) if there's any bugfix, documentation improvement, or general enhancement you'd like to see in the repository! Please fully fill out all required fields in the most appropriate issue form.
14 |
15 | ## Sending Contributions
16 |
17 | Sending your own changes as contribution is always appreciated!
18 | There are two steps involved:
19 |
20 | 1. [Finding an Issue](#finding-an-issue)
21 | 2. [Sending a Pull Request](#sending-a-pull-request)
22 |
23 | ### Finding an Issue
24 |
25 | With the exception of very small typos, all changes to this repository generally need to correspond to an [open issue marked as `accepting prs` on the issue tracker](https://github.com/mcnaveen/Cart/issues?q=is%3Aopen+is%3Aissue+label%3A%22accepting+prs%22).
26 | If this is your first time contributing, consider searching for [unassigned issues that also have the `good first issue` label](https://github.com/mcnaveen/Cart/issues?q=is%3Aopen+is%3Aissue+label%3A%22accepting+prs%22+label%3A%22good+first+issue%22+no%3Aassignee).
27 | If the issue you'd like to fix isn't found on the issue, see [Reporting Issues](#reporting-issues) for filing your own (please do!).
28 |
29 | #### Issue Claiming
30 |
31 | We don't use any kind of issue claiming system.
32 | We've found in the past that they result in accidental ["licked cookie"](https://devblogs.microsoft.com/oldnewthing/20091201-00/?p=15843) situations where contributors claim an issue but run out of time or energy trying before sending a PR.
33 |
34 | If an issue has been marked as `accepting prs` and an open PR does not exist, feel free to send a PR.
35 | You don't need to ask for permission.
36 |
37 | ### Sending a Pull Request
38 |
39 | Once you've identified an open issue accepting PRs that doesn't yet have a PR sent, you're free to send a pull request.
40 | Be sure to fill out the pull request template's requested information -- otherwise your PR will likely be closed.
41 |
42 | PRs are also expected to have a title that adheres to [commitlint](https://github.com/conventional-changelog/commitlint).
43 | Only PR titles need to be in that format, not individual commits.
44 | Don't worry if you get this wrong: you can always change the PR title after sending it.
45 | Check [previously merged PRs](https://github.com/mcnaveen/Cart/pulls?q=is%3Apr+is%3Amerged+-label%3Adependencies+) for reference.
46 |
47 | #### Draft PRs
48 |
49 | If you don't think your PR is ready for review, [set it as a draft](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/changing-the-stage-of-a-pull-request#converting-a-pull-request-to-a-draft).
50 | Draft PRs won't be reviewed.
51 |
52 | #### Granular PRs
53 |
54 | Please keep pull requests single-purpose: in other words, don't attempt to solve multiple unrelated problems in one pull request.
55 | Send one PR per area of concern.
56 | Multi-purpose pull requests are harder and slower to review, block all changes from being merged until the whole pull request is reviewed, and are difficult to name well with semantic PR titles.
57 |
58 | #### Pull Request Reviews
59 |
60 | When a PR is not in draft, it's considered ready for review.
61 | Please don't manually `@` tag anybody to request review.
62 | A maintainer will look at it when they're next able to.
63 |
64 | PRs should have passing [GitHub status checks](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/collaborating-on-repositories-with-code-quality-features/about-status-checks) before review is requested (unless there are explicit questions asked in the PR about any failures).
65 |
66 | #### Asking Questions
67 |
68 | If you need help and/or have a question, posting a comment in the PR is a great way to do so.
69 | There's no need to tag anybody individually.
70 | One of us will drop by and help when we can.
71 |
72 | Please post comments as [line comments](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/commenting-on-a-pull-request#adding-line-comments-to-a-pull-request) when possible, so that they can be threaded.
73 | You can [resolve conversations](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/commenting-on-a-pull-request#resolving-conversations) on your own when you feel they're resolved - no need to comment explicitly and/or wait for a maintainer.
74 |
75 | #### Requested Changes
76 |
77 | After a maintainer reviews your PR, they may request changes on it.
78 | Once you've made those changes, [re-request review on GitHub](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/about-pull-request-reviews#re-requesting-a-review).
79 |
80 | Please try not to force-push commits to PRs that have already been reviewed.
81 | Doing so makes it harder to review the changes.
82 | We squash merge all commits so there's no need to try to preserve Git history within a PR branch.
83 |
84 | Once you've addressed all our feedback by making code changes and/or started a followup discussion, [re-request review](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/about-pull-request-reviews#re-requesting-a-review) from each maintainer whose feedback you addressed.
85 |
86 | Once all feedback is addressed and the PR is approved, we'll ensure the branch is up to date with `main` and merge it for you.
87 |
88 | #### Post-Merge Recognition
89 |
90 | Once your PR is merged, if you haven't yet been added to the [_Contributors_ table in the README.md](../README.md#contributors) for its [type of contribution](https://allcontributors.org/docs/en/emoji-key "Allcontributors emoji key"), you should be soon.
91 | Please do ping the maintainer who merged your PR if that doesn't happen within 24 hours - it was likely an oversight on our end!
92 |
93 | ## Emojis & Appreciation
94 |
95 | If you made it all the way to the end, bravo dear user, we love you.
96 | Please include your favorite emoji in the bottom of your issues and PRs to signal to us that you did in fact read this file and are trying to conform to it as best as possible.
97 | 💖 is a good starter if you're not sure which to use.
98 |
--------------------------------------------------------------------------------
/.github/DEVELOPMENT.md:
--------------------------------------------------------------------------------
1 | # Development
2 |
3 | After [forking the repo from GitHub](https://help.github.com/articles/fork-a-repo) and [installing pnpm](https://pnpm.io/installation):
4 |
5 | ```shell
6 | git clone https://github.com//Cart
7 | cd Cart
8 | pnpm install
9 | ```
10 |
11 | > This repository includes a list of suggested VS Code extensions.
12 | > It's a good idea to use [VS Code](https://code.visualstudio.com) and accept its suggestion to install them, as they'll help with development.
13 |
14 | ## Building
15 |
16 | Run [**tsup**](https://tsup.egoist.dev) locally to build source files from `src/` into output files in `lib/`:
17 |
18 | ```shell
19 | pnpm build
20 | ```
21 |
22 | Add `--watch` to run the builder in a watch mode that continuously cleans and recreates `lib/` as you save files:
23 |
24 | ```shell
25 | pnpm build --watch
26 | ```
27 |
28 | ## Formatting
29 |
30 | [Prettier](https://prettier.io) is used to format code.
31 | It should be applied automatically when you save files in VS Code or make a Git commit.
32 |
33 | To manually reformat all files, you can run:
34 |
35 | ```shell
36 | pnpm format:write
37 | ```
38 |
39 | ## Linting
40 |
41 | This package includes several forms of linting to enforce consistent code quality and styling.
42 | Each should be shown in VS Code, and can be run manually on the command-line:
43 |
44 | - `pnpm lint` ([ESLint](https://eslint.org) with [typescript-eslint](https://typescript-eslint.io)): Lints JavaScript and TypeScript source files
45 | - `pnpm lint:knip` ([knip](https://github.com/webpro/knip)): Detects unused files, dependencies, and code exports
46 | - `pnpm lint:md` ([Markdownlint](https://github.com/DavidAnson/markdownlint)): Checks Markdown source files
47 | - `pnpm lint:package-json` ([npm-package-json-lint](https://npmpackagejsonlint.org/)): Lints the `package.json` file
48 | - `pnpm lint:packages` ([pnpm dedupe --check](https://pnpm.io/cli/dedupe)): Checks for unnecessarily duplicated packages in the `pnpm-lock.yml` file
49 | - `pnpm lint:spelling` ([cspell](https://cspell.org)): Spell checks across all source files
50 |
51 | Read the individual documentation for each linter to understand how it can be configured and used best.
52 |
53 | For example, ESLint can be run with `--fix` to auto-fix some lint rule complaints:
54 |
55 | ```shell
56 | pnpm run lint --fix
57 | ```
58 |
59 | ## Testing
60 |
61 | [Vitest](https://vitest.dev) is used for tests.
62 | You can run it locally on the command-line:
63 |
64 | ```shell
65 | pnpm run test
66 | ```
67 |
68 | Add the `--coverage` flag to compute test coverage and place reports in the `coverage/` directory:
69 |
70 | ```shell
71 | pnpm run test --coverage
72 | ```
73 |
74 | Note that [console-fail-test](https://github.com/JoshuaKGoldberg/console-fail-test) is enabled for all test runs.
75 | Calls to `console.log`, `console.warn`, and other console methods will cause a test to fail.
76 |
77 | ### Debugging Tests
78 |
79 | This repository includes a [VS Code launch configuration](https://code.visualstudio.com/docs/editor/debugging) for debugging unit tests.
80 | To launch it, open a test file, then run _Debug Current Test File_ from the VS Code Debug panel (or press F5).
81 |
82 | ## Type Checking
83 |
84 | You should be able to see suggestions from [TypeScript](https://typescriptlang.org) in your editor for all open files.
85 |
86 | However, it can be useful to run the TypeScript command-line (`tsc`) to type check all files in `src/`:
87 |
88 | ```shell
89 | pnpm tsc
90 | ```
91 |
92 | Add `--watch` to keep the type checker running in a watch mode that updates the display as you save files:
93 |
94 | ```shell
95 | pnpm tsc --watch
96 | ```
97 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | ## Overview
8 |
9 | ...
10 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/01-bug.yml:
--------------------------------------------------------------------------------
1 | body:
2 | - attributes:
3 | description: If any of these required steps are not taken, we may not be able to review your issue. Help us to help you!
4 | label: Bug Report Checklist
5 | options:
6 | - label: I have tried restarting my IDE and the issue persists.
7 | required: true
8 | - label: I have pulled the latest `main` branch of the repository.
9 | required: true
10 | - label: I have [searched for related issues](https://github.com/mcnaveen/Cart/issues?q=is%3Aissue) and found none that matched my issue.
11 | required: true
12 | type: checkboxes
13 | - attributes:
14 | description: What did you expect to happen?
15 | label: Expected
16 | type: textarea
17 | validations:
18 | required: true
19 | - attributes:
20 | description: What happened instead?
21 | label: Actual
22 | type: textarea
23 | validations:
24 | required: true
25 | - attributes:
26 | description: Any additional info you'd like to provide.
27 | label: Additional Info
28 | type: textarea
29 | description: Report a bug trying to run the code
30 | labels:
31 | - "type: bug"
32 | name: 🐛 Bug
33 | title: "🐛 Bug: "
34 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/02-documentation.yml:
--------------------------------------------------------------------------------
1 | body:
2 | - attributes:
3 | description: If any of these required steps are not taken, we may not be able to review your issue. Help us to help you!
4 | label: Bug Report Checklist
5 | options:
6 | - label: I have pulled the latest `main` branch of the repository.
7 | required: true
8 | - label: I have [searched for related issues](https://github.com/mcnaveen/Cart/issues?q=is%3Aissue) and found none that matched my issue.
9 | required: true
10 | type: checkboxes
11 | - attributes:
12 | description: What would you like to report?
13 | label: Overview
14 | type: textarea
15 | validations:
16 | required: true
17 | - attributes:
18 | description: Any additional info you'd like to provide.
19 | label: Additional Info
20 | type: textarea
21 | description: Report a typo or missing area of documentation
22 | labels:
23 | - "area: documentation"
24 | name: 📝 Documentation
25 | title: "📝 Documentation: "
26 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/03-feature.yml:
--------------------------------------------------------------------------------
1 | body:
2 | - attributes:
3 | description: If any of these required steps are not taken, we may not be able to review your issue. Help us to help you!
4 | label: Bug Report Checklist
5 | options:
6 | - label: I have tried restarting my IDE and the issue persists.
7 | required: true
8 | - label: I have pulled the latest `main` branch of the repository.
9 | required: true
10 | - label: I have [searched for related issues](https://github.com/mcnaveen/Cart/issues?q=is%3Aissue) and found none that matched my issue.
11 | required: true
12 | type: checkboxes
13 | - attributes:
14 | description: What did you expect to be able to do?
15 | label: Overview
16 | type: textarea
17 | validations:
18 | required: true
19 | - attributes:
20 | description: Any additional info you'd like to provide.
21 | label: Additional Info
22 | type: textarea
23 | description: Request that a new feature be added or an existing feature improved
24 | labels:
25 | - "type: feature"
26 | name: 🚀 Feature
27 | title: "🚀 Feature: "
28 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/04-tooling.yml:
--------------------------------------------------------------------------------
1 | body:
2 | - attributes:
3 | description: If any of these required steps are not taken, we may not be able to review your issue. Help us to help you!
4 | label: Bug Report Checklist
5 | options:
6 | - label: I have tried restarting my IDE and the issue persists.
7 | required: true
8 | - label: I have pulled the latest `main` branch of the repository.
9 | required: true
10 | - label: I have [searched for related issues](https://github.com/mcnaveen/Cart/issues?q=is%3Aissue) and found none that matched my issue.
11 | required: true
12 | type: checkboxes
13 | - attributes:
14 | description: What did you expect to be able to do?
15 | label: Overview
16 | type: textarea
17 | validations:
18 | required: true
19 | - attributes:
20 | description: Any additional info you'd like to provide.
21 | label: Additional Info
22 | type: textarea
23 | description: Report a bug or request an enhancement in repository tooling
24 | labels:
25 | - "area: tooling"
26 | name: 🛠 Tooling
27 | title: "🛠 Tooling: "
28 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 |
4 |
5 | ## PR Checklist
6 |
7 | - [ ] Addresses an existing open issue: fixes #000
8 | - [ ] That issue was marked as [`status: accepting prs`](https://github.com/mcnaveen/Cart/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22)
9 | - [ ] Steps in [CONTRIBUTING.md](https://github.com/mcnaveen/Cart/blob/main/.github/CONTRIBUTING.md) were taken
10 |
11 | ## Overview
12 |
13 |
14 |
--------------------------------------------------------------------------------
/.github/SECURITY.md:
--------------------------------------------------------------------------------
1 | # Security Policy
2 |
3 | We take all security vulnerabilities seriously.
4 | If you have a vulnerability or other security issues to disclose:
5 |
6 | - Thank you very much, please do!
7 | - Please send them to us by emailing `8493007+mcnaveen@users.noreply.github.com`
8 |
9 | We appreciate your efforts and responsible disclosure and will make every effort to acknowledge your contributions.
10 |
--------------------------------------------------------------------------------
/.github/actions/prepare/action.yml:
--------------------------------------------------------------------------------
1 | description: Prepares the repo for a typical CI job
2 |
3 | name: Prepare
4 |
5 | runs:
6 | steps:
7 | - uses: pnpm/action-setup@v2
8 | - uses: actions/setup-node@v3
9 | with:
10 | cache: pnpm
11 | node-version: "18"
12 | - run: pnpm install --frozen-lockfile
13 | shell: bash
14 | using: composite
15 |
--------------------------------------------------------------------------------
/.github/renovate.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json",
3 | "automerge": true,
4 | "internalChecksFilter": "strict",
5 | "labels": ["dependencies"],
6 | "postUpdateOptions": ["pnpmDedupe"],
7 | "stabilityDays": 3
8 | }
9 |
--------------------------------------------------------------------------------
/.github/workflows/build.yml:
--------------------------------------------------------------------------------
1 | jobs:
2 | build:
3 | runs-on: ubuntu-latest
4 | steps:
5 | - uses: actions/checkout@v4
6 | - uses: ./.github/actions/prepare
7 | - run: pnpm build
8 | - run: node ./lib/index.js
9 |
10 | name: Build
11 |
12 | on:
13 | pull_request: ~
14 | push:
15 | branches:
16 | - main
17 |
--------------------------------------------------------------------------------
/.github/workflows/compliance.yml:
--------------------------------------------------------------------------------
1 | jobs:
2 | compliance:
3 | runs-on: ubuntu-latest
4 | steps:
5 | - uses: mtfoley/pr-compliance-action@main
6 | with:
7 | body-auto-close: false
8 | ignore-authors: |-
9 | allcontributors
10 | allcontributors[bot]
11 | renovate
12 | renovate[bot]
13 | ignore-team-members: false
14 |
15 | name: Compliance
16 |
17 | on:
18 | pull_request:
19 | branches:
20 | - main
21 | types:
22 | - edited
23 | - opened
24 | - reopened
25 | - synchronize
26 |
27 | permissions:
28 | pull-requests: write
29 |
--------------------------------------------------------------------------------
/.github/workflows/contributors.yml:
--------------------------------------------------------------------------------
1 | jobs:
2 | contributors:
3 | runs-on: ubuntu-latest
4 | steps:
5 | - uses: actions/checkout@v4
6 | with:
7 | fetch-depth: 0
8 | - uses: ./.github/actions/prepare
9 | - env:
10 | GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
11 | uses: JoshuaKGoldberg/all-contributors-auto-action@v0.3.2
12 |
13 | name: Contributors
14 |
15 | on:
16 | push:
17 | branches:
18 | - main
19 |
--------------------------------------------------------------------------------
/.github/workflows/lint-knip.yml:
--------------------------------------------------------------------------------
1 | jobs:
2 | lint_knip:
3 | runs-on: ubuntu-latest
4 | steps:
5 | - uses: actions/checkout@v4
6 | - uses: ./.github/actions/prepare
7 | - run: pnpm lint:knip
8 |
9 | name: Lint Knip
10 |
11 | on:
12 | pull_request: ~
13 | push:
14 | branches:
15 | - main
16 |
--------------------------------------------------------------------------------
/.github/workflows/lint-markdown.yml:
--------------------------------------------------------------------------------
1 | jobs:
2 | lint_markdown:
3 | runs-on: ubuntu-latest
4 | steps:
5 | - uses: actions/checkout@v4
6 | - uses: ./.github/actions/prepare
7 | - run: pnpm lint:md
8 |
9 | name: Lint Markdown
10 |
11 | on:
12 | pull_request: ~
13 | push:
14 | branches:
15 | - main
16 |
--------------------------------------------------------------------------------
/.github/workflows/lint-package-json.yml:
--------------------------------------------------------------------------------
1 | jobs:
2 | lint_package_json:
3 | runs-on: ubuntu-latest
4 | steps:
5 | - uses: actions/checkout@v4
6 | - uses: ./.github/actions/prepare
7 | - run: pnpm lint:package-json
8 |
9 | name: Lint Package JSON
10 |
11 | on:
12 | pull_request: ~
13 | push:
14 | branches:
15 | - main
16 |
--------------------------------------------------------------------------------
/.github/workflows/lint-packages.yml:
--------------------------------------------------------------------------------
1 | jobs:
2 | lint_packages:
3 | runs-on: ubuntu-latest
4 | steps:
5 | - uses: actions/checkout@v4
6 | - uses: ./.github/actions/prepare
7 | - run: pnpm lint:packages
8 |
9 | name: Lint Packages
10 |
11 | on:
12 | pull_request: ~
13 | push:
14 | branches:
15 | - main
16 |
--------------------------------------------------------------------------------
/.github/workflows/lint-spelling.yml:
--------------------------------------------------------------------------------
1 | jobs:
2 | lint_spelling:
3 | runs-on: ubuntu-latest
4 | steps:
5 | - uses: actions/checkout@v4
6 | - uses: ./.github/actions/prepare
7 | - run: pnpm lint:spelling
8 |
9 | name: Lint spelling
10 |
11 | on:
12 | pull_request: ~
13 | push:
14 | branches:
15 | - main
16 |
--------------------------------------------------------------------------------
/.github/workflows/lint.yml:
--------------------------------------------------------------------------------
1 | jobs:
2 | lint:
3 | runs-on: ubuntu-latest
4 | steps:
5 | - uses: actions/checkout@v4
6 | - uses: ./.github/actions/prepare
7 | - run: pnpm lint
8 |
9 | name: Lint
10 |
11 | on:
12 | pull_request: ~
13 | push:
14 | branches:
15 | - main
16 |
--------------------------------------------------------------------------------
/.github/workflows/post-release.yml:
--------------------------------------------------------------------------------
1 | jobs:
2 | post_release:
3 | runs-on: ubuntu-latest
4 | steps:
5 | - uses: actions/checkout@v4
6 | with:
7 | fetch-depth: 0
8 | - run: echo "npm_version=$(npm pkg get version | tr -d '"')" >> "$GITHUB_ENV"
9 | - uses: apexskier/github-release-commenter@v1
10 | with:
11 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
12 | comment-template: |
13 | :tada: This is included in version {release_link} :tada:
14 |
15 | The release is available on:
16 |
17 | * [GitHub releases](https://github.com/mcnaveen/Cart/releases/tag/{release_tag})
18 | * [npm package (@latest dist-tag)](https://www.npmjs.com/package/Cart/v/${{ env.npm_version }})
19 |
20 | Cheers! 📦🚀
21 |
22 | name: Post Release
23 |
24 | on:
25 | release:
26 | types:
27 | - published
28 |
--------------------------------------------------------------------------------
/.github/workflows/pr-review-requested.yml:
--------------------------------------------------------------------------------
1 | jobs:
2 | pr_review_requested:
3 | runs-on: ubuntu-latest
4 | steps:
5 | - uses: actions-ecosystem/action-remove-labels@v1
6 | with:
7 | labels: "status: waiting for author"
8 | - if: failure()
9 | run: |
10 | echo "Don't worry if the previous step failed."
11 | echo "See https://github.com/actions-ecosystem/action-remove-labels/issues/221."
12 |
13 | name: PR Review Requested
14 |
15 | on:
16 | pull_request_target:
17 | types:
18 | - review_requested
19 |
20 | permissions:
21 | pull-requests: write
22 |
--------------------------------------------------------------------------------
/.github/workflows/prettier.yml:
--------------------------------------------------------------------------------
1 | jobs:
2 | prettier:
3 | runs-on: ubuntu-latest
4 | steps:
5 | - uses: actions/checkout@v4
6 | - uses: ./.github/actions/prepare
7 | - run: pnpm format --list-different
8 |
9 | name: Prettier
10 |
11 | on:
12 | pull_request: ~
13 | push:
14 | branches:
15 | - main
16 |
--------------------------------------------------------------------------------
/.github/workflows/release.yml:
--------------------------------------------------------------------------------
1 | concurrency:
2 | group: ${{ github.workflow }}
3 |
4 | jobs:
5 | release:
6 | runs-on: ubuntu-latest
7 | steps:
8 | - uses: actions/checkout@v4
9 | with:
10 | fetch-depth: 0
11 | ref: main
12 | - uses: ./.github/actions/prepare
13 | - run: pnpm build
14 | - run: git config user.name "${GITHUB_ACTOR}"
15 | - run: git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
16 | - env:
17 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
18 | run: npm config set //registry.npmjs.org/:_authToken $NPM_TOKEN
19 | - name: Delete branch protection on main
20 | uses: actions/github-script@v6.4.1
21 | with:
22 | github-token: ${{ secrets.ACCESS_TOKEN }}
23 | script: |
24 | try {
25 | await github.request(
26 | `DELETE /repos/mcnaveen/Cart/branches/main/protection`,
27 | );
28 | } catch (error) {
29 | if (!error.message?.includes?.("Branch not protected")) {
30 | throw error;
31 | }
32 | }
33 | - env:
34 | GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
35 | run: |
36 | if pnpm run should-semantic-release ; then
37 | pnpm release-it --verbose
38 | fi
39 | - if: always()
40 | name: Recreate branch protection on main
41 | uses: actions/github-script@v6.4.1
42 | with:
43 | github-token: ${{ secrets.ACCESS_TOKEN }}
44 | script: |
45 | github.request(
46 | `PUT /repos/mcnaveen/Cart/branches/main/protection`,
47 | {
48 | allow_deletions: false,
49 | allow_force_pushes: true,
50 | allow_fork_pushes: false,
51 | allow_fork_syncing: true,
52 | block_creations: false,
53 | branch: "main",
54 | enforce_admins: false,
55 | owner: "mcnaveen",
56 | repo: "Cart",
57 | required_conversation_resolution: true,
58 | required_linear_history: false,
59 | required_pull_request_reviews: null,
60 | required_status_checks: {
61 | checks: [
62 | { context: "build" },
63 | { context: "compliance" },
64 | { context: "lint" },
65 | { context: "lint_knip" },
66 | { context: "lint_markdown" },
67 | { context: "lint_package_json" },
68 | { context: "lint_packages" },
69 | { context: "lint_spelling" },
70 | { context: "prettier" },
71 | { context: "test" },
72 | ],
73 | strict: false,
74 | },
75 | restrictions: null,
76 | }
77 | );
78 |
79 | name: Release
80 |
81 | on:
82 | push:
83 | branches:
84 | - main
85 |
86 | permissions:
87 | contents: write
88 | id-token: write
89 |
--------------------------------------------------------------------------------
/.github/workflows/tsc.yml:
--------------------------------------------------------------------------------
1 | jobs:
2 | type_check:
3 | runs-on: ubuntu-latest
4 | steps:
5 | - uses: actions/checkout@v4
6 | - uses: ./.github/actions/prepare
7 | - run: pnpm tsc
8 |
9 | name: Type Check
10 |
11 | on:
12 | pull_request: ~
13 | push:
14 | branches:
15 | - main
16 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | coverage/
2 | lib/
3 | node_modules/
4 |
--------------------------------------------------------------------------------
/.husky/.gitignore:
--------------------------------------------------------------------------------
1 | _
2 |
--------------------------------------------------------------------------------
/.husky/pre-commit:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | . "$(dirname "$0")/_/husky.sh"
3 | npx lint-staged
4 |
--------------------------------------------------------------------------------
/.markdownlint.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "markdownlint/style/prettier",
3 | "first-line-h1": false,
4 | "no-inline-html": false
5 | }
6 |
--------------------------------------------------------------------------------
/.markdownlintignore:
--------------------------------------------------------------------------------
1 | .github/CODE_OF_CONDUCT.md
2 | CHANGELOG.md
3 | lib/
4 | node_modules/
5 | docs/
--------------------------------------------------------------------------------
/.npmpackagejsonlintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "npm-package-json-lint-config-default",
3 | "rules": { "require-description": "error", "require-license": "error" }
4 | }
5 |
--------------------------------------------------------------------------------
/.nvmrc:
--------------------------------------------------------------------------------
1 | 18.18.0
2 |
--------------------------------------------------------------------------------
/.prettierignore:
--------------------------------------------------------------------------------
1 | .all-contributorsrc
2 | coverage/
3 | lib/
4 | pnpm-lock.yaml
5 | docs/
--------------------------------------------------------------------------------
/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "http://json.schemastore.org/prettierrc",
3 | "overrides": [
4 | { "files": ".*rc", "options": { "parser": "json" } },
5 | { "files": ".nvmrc", "options": { "parser": "yaml" } }
6 | ],
7 | "plugins": ["prettier-plugin-curly", "prettier-plugin-packagejson"],
8 | "useTabs": true
9 | }
10 |
--------------------------------------------------------------------------------
/.release-it.json:
--------------------------------------------------------------------------------
1 | {
2 | "git": {
3 | "commitMessage": "chore: release v${version}",
4 | "requireCommits": true
5 | },
6 | "github": {
7 | "autoGenerate": true,
8 | "release": true,
9 | "releaseName": "v${version}"
10 | },
11 | "npm": { "publishArgs": ["--provenance"] },
12 | "plugins": {
13 | "@release-it/conventional-changelog": {
14 | "infile": "CHANGELOG.md",
15 | "preset": "angular"
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/.vscode/extensions.json:
--------------------------------------------------------------------------------
1 | {
2 | "recommendations": [
3 | "DavidAnson.vscode-markdownlint",
4 | "dbaeumer.vscode-eslint",
5 | "esbenp.prettier-vscode",
6 | "streetsidesoftware.code-spell-checker"
7 | ]
8 | }
9 |
--------------------------------------------------------------------------------
/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | "configurations": [
3 | {
4 | "args": ["run", "${relativeFile}"],
5 | "autoAttachChildProcesses": true,
6 | "console": "integratedTerminal",
7 | "name": "Debug Current Test File",
8 | "program": "${workspaceRoot}/node_modules/vitest/vitest.mjs",
9 | "request": "launch",
10 | "skipFiles": ["/**", "**/node_modules/**"],
11 | "smartStep": true,
12 | "type": "node"
13 | }
14 | ],
15 | "version": "0.2.0"
16 | }
17 |
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "editor.codeActionsOnSave": { "source.fixAll.eslint": true },
3 | "editor.defaultFormatter": "esbenp.prettier-vscode",
4 | "editor.formatOnSave": true,
5 | "editor.rulers": [80],
6 | "eslint.probe": [
7 | "javascript",
8 | "javascriptreact",
9 | "json",
10 | "jsonc",
11 | "markdown",
12 | "typescript",
13 | "typescriptreact",
14 | "yaml"
15 | ],
16 | "eslint.rules.customizations": [{ "rule": "*", "severity": "warn" }],
17 | "typescript.tsdk": "node_modules/typescript/lib"
18 | }
19 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | ## [1.1.2](https://github.com/mcnaveen/cart/compare/1.1.1...1.1.2) (2023-10-27)
2 |
3 | ### Bug Fixes
4 |
5 | - **storage:** :bug: fix storage not working in react-native ([7337df9](https://github.com/mcnaveen/cart/commit/7337df933339cd1f70d76cf1aa067ecc0b18ab22))
6 |
7 | ## [1.1.1](https://github.com/mcnaveen/cart/compare/1.1.0...1.1.1) (2023-09-23)
8 |
9 | # 1.1.0 (2023-09-22)
10 |
11 | ### Features
12 |
13 | - **core:** :sparkles: initial release ([fa3db1e](https://github.com/mcnaveen/cart/commit/fa3db1e6b0e719db44ee2c6c74cc049dd9cdb630))
14 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | # MIT License
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining
4 | a copy of this software and associated documentation files (the
5 | 'Software'), to deal in the Software without restriction, including
6 | without limitation the rights to use, copy, modify, merge, publish,
7 | distribute, sublicense, and/or sell copies of the Software, and to
8 | permit persons to whom the Software is furnished to do so, subject to
9 | the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be
12 | included in all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
))` |
11 | | `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 });` |
12 | | `decreaseItem` | `function` | - | Decreases the quantity of an item in the shopping cart or removes it if the quantity becomes zero. | `decreaseItem('product1', 1);` |
13 | | `removeFromCart` | `function` | - | Removes an item from the shopping cart. | `removeFromCart('product1');` |
14 | | `clearCart` | `function` | - | Clears all items from the shopping cart. | `clearCart();` |
15 |
--------------------------------------------------------------------------------
/docs/pages/index.mdx:
--------------------------------------------------------------------------------
1 | # Introduction
2 |
3 | Welcome to Cart! 🛒 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.
4 |
5 |
6 | ## What is Cart?
7 |
8 |
9 | An online shopping cart is like a virtual basket for your online purchases. It helps you add items, review them, and make payments easily. However, building one from scratch can be tough and time-consuming. It requires a lot of coding and might have more bugs or security issues.
10 |
11 |
12 | ## Example
13 |
14 | > Please note that the cart library is a headless, means only the cart functions will be provided. No UI, No styles. Below one I created the UI for demo purpose. You can test using the below example.
15 |
16 | import {MyCart} from "../components/mycart.tsx"
17 |
18 |
--------------------------------------------------------------------------------
/docs/pages/installation.mdx:
--------------------------------------------------------------------------------
1 | # Installation
2 |
3 | A Cart library can be installed on your JavaScript projects including Reactjs, Nextjs and so on just with a single line of command.
4 |
5 | - [View NPM](https://www.npmjs.com/package/cart)
6 |
7 | ```bash
8 | # npm
9 | npm install cart --save
10 |
11 | # yarn
12 | yarn add cart
13 |
14 | #pnpm
15 | pnpm add cart
16 |
17 | # bun
18 | bun install cart
19 | ```
--------------------------------------------------------------------------------
/docs/pages/usage/nextjs.mdx:
--------------------------------------------------------------------------------
1 | # Using with Nextjs
2 |
3 | ### Intro
4 | Once you have done with the Installation, All you have to do is to Import `useCart` hook and `withSSR` in your Cart Component
5 |
6 | Then create a new file called `mycart.jsx` and use the below example code.
7 |
8 | > If you're using App Directory, make sure you have `"use client"` directive at the top.
9 |
10 | Feel free to remove the `types` if you're using JavaScript.
11 |
12 | ### Example
13 |
14 | ```tsx filename="mycart.tsx" copy
15 | 'use client';
16 |
17 | import React from 'react';
18 | import { useCart, withSSR, type CartItems, type CartState } from 'cart';
19 | interface Product {
20 | productId: string;
21 | name: string;
22 | price: number;
23 | }
24 |
25 | const products: Product[] = [
26 | {
27 | productId: '123',
28 | name: 'Product 1',
29 | price: 10,
30 | },
31 | {
32 | productId: '456',
33 | name: 'Product 2',
34 | price: 15,
35 | },
36 | {
37 | productId: '789',
38 | name: 'Product 3',
39 | price: 20,
40 | },
41 | ];
42 |
43 | export function MyCart() {
44 | // For using with SSR, Wrap the useCart using withSSR like below
45 | const cart: CartState = withSSR(useCart, (state) => state);
46 |
47 | const handleToggle = () => {
48 | cart?.toggleCart?.();
49 | };
50 |
51 | const addItem = (product: CartItems) => {
52 | cart?.addToCart?.(product);
53 | };
54 |
55 | const subtractItem = (productId: string) => {
56 | cart?.decreaseItem?.(productId, 1);
57 | };
58 |
59 | return (
60 |