UNPKG

prettier-plugin-jsdoc

Version:

Prettier plugin for format jsdoc and convert to standard Match with Visual studio and other IDE which support jsdoc.

48 lines (47 loc) 1.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.formatType = exports.convertToModernArray = void 0; //@ts-check 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);\n]*$/g, ""); return pretty; } catch (error) { // console.log("jsdoc-parser", error); return type; } } exports.formatType = formatType;