generic-import
TypeScript icon, indicating that this package has built-in type declarations

3.0.3 • Public • Published

generic-import

Iterable, recursive, generic, cumulative imports.

Usage

import genericImport from "generic-import";
...express backend initial code

interface MyRouterInterface {
    basepath: string,
    router: Router // imported from express
}

const routesPath = path.join(process.cwd(), "routes");
const routers = genericImport<MyRouterInterface>(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 folders

Forked from import-modules

Package Sidebar

Install

npm i generic-import

Weekly Downloads

1

Version

3.0.3

License

MIT

Unpacked Size

5.69 kB

Total Files

6

Last publish

Collaborators

  • ufukbakan