npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@mora/module-parse

v0.2.0

Published

parse export import statement

Downloads

9

Readme

@mora/module-parse

解析代码中的 require, module.exports, importexport 语句

注意:由于 require 和 exports 可以赋值给其它变量,其它变量也可以覆盖 require 和 exports,所以解析出来的结果可能不准备,如:

const r = require
const fs = r('fs') // 这里的 r 是解析不出来的

建议采用 import 和 export 来解析,即设置 module="esnext"

支持解析下面的语句

  • module="commonjs"
// REQUIRE_ONLY
require('my_module')

// REQUIRE_ASIGN
var fs = require('my_module')
let fs = require('my_module')
const fs = require('my_module')

// REQUIRE_DESTRUCT
const { stat, exists, readFile } = require('my_module')

// EXPORTS_DEFAULT
module.exports = 42
module.exports = variable
module.exports = function() {}
module.exports = function test() {}

// EXPORTS_VARIABLE
exports.a = xx
module.exports.a = xx
  • module="esnext"
// IMPORT_ONLY
import 'my_module'

// IMPORT_ALL
import * as fs from 'my_module'

// IMPORT_NAMED
import fs from 'my_module'
import { stat, exists, readFile } from 'my_module'
import { a as b } from 'my_module'
import _, { each, forEach } from 'lodash'

// EXPORT_DEFAULT
export default 42
export default variable
export default function() {}
export default function test() {}

// EXPORT_ASSIGN
export const A = 1
export class A {}
export function A() {}

// EXPORT_NAMED
export {A, B}
export {A as AA, B}

// EXPORT_ALL_FROM
export * from './a'

// EXPORT_NAMED_FROM
export { default } from 'foo'
export { foo, bar } from 'my_module'
export { es6 as default } from './someModule'

Installation

npm i @mora/module-parser

Usage

import parse from '@mora/module-parser'

parse(code, options)

Support

Changelog

[Changelog][./CHANGELOG.md]

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT