{"_id":"@dmitriyzverev/pod","name":"@dmitriyzverev/pod","dist-tags":{"latest":"1.0.0-dev.0"},"versions":{"1.0.0-dev.0":{"name":"@dmitriyzverev/pod","version":"1.0.0-dev.0","homepage":"https://gitlab.com/DmitriyZverev/pod","bugs":{"url":"https://gitlab.com/DmitriyZverev/pod/-/issues","email":"opensource@dmitriyzverev.ru"},"license":"MIT","author":{"name":"Dmitriy Zverev","email":"opensource@dmitriyzverev.ru"},"repository":{"type":"git","url":"git+https://gitlab.com/DmitriyZverev/pod.git"},"scripts":{"build":"rm -rf .package && npx tsc --outDir .package && cp package.json LICENSE README.md .package","eslint:fix":"npx eslint --no-error-on-unmatched-pattern --fix --ext .ts,.js .","eslint:check":"npx eslint --no-error-on-unmatched-pattern --ext .ts,.js .","prettier:fix":"npx prettier --write \"**/*.{ts,js,json,yml,md}\"","prettier:check":"npx prettier --check \"**/*.{ts,js,json,yml,md}\"","test":"npx jest -c .jestconfig.json"},"dependencies":{"tslib":"^2.0.0"},"devDependencies":{"@dmitriyzverev/eslint-config":"3.0.0","@dmitriyzverev/prettier-config":"1.0.1","@dmitriyzverev/typescript-config":"1.1.1","@types/jest":"29.5.0","@types/node":"16.18.23","eslint":"8.38.0","jest":"29.5.0","prettier":"2.8.7","ts-jest":"29.1.0","typescript":"5.0.4"},"types":"./index.d.ts","gitHead":"3a62924dfdb5ee567bee34291e827a3abe8d7418","description":"_Simple implementation of Service Locator pattern with singletons and lazy loading_","_id":"@dmitriyzverev/pod@1.0.0-dev.0","_nodeVersion":"16.20.1","_npmVersion":"8.19.4","dist":{"integrity":"sha512-QMRlyVXkz/yuoDPdRZPWvQf5MYGmr8banfpEi7WCzIm3b8p7PyrzY4DDHOUOr5mD7R65CrG7wxpYVIpRbUZ0vQ==","shasum":"5f63365280baefb7111d886db867ac4bcfaec711","tarball":"https://registry.npmjs.org/@dmitriyzverev/pod/-/pod-1.0.0-dev.0.tgz","fileCount":13,"unpackedSize":10069,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAH08nZOTuRldokdH6Uuiaj0x4HCakzE1t+6LlhIcdxgAiEA3I8nydacpt36+5fKFv8XZIpwAPMqQJDEBMba75YOYhA="}]},"_npmUser":{"name":"dmitriyzverev","email":"zver.lockon@mail.ru"},"directories":{},"maintainers":[{"name":"dmitriyzverev","email":"zver.lockon@mail.ru"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/pod_1.0.0-dev.0_1688826144149_0.08705518841597293"},"_hasShrinkwrap":false}},"time":{"created":"2023-07-08T14:22:24.013Z","1.0.0-dev.0":"2023-07-08T14:22:24.339Z","modified":"2023-07-08T14:22:24.625Z"},"maintainers":[{"name":"dmitriyzverev","email":"zver.lockon@mail.ru"}],"description":"_Simple implementation of Service Locator pattern with singletons and lazy loading_","homepage":"https://gitlab.com/DmitriyZverev/pod","repository":{"type":"git","url":"git+https://gitlab.com/DmitriyZverev/pod.git"},"author":{"name":"Dmitriy Zverev","email":"opensource@dmitriyzverev.ru"},"bugs":{"url":"https://gitlab.com/DmitriyZverev/pod/-/issues","email":"opensource@dmitriyzverev.ru"},"license":"MIT","readme":"# @dmitriyzverev/pod\n\n_Simple implementation of Service Locator pattern with singletons and lazy\nloading_\n\n---\n\n## Intro\n\nThere are two main entities: pod and seed. Pod is a container for seeds. Seed is\na function that get pod as an argument and returns some value. Seed can use any\nother seed from pod as a dependency. It is a way to organize your code into\nsmall pieces, that can be easily tested and reused.\n\n## Usage\n\n1. Install dependencies:\n\n    ```bash\n    npm i -SE @dmitriyzverev/pod\n    ```\n\n2. Create pod and define your seeds inside:\n    ```ts\n    import {createPod} from '@dmitriyzverev/pod';\n    const pod = createPod({\n        seeds: {\n            get user() {\n                return {\n                    name: 'Bob',\n                };\n            },\n            get helloMessage() {\n                return `Hello, ${pod.user.name}!`; // use \"user\" seed as a dependency\n            },\n        },\n    });\n    ```\n    Now you can use any seed defined in pod:\n    ```ts\n    console.log(pod.helloMessage); // Hello, Bob!\n    ```\n\n## Advanced usage\n\n### Singletons\n\nBy default, each seed is a singleton. It will be created only once, and only if\nrequested. If you need to create a new seed instance for each seed request,\ndisable the seed singleton in the `singletons` property:\n\n```ts\nimport {createPod} from '@dmitriyzverev/pod';\nconst pod = createPod({\n    seeds: {\n        get user() {\n            return {\n                name: 'Bob',\n            };\n        },\n    },\n    singletons: {\n        user: false, // disable singleton for \"user\" seed\n    },\n});\nconsole.log(pod.user === pod.user); // false - each request creates a new instance\n```\n\n### Exclude and include seeds\n\nIf you need to exclude some seeds from pod, use `exclude` property:\n\n```ts\nimport {createPod} from '@dmitriyzverev/pod';\nconst pod = createPod({\n    seeds: {\n        get foo() {\n            return 'foo';\n        },\n        get bar() {\n            return 'bar';\n        },\n        get baz() {\n            return 'baz';\n        },\n    },\n});\nconst podWithoutFoo = pod.exclude('foo');\nconsole.log(podWithoutFoo.foo); // undefined\n```\n\nOr you can include only some seeds:\n\n```ts\nconst podWithFooAndBar = pod.include('foo', 'bar');\nconsole.log(podWithFooAndBar.foo); // 'foo'\nconsole.log(podWithFooAndBar.baz); // undefined\n```\n\nBoth `exclude` and `include` methods create a new pod instance, so you can use\nthem and don't worry about the original pod:\n\n```ts\nconsole.log(pod.foo); // 'foo' - still available in the original pod\n```\n","readmeFilename":"README.md"}