{"id":13670463,"url":"https://github.com/wilsonlewis/require-context","last_synced_at":"2025-04-27T13:32:17.176Z","repository":{"id":57354212,"uuid":"106194818","full_name":"wilsonlewis/require-context","owner":"wilsonlewis","description":"Require a group of modules for Node.js using Webpack syntax.","archived":false,"fork":false,"pushed_at":"2018-10-10T15:18:40.000Z","size":38,"stargazers_count":49,"open_issues_count":12,"forks_count":15,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-11T08:40:50.231Z","etag":null,"topics":["context","javascript","modules","node","require","webpack"],"latest_commit_sha":null,"homepage":"","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/wilsonlewis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-08T17:17:00.000Z","updated_at":"2024-02-27T02:35:18.000Z","dependencies_parsed_at":"2022-09-05T11:21:47.925Z","dependency_job_id":null,"html_url":"https://github.com/wilsonlewis/require-context","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/wilsonlewis%2Frequire-context","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wilsonlewis%2Frequire-context/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wilsonlewis%2Frequire-context/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wilsonlewis%2Frequire-context/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wilsonlewis","download_url":"https://codeload.github.com/wilsonlewis/require-context/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251145627,"owners_count":21543074,"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":["context","javascript","modules","node","require","webpack"],"created_at":"2024-08-02T09:00:42.831Z","updated_at":"2025-04-27T13:32:16.552Z","avatar_url":"https://github.com/wilsonlewis.png","language":"JavaScript","readme":"# require-context v1.1.0\n\n## Installation\n\nUsing npm:\n```shell\n$ npm i -g npm\n$ npm i --save require-context\n```\n\nIn Node.js:\n```js\n// Load globally into all modules.\nrequire('require-context/register')\n\n// Load locally as a function.\nvar requireContext = require('require-context');\n```\n\n## Usage\n\nIt allows you to pass in a directory to search, a flag indicating whether\nsubdirectories should be searched too, and a regular expression to match files against.\n\nThe syntax is as follows:\n```js\nrequire.context(directory, useSubdirectories = false, regExp = /^\\.\\//)\n```\n\nExamples\n```js\nrequire.context(\"./test\", false, /\\.test\\.js$/);\n// a context with files from the test directory that can be required with a request endings with `.test.js`.\n```\n```js\nrequire.context(\"../\", true, /\\.stories\\.js$/);\n// a context with all files in the parent folder and descending folders ending with `.stories.js`.\n```\n\n## Context API\n\nA context module exports a (require) function that takes one argument: the request.\n\nThe exported function has 3 properties: resolve, keys, id.\n\n * `resolve` is a function and returns the module id of the parsed request.\n * `keys` is a function that returns an array of all possible requests that the context module can handle.\n \nThis can be useful if you want to require all files in a directory or matching a pattern, Example:\n\n```js\nfunction importAll (r) {\n  r.keys().forEach(r);\n}\n\nimportAll(require.context('../components/', true, /\\.js$/));\n```\n\n## Why require-context?\n\n * Take the hassle out of requiring groups of modules\n * Write cross-platform code between [webpack](https://webpack.js.org) and [node](https://nodejs.org)\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwilsonlewis%2Frequire-context","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwilsonlewis%2Frequire-context","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwilsonlewis%2Frequire-context/lists"}