0.2.1 • Published 4 years ago

schema2md v0.2.1

Weekly downloads
4
License
MIT
Repository
github
Last release
4 years ago

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',
})

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

0.2.1

4 years ago

0.2.0

4 years ago

0.1.4

4 years ago

0.1.5

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago