json-to-jsdoc-converter
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

json-to-jsdoc-converter

Web demo

How to use:

Import dependencies

import { JsonToJsdocConverter } from "json-to-jsdoc-converter";

Initialize converter

const converter = new JsonToJsdocConverter();

Provide some json

 {
  "id": 1,
  "name": "Super Mario",
  "age": null,
  "cars": [
    "honda",
    "bmw"
  ],
  "structure": {
    "logo": ""
  },
  "level1": {
    "alias": "testLevel",
    "level2": {
      "score": 12,
      "item": {},
      "level3": null
    }
  }
}

Pass the json to the convert method

const json = JSON.stringify(jsonMock1);
const jsDoc = converter.convert(json, { typesPrefix: "", typesSuffix: "Type" }); //you can set type name rules by passing optional config

Use the jsDoc output

/**
* @typedef Type
* @property {number} id
* @property {string} name
* @property {any} [age]
* @property {string[]} cars
* @property {StructureType} structure
* @property {Level1Type} level1
*/

/**
* @typedef StructureType
* @property {string} logo
*/

/**
* @typedef Level1Type
* @property {string} alias
* @property {Level1Level2Type} level2
*/

/**
* @typedef Level1Level2Type
* @property {number} score
* @property {object} item
* @property {any} [level3]
*/

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

Package Sidebar

Install

npm i json-to-jsdoc-converter

Weekly Downloads

117

Version

1.0.5

License

MIT

Unpacked Size

23.5 kB

Total Files

21

Last publish

Collaborators

  • nvidia1997