Node js模块如何获取导出函数列表 [英] Node js module how to get list of exported functions

查看:72
本文介绍了Node js模块如何获取导出函数列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定一个节点js模块/包,有什么方法可以提取出该模块导出的所有函数?

Given a node js module/package, is there some way I can extract out all functions exported by that module ?

例如-如果模块具有带有以下代码的js文件:

For example - if the module has a js file with following code:

exports.tokenizer = tokenizer;
exports.parse = parse;
exports.slice = slice;
exports.curry = curry;

然后,我希望将以下内容列为导出内容:标记生成器,解析,切片,咖喱

Then I would like to have a following listed as exports: tokenizer, parse, slice, curry

推荐答案

您可以要求文件并仅通过对象键进行映射,这将返回导出对象名称的数组.

You can require the file and just map through the object keys, which would return an array of the names of the exported objects.

var myExports = require('./exported-file.js');

console.log(Object.keys(myExports));

这篇关于Node js模块如何获取导出函数列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆