UNPKG

prettier-plugin-jsdoc

Version:

Prettier plugin for format comment blocks and convert to standard Match with Visual studio and other IDE which support jsdoc and comments as markdown.

46 lines (45 loc) 1.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.formatType = exports.convertToModernArray = void 0; const prettier_1 = require("prettier"); function convertToModernArray(type) { if (!type) { return type; } const maxWrapper = /^(?!<>\]\[\{\}:;,\s)(Array<([^<>]+)>)/g; const minWrapper = /^(?!<>\]\[\{\}:;,\s)(Array<([^.]+)>)/g; type = type.replace(".<", "<"); function replaceArray(value) { let regular = maxWrapper; let result = regular.exec(value); if (!result) { regular = minWrapper; result = regular.exec(value); } if (!result) { return value; } const typeName = result[2]; value = value.replace(regular, `${typeName}[]`); return replaceArray(value); } return replaceArray(type); } exports.convertToModernArray = convertToModernArray; function formatType(type, options) { try { let pretty = type.replace("*", "any"); const TYPE_START = "type name = "; pretty = prettier_1.format(`${TYPE_START}${pretty}`, { ...options, parser: "typescript", }); pretty = pretty.slice(TYPE_START.length); pretty = pretty.replace(/[;\n]*$/g, ""); return pretty; } catch (error) { // console.log("jsdoc-parser", error); return type; } } exports.formatType = formatType;