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

xuyou-mddir

v0.1.61

Published

Generate a directory tree in markdown format 生成项目结构树

Readme

xuyou-mddir

存储库

https://github.com/xuyouer/xuyou-mddir

NPM

https://www.npmjs.com/package/xuyou-mddir

安装

npm i xuyou-mddir

使用

调用方法使用

在项目根目录创建 test.js 文件

create test.js in root directory

// test.js
const {Tree, generateTree} = require('xuyou-mddir')

generateTree()
// OR
const tree = new Tree()
tree.generateTree();

运行结果

xuyou-mddir/
│
├── .gitattributes
├── .gitignore
├── .mddirignore
├── .npmrc
├── LICENSE
├── README.md
├── index.js
├── package-lock.json
├── package.json
├── pnpm-lock.yaml
├── src/
│   ├── Tree.js
│   ├── Utils.js
│   └── ...
│
└── ...

自定义使用

添加配置

在项目根目录创建 .mddirignore 文件

create .mddirignore or other name file in root directory

default configuration file name is .mddirignore

ignore:
  - node_modules
  - .git
  - .idea
  - .vscode
  - build
  - __tests__
  - temp
include: []
exclude: []
build:
  keepIgnoredName: false
  maxDepth: 5
  outputFormat: console
  showFileSize: false
  showIgnoredFileSize: false
  appendIgnore: true
  appendInclude: true
  appendExclude: true

调用方法使用

// test.js
const {Tree, generateTree} = require('xuyou-mddir')

const options = {
    configFilePath: '.mddirignore',
    include: ['__tests__'],
    buildOptions: {
        keepIgnoredName: true,
    },
}

generateTree(null, options)
// OR
const tree = new Tree(null, options)
tree.generateTree()

运行结果

xuyou-mddir/
│
├── .git/
│   └── ...
│
├── .gitattributes
├── .gitignore
├── .mddirignore
├── .npmrc
├── LICENSE
├── README.md
├── __tests__/
│   ├── test.js
│   └── ...
│
├── index.js
├── node_modules/
│   └── ...
│
├── package-lock.json
├── package.json
├── pnpm-lock.yaml
├── src/
│   ├── Tree.js
│   ├── Utils.js
│   └── ...
│
└── ...

默认配置

获取

// test.js
const {
    defaultConfigFilePath,
    defaultIgnoreDirs,
    defaultIncludeDirs,
    defaultExcludeDirs,
    defaultBuildOptions,
    supportedOutputFormats,
} = require('xuyou-mddir')

console.log(defaultConfigFilePath)
console.log(defaultIgnoreDirs)
console.log(defaultIncludeDirs)
console.log(defaultExcludeDirs)
console.log(defaultBuildOptions)
console.log(supportedOutputFormats)

解析

部分配置解析

{
  "ignore": ['customIgnore'],           # 忽略文件(目录)
  "include": ['customInclude'],         # 包含文件(目录)
  "exclude": ['customExclude'],         # 排除文件(目录)
  "buildOptions" : {                    # 生成配置选项
    "keepIgnoredName": Boolean,         # 忽略文件(目录)是否保留名称, 默认 false
    "maxDepth": Number,                 # 树的生成最大深度, 默认 5
    "outputFormat": String,             # 输出格式选项, 默认 console
    "showFileSize": Boolean,            # 显示文件(目录)大小, 默认 false
    "showIgnoredFileSize": Boolean,     # 显示忽略文件(目录)大小, 默认 false
    "appendIgnore": Boolean,            # 追加忽略模式, 默认 true
    "appendInclude": Boolean,           # 追加包含模式, 默认 true
    "appendExclude": Boolean,           # 追加排除模式, 默认 true
    ...
  }
  ...
}

部分方法参数解析

// Tree.js
...

class Tree {
    static defaultConfig = {  // 默认配置
        configFilePath: '.mddirignore',  // 配置文件路径
        ignoreDirs: [  // 忽略配置
            'node_modules',
            '.idea',
            '.git',
            '.vscode',
            'build',
            '__tests__',
            'temp',
        ],
        includeDirs: [],  // 包含配置
        excludeDirs: [],  // 排除配置
        buildOptions: {  // 生成配置
            keepIgnoredName: false,  // 忽略是否保留名称
            maxDepth: 5,  // 树的生成最大深度
            outputFormat: 'console',  // 输出方式
            showFileSize: false,  // 显示文件大小
            showIgnoredFileSize: false,  // 显示忽略文件大小
            appendIgnore: true,  // 追加忽略
            appendInclude: true,  // 追加包含
            appendExclude: true,  // 追加排除
        },
    }
    static supportedOutputFormats = ['console', 'json']  // 支持的输出格式

    constructor(rootPath = process.cwd(), options = {}) {
        this.rootPath = typeof rootPath === 'string' ? rootPath : process.cwd()  // 项目路径
        this.options = {
            ...Tree.defaultConfig,
            projectName: path.basename(this.rootPath),  // 项目名
        }
        this._loadConfigFilePath(options)
        this._loadConfig()  // 读取配置
        this._loadOptions(options)  // 读取options
    }

    _loadConfig() {  // 读取配置信息
        ...
    }

    generateTreeData(currentPath = null, level = 0) {  // 生成树形结构的 JSON 数据
        ...
    }

    generateTreeConsole(currentPath = null, level = 0) {  // 生成树形结构的默认控制台输出
        ...
    }

    generateTree(currentPath = null, level = 0) {  // 选择不同的输出方式生成项目结构树
        ...
    }

    ...
}

module.exports = {
    ...
}