Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ufukbakan/generic-import
https://github.com/ufukbakan/generic-import
Last synced: 4 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/ufukbakan/generic-import
- Owner: ufukbakan
- License: mit
- Created: 2023-02-03T14:53:53.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-02-28T12:19:13.000Z (almost 2 years ago)
- Last Synced: 2024-12-18T06:24:22.317Z (16 days ago)
- Language: JavaScript
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: license
Awesome Lists containing this project
README
generic-import
Iterable, recursive, generic, cumulative imports.
Usage
```ts
import genericImport from "generic-import";
...express backend initial codeinterface MyRouterInterface {
basepath: string,
router: Router // imported from express
}const routesPath = path.join(process.cwd(), "routes");
const routers = genericImport(routesPath);
// [
// { filename: "router1", value: Object },
// { filename: "router2", value: Object },
// ]
for(const r of routers){ // for of loop supported in only ES syntax
app.use(r.value.basepath, r.value.router);
}app.listen(8080);
```Why use this approach?
It provides no coupling between main script file and route files. So there is much more scalable code.Options
- **camelize** *boolean* Camelizes returned file names of modules
- **fileExtensions** *array* Dot prefixed file extensions to include in search
- **recursive** *boolean* Enables search in nested foldersForked from import-modules