{"id":15362233,"url":"https://github.com/doug-wade/idd","last_synced_at":"2026-02-06T13:37:14.567Z","repository":{"id":57271131,"uuid":"62691539","full_name":"doug-wade/idd","owner":"doug-wade","description":"Injection of Dependencies through Destructuring","archived":false,"fork":false,"pushed_at":"2020-05-01T03:21:05.000Z","size":90,"stargazers_count":1,"open_issues_count":6,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-16T05:08:59.071Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/doug-wade.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-07-06T04:40:23.000Z","updated_at":"2018-12-18T02:56:45.000Z","dependencies_parsed_at":"2022-09-06T14:50:27.001Z","dependency_job_id":null,"html_url":"https://github.com/doug-wade/idd","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/doug-wade/idd","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doug-wade%2Fidd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doug-wade%2Fidd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doug-wade%2Fidd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doug-wade%2Fidd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/doug-wade","download_url":"https://codeload.github.com/doug-wade/idd/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/doug-wade%2Fidd/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266586905,"owners_count":23952204,"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","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-01T12:59:26.594Z","updated_at":"2026-02-06T13:37:14.515Z","avatar_url":"https://github.com/doug-wade.png","language":"JavaScript","readme":"# idd ![idd travis build status](https://travis-ci.org/doug-wade/idd.svg) ![idd appveyor build status](https://ci.appveyor.com/api/projects/status/github/doug-wade/idd?branch=master\u0026svg=true) ![idd codecov status](https://img.shields.io/codecov/c/github/doug-wade/idd.svg)\n\nA dependency injection system with destructuring.  Combines a common pattern\nof using a single destructuring argument to avoid confusing the order of\narguments to high-parity functions, possibly with many optional parameters.\n\n\n## Getting Started\n\nTo install the dependency injection system, use `npm install`\n\n```shell\nnpm install --save idd\n```\n\nThen, from other peer directories, you can require the files as properties\non the directory's default export\n\nlib/config.js\n\n```javascript\nexport default function () {\n\treturn {\n\t\tlanguage: 'ru-ru',\n\t\tlevel: 'info'\n\t};\n};\n```\n\nlib/greeter.js\n\n```javascript\nexport default ({config, Logger}) =\u003e {\n\tconst logger = new Logger();\n\treturn {\n\t\tgreet: () =\u003e {\n\t\t\tif (config.language === 'en-us') {\n\t\t\t\tlogger.log('Hello World!');\n\t\t\t} else if (config.language === 'ru-ru') {\n\t\t\t\tlogger.log('Привет, мир!');\n\t\t\t} else {\n\t\t\t\tlogger.error('unsupported language ' + config.language);\n\t\t\t}\n\t\t}\n\t};\n};\n```\n\nlib/Logger.js\n\n```javascript\nimport chalk from 'chalk';\n\nexport default () =\u003e class Logger {\n\tconstructor() {\n\t\tthis.level = process.env.LEVEL;\n\t}\n\tlog(msg) {\n\t\tif (this.level !== 'quiet') {\n\t\t\tconsole.log(msg);\n\t\t}\n\t}\n\terror(msg) {\n\t\tif (this.level !== 'quiet' \u0026\u0026 this.level !== 'silent') {\n\t\t\tchalk.red(msg);\n\t\t}\n\t}\n};\n```\n\nindex.js\n\n```javascript\nimport path from 'path';\nimport idd from '../../../..';\n\nconst {greeter} = idd(path.join(__dirname, 'lib'));\n\ngreeter.greet();\n```\n\nThen the output would be 'Hello World!'.  If you were to change config to be\ninstead \t\n\n```javascript\nexport default function() {\n\tlanguage: 'ru-ru',\n\tlevel: 'error'\n}\n```\n\nThen the output would be 'Привет, мир!'.\n\n\n## Testing\n\nA good dependency injection system should make unit testing easy.  To mock out\nyour dependencies, just provide an optional third option with the mocks\n\n```javascript\nimport {sinon} from 'sinon';\nimport idd from 'idd';\nimport test from 'ava';\n\ntest('Greet was called', t =\u003e {\n\tconst greet = sinon.spy();\n\tconst config = { greeting: 'Hello World!'};\n\tconst {greeter} = idd('./lib', { config, greet });\n\n\tgreeter.greet();\n\n\tt.true(greet.calledOnce);\n});\n```\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoug-wade%2Fidd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdoug-wade%2Fidd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdoug-wade%2Fidd/lists"}