Skip to content

Latest commit

 

History

History
161 lines (124 loc) · 3.21 KB

README.md

File metadata and controls

161 lines (124 loc) · 3.21 KB

schema2md

NPM version NPM downloads Node.js CI codecov

Install

tnpm install schema2md --save

Example

  • Input:
{
  "title": "foo.config.js",
  "description": "My Config File",
  "properties": {
    "type": {
      "description": "TYPE's description",
      "type": "string",
      "enum": [
        "foo",
        "bar"
      ]
    },
    "env": {
      "description": "ENV's description",
      "type": "string"
    }
  }
}
  • Output:
# foo.config.js
 
My Config File

## type

- Type: `"foo" | "bar"`
- Description: TYPE's description

## env

- Type: `string`
- Description: ENV's description"

Usage

const { transform } = require('schema2md')

transform({
  schemaPath: 'fixtures/simple.json',
  outputPath: 'docs/config/README.md',
})

Using in VuePress

Here is seperate VuePress plugin for you to use it at VuePress.

API

.transform()

  • Type: (options: ITransformOptions) => Promise<string>
  • Description: Get markdown output by JSON Schema.

Type of ITransformOptions is as follows:

interface ITransformOptions {
  /**
   * Current working directory, used to calcaulate absolute path for "schemaPath"
   * and "outputPath" with relative path, defaults to `process.cwd()`.
   */
  cwd?: string;
  /**
   * A relative path or an absolute path to a JSON Schema file. 
   */
  schemaPath: string;
  /**
   * A relative path or an absolute path to a output markdown file.
   */
  outputPath: string;
  /**
   * Whether to write output content to "outputPath".
   */
  write: boolean;
  /**
   * Current locale.
   */
  locale: string;
  /**
   * Specify a markdown file to be merged into the generated markdown.
   */
  schemaMarkdown: string;
  /**
   * Frontmatter content.
   */
  frontmatter: string;
  /**
   * Content at the below of h1.
   */
  heading: string;
  
}

.batchTransform()

  • Type: (options: IBatchTransformOptions) => Promise<string[]>
  • Description: Get markdown output by JSON Schema.

Type of IBatchTransformOptions is as follows:

interface IBatchTransformOptions {
  /**
   * Global "cwd".
   */
  cwd: string;
  /**
   * Global "cwd".
   */
  locale: string;
  /**
   * Global "write".
   */
  write: string;
  /**
   * Meta transform config.
   */
  configs: ITransformOptions[];
}

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Author

schema2md © ULIVZ, Released under the MIT License.

github.com/ulivz · GitHub @ULIVZ · Twitter @_ulivz