{"id":16773843,"url":"https://github.com/ziflex/namespaces","last_synced_at":"2025-07-17T21:39:49.677Z","repository":{"id":57307689,"uuid":"43978964","full_name":"ziflex/namespaces","owner":"ziflex","description":"Angular-flavored dependency container","archived":false,"fork":false,"pushed_at":"2016-12-17T22:43:23.000Z","size":2269,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-05T21:40:27.368Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://ziflex.github.io/namespaces/","language":"JavaScript","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/ziflex.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-10-09T20:37:11.000Z","updated_at":"2016-11-18T00:13:34.000Z","dependencies_parsed_at":"2022-08-31T04:22:56.843Z","dependency_job_id":null,"html_url":"https://github.com/ziflex/namespaces","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/ziflex/namespaces","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ziflex%2Fnamespaces","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ziflex%2Fnamespaces/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ziflex%2Fnamespaces/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ziflex%2Fnamespaces/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ziflex","download_url":"https://codeload.github.com/ziflex/namespaces/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ziflex%2Fnamespaces/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265663428,"owners_count":23807468,"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":[],"created_at":"2024-10-13T06:47:10.754Z","updated_at":"2025-07-17T21:39:49.634Z","avatar_url":"https://github.com/ziflex.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# namespaces\r\n\u003e Universal registry\r\n\r\nAngular-flavored DI container.\r\n\r\n[![npm version](https://badge.fury.io/js/namespaces-js.svg)](https://www.npmjs.com/package/namespaces-js)\r\n[![Build Status](https://secure.travis-ci.org/ziflex/namespaces.svg?branch=master)](http://travis-ci.org/ziflex/namespaces)\r\n[![Coverage Status](https://coveralls.io/repos/github/ziflex/namespaces/badge.svg?branch=master)](https://coveralls.io/github/ziflex/namespaces)\r\n\r\n## API\r\nYou can find API [here](http://ziflex.github.io/namespaces)\r\n\r\n## Install\r\n\r\n```sh\r\n\r\n    $ npm install --save namespaces-js\r\n\r\n```\r\n\r\n## Motivation\r\n\r\nWe all love testable and modular code. In most cases it means that every piece of you system\r\ndepends on other pieces and these dependencies should be injected if we want to make our system testable and flexible. But wiring everything up might be a very tedious task with creating multiple instances, passing them into others and then, once requirements or designed changed, finding, replacing, updating and etc...\r\nSo, that's why ``namespaces`` package was created - to solve this issue. It allows you organize your system parts and easily define their dependencies by creating an application container with namespaces.\r\n\r\nIts design is inspired by Angular v1 DI, therefore most of the concepts might be familiar for those of you who are familiar with Angular v1, but some are new.\r\n\r\n## Usage\r\n\r\n### Just as a container\r\n\r\n#### Stores values\r\n\r\n```javascript\r\n\r\nvar Container = require('namespaces-js');\r\nvar container = new Container();\r\n\r\ncontainer.const('foo', 'bar');\r\n\r\nconst foo = container.resolve('foo');\r\n\r\nconsole.log(foo); // -\u003e 'bar'\r\n\r\n```\r\n\r\n#### Creates singletons\r\n\r\n```javascript\r\n\r\nvar Container = require('namespaces-js');\r\nvar container = new Container();\r\n\r\ncontainer.factory('foo', () =\u003e {\r\n    return { do: =\u003e 'bar' };\r\n});\r\n\r\nconst foo1 = container.resolve('foo');\r\nconst foo2 = container.resolve('foo');\r\n\r\nconsole.log(foo1 === foo2); // -\u003e true\r\n\r\n```\r\n\r\n### As a container with dependencies\r\n\r\n#### Resolves dependencies by module name\r\n\r\n```javascript\r\n\r\nvar Container = require('namespaces-js');\r\nvar container = new Container();\r\n\r\ncontainer.factory('foo', () =\u003e 'bar');\r\ncontainer.factory('qaz', ['foo'], (foo) =\u003e `${foo}-fighter`);\r\n\r\nconst qaz = container.resolve('qaz');\r\n\r\nconsole.log(qaz); // 'bar-fighter';\r\n\r\n```\r\n\r\n#### Resolves dependencies by custom resolver\r\n\r\n```javascript\r\n\r\nvar Container = require('namespaces-js');\r\nvar container = new Container();\r\n\r\ncontainer.factory('foo', () =\u003e 'bar');\r\ncontainer.factory('qaz', [\r\n    'foo',\r\n    function customResolver() {\r\n        return 'wsx';\r\n    }\r\n], (foo, something) =\u003e {\r\n    return `${foo}-${something}`;\r\n});\r\n\r\nconst qaz = container.resolve('qaz');\r\n\r\nconsole.log(qaz); // 'bar-wsx';\r\n\r\n```\r\n\r\n### Creates nested containers with namespaces\r\n\r\n```javascript\r\n\r\n    var Container = require('namespaces-js');\r\n    var container = new Container();\r\n\r\n    container.value('foo', 'bar');;\r\n    container.namespace('my-namespace').value('foo', 'qaz');\r\n    container.namespace('my-namespace/sub-namespace-1').value('foo', 'qaz');\r\n\r\n    const foo = container.resolve('foo');\r\n    const foo2 = container.resolve('my-namespace/foo');\r\n    const foo3 = container.resolve('my-namespace/sub-namespace/foo');\r\n\r\n    console.log(foo === foo2); // false\r\n\r\n\r\n    container.namespace('my-namespace').namespace('sub-namespace-2').factory('foobar', [\r\n        'foo',\r\n        'my-namespace-1/foo'\r\n    ], (foo, foo2) =\u003e {\r\n        return `${foo} !== ${foo2}`;\r\n    });\r\n\r\n    const foobar = container.resolve('my-namespace/sub-namespace-2/foobar');\r\n\r\n    console.log(foobar); // 'bar !== qaz';\r\n\r\n```\r\n\r\n### Namespace Helper\r\n\r\nIt comes with a handy utility function that converts a given namespace tree into function tree.\r\nEach function-node of the tree recieves a module name and returns a full path of it.\r\n\r\n````javascript\r\n\r\n    var namespaces = Container.map({\r\n        a: 'b',\r\n        c: ['d', 'e', { f: ['g', 'h'] }]\r\n    });\r\n\r\n    var container = new Container();\r\n\r\n    container.namespace(namespaces.a()).value('foo', 'bar');\r\n    container.namespace(namespaces.b()).factory('foo', () =\u003e 'bar');\r\n    container.namespace(namespaces.c()).factory('foo', () =\u003e 'bar');\r\n    container.namespace(namespaces.c.f.g()).value('foo', 'bar');\r\n\r\n    container.resolve(namespaces.a('foo'));\r\n    container.resolve(namespaces.c.f.g('foo'));\r\n\r\n````     \r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fziflex%2Fnamespaces","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fziflex%2Fnamespaces","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fziflex%2Fnamespaces/lists"}