{"id":20195842,"url":"https://github.com/ralphv/require-inject-scope","last_synced_at":"2025-03-03T08:13:06.795Z","repository":{"id":57354280,"uuid":"89126299","full_name":"ralphv/require-inject-scope","owner":"ralphv","description":"Inject scoped variables when requiring a file in Node.js","archived":false,"fork":false,"pushed_at":"2017-04-23T11:16:31.000Z","size":11,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-24T02:53:27.085Z","etag":null,"topics":["inject","nodejs","require","scope","variables"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ralphv.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog","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":"2017-04-23T07:58:56.000Z","updated_at":"2018-04-27T23:48:37.000Z","dependencies_parsed_at":"2022-09-26T20:21:50.882Z","dependency_job_id":null,"html_url":"https://github.com/ralphv/require-inject-scope","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ralphv%2Frequire-inject-scope","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ralphv%2Frequire-inject-scope/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ralphv%2Frequire-inject-scope/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ralphv%2Frequire-inject-scope/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ralphv","download_url":"https://codeload.github.com/ralphv/require-inject-scope/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241629772,"owners_count":19993710,"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":["inject","nodejs","require","scope","variables"],"created_at":"2024-11-14T04:19:22.687Z","updated_at":"2025-03-03T08:13:06.762Z","avatar_url":"https://github.com/ralphv.png","language":"JavaScript","readme":"## require-inject-scope - Inject scoped variables when requiring a file.\n\n[![NPM](https://nodei.co/npm/require-inject-scope.png?mini=true)](https://nodei.co/npm/require-inject-scope/)\n\n[![Build Status](https://travis-ci.org/ralphv/require-inject-scope.svg?branch=master)](https://travis-ci.org/ralphv/require-inject-scope)\n[![Coverage Status](https://coveralls.io/repos/github/ralphv/require-inject-scope/badge.svg?branch=master)](https://coveralls.io/github/ralphv/require-inject-scope?branch=master)\n        \n* [What is it?](#what-is-it)\n* [Getting started](#getting-started)\n* [Usage](#usage)\n* [License](#License)\n* [Changelog](#Changelog)\n\n## What is it\n\nThe built in `require` of Node.js does not have a way to allow you to inject scoped variables. \nThe variables `module`, `exports`, `__dirname`, `__filename`... are available in the context of a required file but there is no easy way to provide your own variables. \n\nMany developers will revert to using either globally defined variables or using singleton variables like `globals`, but neither of these are best practices.\n\nThis library allows you to inject your own variables to the context of the required file.\n\n## Getting started\n\n    $ npm install --save require-inject-scope\n\n## Usage\n\nrequire this library as early as possible in your own code.\n\n```javascript\nrequire(\"require-inject-scope\");\n```\n\nrequire will work normally as expected.\n\nWhen you need to inject variables into a scope, instead of calling `require` with one parameter which \nis the `path`, you call it using an array with exactly two elements. \nThe first element is the standard `path` and the second element will be an object having properties as variable names to inject and their values.\n\nThis is most useful when creating a plugin architecture where you want to provide the plugins a list of defined variables without requiring your plugins to require them manually.\n\nexample:\n\n```javascript\nrequire([\"./sample.js\", {\"$config\":configObject, \"$helper\": helperObject}]);\n```\n\nThe file sample.js will have the two variables `$config` and `$helper` defined in its scope similar to the standard available variables.\n\n### License\n\nrequire-inject-scope is licensed under the [MIT](https://github.com/ralphv/require-inject-scope/raw/master/LICENSE).\n\n### Changelog\n\n* 1.0.0: Initial version\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fralphv%2Frequire-inject-scope","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fralphv%2Frequire-inject-scope","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fralphv%2Frequire-inject-scope/lists"}