{"_id":"@bndl-io/context-providers-provider","_rev":"2-4487d53acae07b563ec1604e1958c25c","name":"@bndl-io/context-providers-provider","dist-tags":{"latest":"1.1.0"},"versions":{"1.0.0":{"name":"@bndl-io/context-providers-provider","version":"1.0.0","keywords":["react","context","typescript","provider","dependency-management","context-provider","react-context"],"author":{"name":"Ramon Gebben","email":"ramon@dahuis.nl"},"license":"MIT","_id":"@bndl-io/context-providers-provider@1.0.0","maintainers":[{"name":"pindakaasman","email":"ramon@ra-ge.net"}],"homepage":"https://github.com/DatHuis/-bndl-io-context-providers-provider#readme","bugs":{"url":"https://github.com/DatHuis/-bndl-io-context-providers-provider/issues"},"dist":{"shasum":"c81d79bfadb39f2dc82da7827acc22f6dd505e7e","tarball":"https://registry.npmjs.org/@bndl-io/context-providers-provider/-/context-providers-provider-1.0.0.tgz","fileCount":17,"integrity":"sha512-a3aVCkEAFvQOuLi5MxkLJdOkjj5Oj4hHktGDv4rnDwMUyt9Xx+bT2AgwcQLHn4jiSV0bhRPP1lr3ng2iqeULsg==","signatures":[{"sig":"MEQCIQCMw/2XJXIEVwdJWkN14hHt+IHOVHhU8QS+CaBUD2w0kQIfAMp278nIXWs40r+TQtAWVxQvXJ/uTmm1kd6Oy0+Z6A==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":23216},"main":"dist/index.js","types":"dist/index.d.ts","engines":{"node":">=14"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"scripts":{"test":"jest","build":"rm -rf dist/ && tsc","prepublishOnly":"npm run build"},"_npmUser":{"name":"pindakaasman","email":"ramon@ra-ge.net"},"repository":{"url":"git+https://github.com/DatHuis/-bndl-io-context-providers-provider.git","type":"git"},"_npmVersion":"10.8.2","description":"A React utility component for managing complex context dependencies. Automatically sorts and nests context providers based on dependencies, promoting clean and maintainable context usage patterns.","directories":{},"_nodeVersion":"20.18.0","_hasShrinkwrap":false,"devDependencies":{"jest":"^29.7.0","csstype":"^3.x","ts-jest":"^29.2.5","typescript":"^4.x","@types/jest":"^29.5.14","@types/react":"^18.3.12","@types/react-dom":"^18.3.1","@types/prop-types":"^15.x","@testing-library/react":"^16.0.1","jest-environment-jsdom":"^29.7.0","@testing-library/jest-dom":"^6.6.3"},"peerDependencies":{"react":"^17.0.0 || ^18.0.0 || ^19.0.0"},"_npmOperationalInternal":{"tmp":"tmp/context-providers-provider_1.0.0_1734688822009_0.15600573851308042","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@bndl-io/context-providers-provider","version":"1.0.1","keywords":["react","context","typescript","provider","dependency-management","context-provider","react-context"],"author":{"name":"Ramon Gebben","email":"ramon@dahuis.nl"},"license":"MIT","_id":"@bndl-io/context-providers-provider@1.0.1","maintainers":[{"name":"pindakaasman","email":"ramon@ra-ge.net"}],"homepage":"https://github.com/DatHuis/-bndl-io-context-providers-provider#readme","bugs":{"url":"https://github.com/DatHuis/-bndl-io-context-providers-provider/issues"},"dist":{"shasum":"6aa1af0d1a816135a6b6a28e1649d12da55bc747","tarball":"https://registry.npmjs.org/@bndl-io/context-providers-provider/-/context-providers-provider-1.0.1.tgz","fileCount":17,"integrity":"sha512-4fN2IPtx7LXDLH00skg3iSLMzemuPU2WqXIPAvSITug7ooPMsJqS3/GvZb9orwRlKv6lXhDt8wCtN4Q4br5B1Q==","signatures":[{"sig":"MEYCIQCLTIa8Z4jMwppCJyebhl0VpmOpAHl1dfp43bmDuW44NgIhANcwkMe4uxTUjg2AzJ3Cb+BF6lKXdlqi5y2IdIDE3z8e","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":23212},"main":"dist/index.js","types":"dist/index.d.ts","engines":{"node":">=14"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"scripts":{"test":"jest","build":"rm -rf dist/ && tsc","prepublishOnly":"npm run build"},"_npmUser":{"name":"pindakaasman","email":"ramon@ra-ge.net"},"repository":{"url":"git+https://github.com/DatHuis/-bndl-io-context-providers-provider.git","type":"git"},"_npmVersion":"10.8.2","description":"A React utility component for managing complex context dependencies. Automatically sorts and nests context providers based on dependencies, promoting clean and maintainable context usage patterns.","directories":{},"_nodeVersion":"20.18.0","_hasShrinkwrap":false,"devDependencies":{"jest":"^29.7.0","csstype":"^3.x","ts-jest":"^29.2.5","typescript":"^4.x","@types/jest":"^29.5.14","@types/react":"^18.3.12","@types/react-dom":"^18.3.1","@types/prop-types":"^15.x","@testing-library/react":"^16.0.1","jest-environment-jsdom":"^29.7.0","@testing-library/jest-dom":"^6.6.3"},"peerDependencies":{"react":"^17.0.0 || ^18.0.0 || ^19.0.0"},"_npmOperationalInternal":{"tmp":"tmp/context-providers-provider_1.0.1_1734689950886_0.381882756317383","host":"s3://npm-registry-packages-npm-production"}},"1.1.0":{"name":"@bndl-io/context-providers-provider","version":"1.1.0","description":"A React utility component for managing complex context dependencies. Automatically sorts and nests context providers based on dependencies, promoting clean and maintainable context usage patterns.","main":"dist/index.js","types":"dist/index.d.ts","exports":{".":{"import":"./dist/index.js","types":"./dist/index.d.ts"}},"scripts":{"build":"rm -rf dist/ && tsc","test":"jest","prepublishOnly":"npm run build"},"repository":{"type":"git","url":"git+https://github.com/DatHuis/-bndl-io-context-providers-provider.git"},"keywords":["react","context","typescript","provider","dependency-management","context-provider","react-context"],"author":{"name":"Ramon Gebben","email":"ramon@dahuis.nl"},"license":"MIT","peerDependencies":{"react":"^17.0.0 || ^18.0.0 || ^19.0.0"},"devDependencies":{"@testing-library/jest-dom":"^6.6.3","@testing-library/react":"^16.0.1","@types/jest":"^29.5.14","@types/prop-types":"^15.x","@types/react":"^18.3.12","@types/react-dom":"^18.3.1","csstype":"^3.x","jest":"^29.7.0","jest-environment-jsdom":"^29.7.0","ts-jest":"^29.2.5","typescript":"^4.x"},"engines":{"node":">=14"},"_id":"@bndl-io/context-providers-provider@1.1.0","gitHead":"0bfcbde28bea3b00c3cce90b651882cbf02d01f2","bugs":{"url":"https://github.com/DatHuis/-bndl-io-context-providers-provider/issues"},"homepage":"https://github.com/DatHuis/-bndl-io-context-providers-provider#readme","_nodeVersion":"20.18.0","_npmVersion":"10.8.2","dist":{"integrity":"sha512-+Nzw55+ggfPAMBcBeNOiEQd7eMa0Yxmtgn+QpP6Z9XVpOGa//qnos94PwQk+4OteYnMNtJQIvsaZXnoUfanAUw==","shasum":"695b8cd7ebe1254316788bb299c72024c172d21a","tarball":"https://registry.npmjs.org/@bndl-io/context-providers-provider/-/context-providers-provider-1.1.0.tgz","fileCount":21,"unpackedSize":29103,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHzVZtLBuD8bBa/5GUTNBHhWIJj++qkjkURKNCTSd24iAiADX48A6PXVbPCIDEKSpbbhmpQhlY+yMw1rdXvuortkkg=="}]},"_npmUser":{"name":"pindakaasman","email":"ramon@ra-ge.net"},"directories":{},"maintainers":[{"name":"pindakaasman","email":"ramon@ra-ge.net"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/context-providers-provider_1.1.0_1734696743495_0.3093058558202926"},"_hasShrinkwrap":false}},"time":{"created":"2024-12-20T10:00:21.854Z","modified":"2024-12-20T12:12:23.935Z","1.0.0":"2024-12-20T10:00:22.181Z","1.0.1":"2024-12-20T10:19:11.205Z","1.1.0":"2024-12-20T12:12:23.738Z"},"bugs":{"url":"https://github.com/DatHuis/-bndl-io-context-providers-provider/issues"},"author":{"name":"Ramon Gebben","email":"ramon@dahuis.nl"},"license":"MIT","homepage":"https://github.com/DatHuis/-bndl-io-context-providers-provider#readme","keywords":["react","context","typescript","provider","dependency-management","context-provider","react-context"],"repository":{"type":"git","url":"git+https://github.com/DatHuis/-bndl-io-context-providers-provider.git"},"description":"A React utility component for managing complex context dependencies. Automatically sorts and nests context providers based on dependencies, promoting clean and maintainable context usage patterns.","maintainers":[{"name":"pindakaasman","email":"ramon@ra-ge.net"}],"readme":"# @bndl-io/context-providers-provider\n\nA React utility component for managing complex context dependencies. Automatically sorts and nests context providers based on dependencies, promoting clean and maintainable patterns for context usage.\n\n## Why?\n\nReact applications often rely on multiple context providers to manage state, theming, authentication, and more. However, managing these providers can quickly lead to deeply nested and unmanageable component trees, especially when providers depend on one another.\n\n### Common Problems:\n\n1. **Context Hell**: Wrapping components in multiple layers of context providers makes the tree hard to read and maintain.\n2. **Dependency Issues**: Incorrect nesting of providers can lead to runtime errors or unexpected behavior.\n3. **Encapsulation**: Logic for initializing context values often leaks outside of dedicated components, making the code harder to reuse or test.\n\n### How `@bndl-io/context-providers-provider` Solves This:\n\n- Automatically **sorts providers** based on their dependencies.\n- Detects **circular dependencies** and throws helpful error messages.\n- Encourages encapsulation by requiring all context logic to reside in dedicated `ProviderComponents`.\n- Simplifies application structure by managing provider nesting for you.\n\n---\n\n## Installation\n\nInstall the library via npm:\n\n```bash\nnpm install @bndl-io/context-providers-provider\n```\n\nor with yarn:\n\n```bash\nyarn add @bndl-io/context-providers-provider\n```\n\n---\n\n## Usage\n\n### Define Your Providers\n\nEach provider is defined as an object with the following structure:\n\n```ts\ntype ProviderConfig = {\n  name: string;\n  C: (children: ReactNode) => JSX.Element; // The provider component\n  dependencies: string[]; // Names of other providers this provider depends on\n};\n```\n\nFor example:\n\n```tsx\nconst providers = [\n  {\n    name: 'Auth',\n    C: children => <AuthProvider>{children}</AuthProvider>,\n    dependencies: ['Theme'], // Auth depends on Theme\n  },\n  {\n    name: 'Theme',\n    C: children => <ThemeProvider>{children}</ThemeProvider>,\n    dependencies: [], // No dependencies\n  },\n  {\n    name: 'Config',\n    C: children => <ConfigProvider>{children}</ConfigProvider>,\n    dependencies: ['Auth'], // Config depends on Auth\n  },\n];\n```\n\n---\n\n### Wrap Your Application\n\nUse the `ContextProvidersProvider` to automatically sort and nest providers based on their dependencies:\n\n```tsx\nimport React from 'react';\nimport ContextProvidersProvider from '@bndl-io/context-providers-provider';\n\nconst providers = [\n  {\n    name: 'Auth',\n    C: children => <AuthProvider>{children}</AuthProvider>,\n    dependencies: ['Theme'],\n  },\n  {\n    name: 'Theme',\n    C: children => <ThemeProvider>{children}</ThemeProvider>,\n    dependencies: [],\n  },\n  {\n    name: 'Config',\n    C: children => <ConfigProvider>{children}</ConfigProvider>,\n    dependencies: ['Auth'],\n  },\n];\n\nconst App = () => {\n  return (\n    <ContextProvidersProvider providers={providers}>\n      <YourApp />\n    </ContextProvidersProvider>\n  );\n};\n```\n\n---\n\n### Example Output\n\nThe above setup would result in the following provider tree:\n\n```tsx\n<ThemeProvider>\n  <AuthProvider>\n    <ConfigProvider>\n      <YourApp />\n    </ConfigProvider>\n  </AuthProvider>\n</ThemeProvider>\n```\n\n---\n\n## API\n\n### `ContextProvidersProvider`\n\n#### Props:\n\n- `providers`: An array of `ProviderConfig` objects. Each config must include:\n  - `name`: A unique string identifying the provider.\n  - `C`: A function that renders the provider component, wrapping its children.\n  - `dependencies`: An array of strings identifying the providers this provider depends on.\n- `children`: The children to be rendered inside the nested providers.\n\n#### Errors:\n\n- Throws an error if a provider has dependencies that don’t exist.\n- Throws an error if circular dependencies are detected.\n\n---\n\n### `createContextProvidersProvider`\n\nA utility function to create a `ContextProvidersProvider` component dynamically.\n\n#### Usage:\n\n```tsx\nimport { createContextProvidersProvider } from '@bndl-io/context-providers-provider';\n\nconst providers = [\n  {\n    name: 'Auth',\n    C: children => <AuthProvider>{children}</AuthProvider>,\n    dependencies: ['Theme'],\n  },\n  {\n    name: 'Theme',\n    C: children => <ThemeProvider>{children}</ThemeProvider>,\n    dependencies: [],\n  },\n  {\n    name: 'Config',\n    C: children => <ConfigProvider>{children}</ConfigProvider>,\n    dependencies: ['Auth'],\n  },\n];\n\nconst ContextWrapper = createContextProvidersProvider({ providers });\n\nconst App = () => (\n  <ContextWrapper>\n    <YourApp />\n  </ContextWrapper>\n);\n\nexport default App;\n```\n\n#### Description:\n\n- Dynamically creates a `ContextProvidersProvider` wrapper with the given providers.\n- Simplifies reusability by abstracting the setup of the `ContextProvidersProvider`.\n\n---\n\n## License\n\nMIT License\n\nCopyright (c) DatHuis B.V.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n---\n\n## Contributing\n\nWe welcome contributions! Please open an issue or submit a pull request for any bugs, features, or enhancements.\n","readmeFilename":"README.md"}