https://github.com/joshmerlino/async-require-context
A rewritten version of @wilsonlewis' require-context package that utilizes modern technologies.
https://github.com/joshmerlino/async-require-context
async npm recursive require require-context typescript
Last synced: 2 months ago
JSON representation
A rewritten version of @wilsonlewis' require-context package that utilizes modern technologies.
- Host: GitHub
- URL: https://github.com/joshmerlino/async-require-context
- Owner: JoshMerlino
- Created: 2021-06-02T01:14:04.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2025-01-16T18:53:57.000Z (10 months ago)
- Last Synced: 2025-08-19T06:10:11.873Z (3 months ago)
- Topics: async, npm, recursive, require, require-context, typescript
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/async-require-context
- Size: 1.4 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# async-require-context
### Checks
* [](https://github.com/JoshMerlino/async-require-context/actions/workflows/build.yml)
* [](https://github.com/JoshMerlino/async-require-context/actions/workflows/code-style-analysis.yml)
* [](https://github.com/JoshMerlino/async-require-context/actions/workflows/test-ci.yml)



A rewritten version of [@wilsonlewis' require-context](https://www.npmjs.com/package/require-context) package that utilizes modern technologies.
> This module is **not** a drop in replacement for [require-context](https://www.npmjs.com/package/require-context).
### Getting started
```bash
npm install --save async-require-context
```
```ts
import asyncRequireContext from "async-require-context";
```
### Arguments
```ts
asyncRequireContext(path, recursive, pattern);
// In TypeScript, you can specify the type that each module is expected to be.
// asyncRequireContext(path, recursive, pattern);
```
| Name | Type | Default | Description |
| - | - | - | - |
| `path` | [String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) | *none (required)* | Specifies the path to look for modules in. |
| `recursive` | [Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean) | `true` | If true, will recurse through subdirectorys in path. |
| `pattern` | [RegExp](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp) | `/\.js$/` | Specifies a filter that files must match. |
### Returns
asyncRequireContext will always return `Promise`, if your using type annotations, it will be `Promise[]>`
The `Context` structure is:
```ts
{
name: string, // Name of the module.
path: string, // Full path of the module.
module: require(path) // The module as if it was required with `require`. This may be any shape depending on if you use type annotations.
}
```