@custom-elements-manifest/to-markdown

中文文档
0.1.0发布于 2021/10/27MITTypeScriptESM + CJS近 30 天下载 1.2万

Custom-elements.json is a file format that describes custom elements. This format will allow tooling and IDEs to give rich information about the custom elements in a given project. It is, however, very experimental and things are subject to change. Follow

原始使用文档
文档目录11 节
  1. Usage
  2. Options
  3. Demo
  4. ./fixtures/-TEST/package/my-element.js :
  5. class: SuperClass
  6. class: MyElement , my-element
  7. mixin: MyMixin4
  8. mixin: Mixin
  9. Variables
  10. Functions
  11. Exports

@custom-elements-manifest/to-markdown

Custom-elements.json is a file format that describes custom elements. This format will allow tooling and IDEs to give rich information about the custom elements in a given project. It is, however, very experimental and things are subject to change. Follow the discussion here.

This library takes a Custom Elements Manifest and renders it to markdown.

Usage

Install:

npm i -S @custom-elements-manifest/to-markdown

Import and use in your code:

import fs from 'fs';
import { customElementsManifestToMarkdown } from '@custom-elements-manifest/to-markdown';

const manifest = JSON.parse(fs.readFileSync('./custom-elements.json', 'utf-8'));
const markdown = customElementsManifestToMarkdown(manifest);

fs.writeFileSync('./custom-elements.md', markdown);

Options

OptionTypeDefaultDescription
headingOffsetInteger0Offset the heading level by this number
private'all'|'details'|'hidden''all'See Private Members
omitDeclarationsOptionalDeclarations[][]See Omit Declarations
omitSectionsOptionalSections[][]See Omit Sections
classNameFilterstring | (() => string)'.*'See Class Name Filter

Private Members

The private option controls how private members appear in the markdown.

  • 'all': private members appear alongside public members according to source order
  • 'hidden': private members do not appear at all in markdown, but protected members do
  • 'details': private and protected members appear in a details disclosure widget below the table

Omit Declarations

The omitDeclarations option is a string[] that controls which kinds of entities are rendered in the final markdown output. The four declaration types are:

  • mixins
  • variables
  • functions
  • exports

The following is an example config that would filter out all four declaration types:

customElementsManifestToMarkdown(manifest, {
  omitSections: ['mixins', 'variables', 'functions', 'exports' ]
})

**Note: ** Mixins can be rendered both as declarations AND as sections inside a declaration. The omitDeclarations option for mixins will only filter out top level mixin declarations. To filter out mixin sections from a class declaration, use the mixin filter from omitSections.

Omit Sections

The omitSections option is a string[] that controls which sections of a declaration's full entry in the manifest.json should be rendered in the final markdown output. The section names are:

  • mainHeading
  • superClass
  • fields
  • methods
  • staticFields
  • staticMethods
  • slots
  • events
  • attributes
  • cssProperties
  • cssParts
  • mixins

The following is an example config showing how to filter out a few sections:

customElementsManifestToMarkdown(manifest, {
  // static fields and static methods tables will not be present
  // in the markdown result
  omitSections: [ 'staticFields', 'staticMethods' ]
})

Class Name Filter

Depending on the source files you pass to the analyzer, your custom-elements-manifest.json may contain more class file declarations than you need for the final markdown output. The classNameFilter option accepts a regex as a string (or a function that returns one) that will be used to filter out class declarations before rendering.

customElementsManifestToMarkdown(manifest, {
  classNameFilter: () => {
    // some logic
    return `(${prefix}-*|SuperClassExact)`; // filters out every class name that doesnt match the regex provided
  } 
})

Demo

customElementsManifestToMarkdown(manifest, {
  headingOffset: 1,
  private: 'details',
})
Source
{
  "schemaVersion": "1.0.0",
  "readme": "",
  "modules": [
    {
      "kind": "javascript-module",
      "path": "./fixtures/-TEST/package/my-element.js",
      "declarations": [
        {
          "kind": "class",
          "name": "SuperClass",
          "events": [
            {
              "name": "custom-event",
              "type": {
                "text": "SuperCustomEvent"
              },
              "description": "this is custom"
            }
          ],
          "superclass": {
            "name": "LitElement",
            "package": "lit-element"
          },
          "members": [
            {
              "kind": "method",
              "name": "superClassMethod",
              "privacy": "public"
            }
          ]
        },
        {
          "kind": "class",
          "name": "MyElement",
          "cssProperties": [
            {
              "name": "--background-color",
              "description": "Controls the color of bar"
            }
          ],
          "cssParts": [
            {
              "name": "bar",
              "description": "Styles the color of bar"
            }
          ],
          "slots": [
            {
              "name": "container",
              "description": "You can put some elements here"
            }
          ],
          "events": [
            {
              "name": "my-event",
              "type": {
                "text": "Event"
              }
            },
            {
              "name": "custom-event",
              "type": {
                "text": "SuperCustomEvent"
              },
              "description": "this is custom",
              "inheritedFrom": {
                "name": "SuperClass",
                "module": "./fixtures/-TEST/package/my-element.js"
              }
            }
          ],
          "mixins": [
            {
              "name": "LocalizeMixin",
              "package": "lion"
            },
            {
              "name": "Mixin",
              "module": "./fixtures/-TEST/package/my-element.js"
            }
          ],
          "superclass": {
            "name": "SuperClass",
            "module": "./fixtures/-TEST/package/my-element.js"
          },
          "attributes": [
            {
              "name": "prop-1",
              "fieldName": "prop1"
            },
            {
              "name": "prop2",
              "fieldName": "prop2"
            }
          ],
          "members": [
            {
              "kind": "field",
              "name": "prop1",
              "privacy": "public"
            },
            {
              "kind": "field",
              "name": "prop2",
              "privacy": "public"
            },
            {
              "kind": "field",
              "name": "prop3",
              "privacy": "public",
              "type": {
                "text": "boolean"
              },
              "default": "true"
            },
            {
              "kind": "field",
              "name": "foo",
              "type": {
                "text": "string"
              },
              "privacy": "private",
              "description": "description goes here",
              "default": "'bar'"
            },
            {
              "kind": "method",
              "name": "instanceMethod",
              "privacy": "public",
              "description": "Some description of the method here",
              "return": {
                "type": {
                  "text": ""
                }
              },
              "parameters": [
                {
                  "name": "e",
                  "type": {
                    "text": "Event"
                  }
                },
                {
                  "name": "a",
                  "type": {
                    "text": "string"
                  },
                  "description": "some description"
                }
              ]
            },
            {
              "kind": "field",
              "name": "mixinProp",
              "type": {
                "text": "number"
              },
              "privacy": "protected",
              "default": "1",
              "inheritedFrom": {
                "name": "Mixin",
                "module": "./fixtures/-TEST/package/my-element.js"
              }
            },
            {
              "kind": "method",
              "name": "superClassMethod",
              "privacy": "public",
              "inheritedFrom": {
                "name": "SuperClass",
                "module": "./fixtures/-TEST/package/my-element.js"
              }
            }
          ],
          "tagName": "my-element"
        },
        {
          "kind": "variable",
          "name": "variableExport",
          "description": "this is a var export",
          "type": {
            "text": "boolean"
          }
        },
        {
          "kind": "variable",
          "name": "stringVariableExport",
          "description": "this is a string var export",
          "type": {
            "text": "string"
          }
        },
        {
          "kind": "function",
          "name": "functionExport",
          "description": "This is a function export",
          "return": {
            "type": {
              "text": "boolean"
            }
          },
          "parameters": [
            {
              "name": "a",
              "type": {
                "text": "string"
              }
            },
            {
              "name": "b",
              "type": {
                "text": "boolean"
              }
            }
          ]
        },
        {
          "kind": "mixin",
          "name": "MyMixin4",
          "parameters": [
            {
              "name": "klass",
              "type": {
                "text": "*"
              },
              "description": "This is the description"
            },
            {
              "name": "foo",
              "type": {
                "text": "string"
              },
              "description": "Description goes here"
            }
          ]
        },
        {
          "kind": "mixin",
          "name": "Mixin",
          "parameters": [
            {
              "name": "klass",
              "type": {
                "text": "*"
              },
              "description": "This is the description"
            }
          ],
          "members": [
            {
              "kind": "field",
              "name": "mixinProp",
              "type": {
                "text": "number"
              },
              "privacy": "protected",
              "default": "1"
            }
          ]
        }
      ],
      "exports": [
        {
          "kind": "js",
          "name": "SuperClass",
          "declaration": {
            "name": "SuperClass",
            "module": "./fixtures/-TEST/package/my-element.js"
          }
        },
        {
          "kind": "custom-element-definition",
          "name": "my-element",
          "declaration": {
            "name": "MyElement",
            "module": "./fixtures/-TEST/package/my-element.js"
          }
        },
        {
          "kind": "js",
          "name": "variableExport",
          "declaration": {
            "name": "variableExport",
            "module": "./fixtures/-TEST/package/my-element.js"
          }
        },
        {
          "kind": "js",
          "name": "stringVariableExport",
          "declaration": {
            "name": "stringVariableExport",
            "module": "./fixtures/-TEST/package/my-element.js"
          }
        },
        {
          "kind": "js",
          "name": "functionExport",
          "declaration": {
            "name": "functionExport",
            "module": "./fixtures/-TEST/package/my-element.js"
          }
        }
      ]
    }
  ]
}
Result

./fixtures/-TEST/package/my-element.js:

class: SuperClass

Superclass

NameModulePackage
LitElementlit-element

Methods

NamePrivacyDescriptionParametersReturnInherited From
superClassMethodpublic

Events

NameTypeDescriptionInherited From
custom-eventSuperCustomEventthis is custom

class: MyElement, my-element

Superclass

NameModulePackage
SuperClass./fixtures/-TEST/package/my-element.js

Mixins

NameModulePackage
LocalizeMixinlion
Mixin./fixtures/-TEST/package/my-element.js

Fields

NamePrivacyTypeDefaultDescriptionInherited From
prop1public
prop2public
prop3publicbooleantrue

Methods

NamePrivacyDescriptionParametersReturnInherited From
instanceMethodpublicSome description of the method heree: Event, a: string
superClassMethodpublicSuperClass

Events

NameTypeDescriptionInherited From
my-eventEvent
custom-eventSuperCustomEventthis is customSuperClass

Attributes

NameFieldInherited From
prop-1prop1
prop2prop2

CSS Properties

NameDescription
--background-colorControls the color of bar

Slots

NameDescription
containerYou can put some elements here
Private API

Fields

NamePrivacyTypeDefaultDescriptionInherited From
fooprivatestring'bar'description goes here
mixinPropprotectednumber1Mixin

mixin: MyMixin4

Parameters

NameTypeDefaultDescription
klass*This is the description
foostringDescription goes here

mixin: Mixin

Parameters

NameTypeDefaultDescription
klass*This is the description
Private API

Fields

NamePrivacyTypeDefaultDescriptionInherited From
mixinPropprotectednumber1

Variables

NameDescriptionType
variableExportthis is a var exportboolean
stringVariableExportthis is a string var exportstring

Functions

NameDescriptionParametersReturn
functionExportThis is a function exporta: string, b: booleanboolean

Exports

KindNameDeclarationModulePackage
jsSuperClassSuperClass./fixtures/-TEST/package/my-element.js
custom-element-definitionmy-elementMyElement./fixtures/-TEST/package/my-element.js
jsvariableExportvariableExport./fixtures/-TEST/package/my-element.js
jsstringVariableExportstringVariableExport./fixtures/-TEST/package/my-element.js
jsfunctionExportfunctionExport./fixtures/-TEST/package/my-element.js

版本与发布记录

@custom-elements-manifest/to-markdown 共发布 15 个版本,首次发布于 2021/02/12;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.1.0latest2021/10/275 年前
0.0.142021/10/135 年前
0.0.132021/07/125 年前
0.0.122021/07/115 年前
0.0.112021/07/115 年前
0.0.102021/07/095 年前

关于 @custom-elements-manifest/to-markdown 的常见问题

@custom-elements-manifest/to-markdown 是什么?

Custom-elements.json is a file format that describes custom elements. This format will allow tooling and IDEs to give rich information about the custom elements in a given project. It is, however, very experimental and things are subject to change. Follow

如何安装 @custom-elements-manifest/to-markdown?

在项目目录运行 npm install @custom-elements-manifest/to-markdown,或使用 pnpm add / yarn add / bun add。

@custom-elements-manifest/to-markdown 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@custom-elements-manifest/to-markdown 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@custom-elements-manifest/to-markdown 可以商用吗?

@custom-elements-manifest/to-markdown 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@custom-elements-manifest/to-markdown 的下载量有多少?

根据 npm 官方下载统计,@custom-elements-manifest/to-markdown 在 2026/10/11 – 2026/11/09 这 30 天内被下载 12,242 次,日均约 408 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@custom-elements-manifest/to-markdown 还在维护吗?

最新版本 0.1.0 发布于 2021/10/27(5 年前);至今共发布 15 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/02/12。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。