New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

batch-import

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

batch-import

批量加载node.js模块、目录,并转换为对应的JS对象

  • 1.2.5
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

批量加载指定目录下node.js模块,并将模块导出结果保存到与模块路径结构一致的对象中

install

  npm install batch-import --save

使用方法

let batchImport = require('batch-import')

let modules = batchImport(options, container)

参数

options Object
  • path String - 指定模块加载目录

  • contain Array - 仅加载指定模块,不能与exclude同时使用

  • exclude Array - 排除指定模块,不能与contain同时使用

  • process Function - 模块导出数据处理函数,用于数据检验、预处理等操作。 输入参数1为模块输出用于加工的原始数据,输入参数2为输出容器对象,用于动态向container添加数据或访问已处理完成的依赖。 返回包含error对象用来抛出并定位异常,data属性导出正常结果。

container(可选)

指定一个容器用于存放模块导出结果,按照指定顺序加载模块,来解决依赖时序问题

示例

let batchImport = require('batch-import')

let modules = batchImport({
   "middleware": {
      "path": "middleware/",
      "exclude": ["test.js"],
   },
   "models": {
      "path": "models/",
      process(func, container) {
         if (typeof func === 'function') {
            return { data: func() }
         } else {
            return { error: `模块输出数据类型必须为函数` }
         }
      },
   },
   "controllers": {
      "path": "controllers/",
      "contain": ["_route.js"],
   },
})

注意事项

  • 配置项加载顺序与定义顺序一致,配置越靠前优先级越高

  • path路径以入口文件所在位置作为根路径

  • path路径中不应该出现./、../等相对路径表达式

FAQs

Package last updated on 10 May 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc