Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

prettier-plugin-jsdoc

Package Overview
Dependencies
Maintainers
1
Versions
105
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prettier-plugin-jsdoc - npm Package Compare versions

Comparing version
1.0.5
to
1.1.0
+7
-0
CHANGELOG.md

@@ -5,2 +5,9 @@ # Changelog

## [1.1.0](https://github.com/hosseinmd/prettier-plugin-jsdoc/compare/v1.0.5...v1.1.0) (2023-10-06)
### Features
* jsdocCommentLineStrategy ([c4e4db5](https://github.com/hosseinmd/prettier-plugin-jsdoc/commit/c4e4db5a2e79ec24698d13df9d81034fb2a2d937))
### [1.0.5](https://github.com/hosseinmd/prettier-plugin-jsdoc/compare/v1.0.4...v1.0.5) (2023-10-05)

@@ -7,0 +14,0 @@

+119
-2

@@ -1,4 +0,121 @@

import prettier, { SupportOption } from "prettier";
import prettier from "prettier";
import { JsdocOptions } from "./types.js";
declare const options: Record<keyof JsdocOptions, SupportOption>;
declare const options: {
jsdocSpaces: {
name: string;
type: "int";
category: string;
default: number;
description: string;
};
jsdocDescriptionWithDot: {
name: string;
type: "boolean";
category: string;
default: false;
description: string;
};
jsdocDescriptionTag: {
name: string;
type: "boolean";
category: string;
default: false;
description: string;
};
jsdocVerticalAlignment: {
name: string;
type: "boolean";
category: string;
default: false;
description: string;
};
jsdocKeepUnParseAbleExampleIndent: {
name: string;
type: "boolean";
category: string;
default: false;
description: string;
};
jsdocSingleLineComment: {
name: string;
type: "boolean";
category: string;
deprecated: string;
default: true;
description: string;
};
jsdocCommentLineStrategy: {
name: string;
type: "choice";
choices: {
since: string;
value: string;
description: string;
}[];
category: string;
default: string;
description: string;
};
jsdocSeparateReturnsFromParam: {
name: string;
type: "boolean";
category: string;
default: false;
description: string;
};
jsdocSeparateTagGroups: {
name: string;
type: "boolean";
category: string;
default: false;
description: string;
};
jsdocCapitalizeDescription: {
name: string;
type: "boolean";
category: string;
default: true;
description: string;
};
tsdoc: {
name: string;
type: "boolean";
category: string;
default: false;
description: string;
};
jsdocPrintWidth: {
name: string;
type: "int";
category: string;
default: any;
description: string;
};
jsdocAddDefaultToDescription: {
name: string;
type: "boolean";
category: string;
default: true;
description: string;
};
jsdocPreferCodeFences: {
name: string;
type: "boolean";
category: string;
default: false;
description: string;
};
jsdocLineWrappingStyle: {
name: string;
type: "choice";
choices: {
since: string;
value: string;
description: string;
}[];
category: string;
default: string;
description: string;
};
};
declare const defaultOptions: JsdocOptions;

@@ -5,0 +122,0 @@ declare const parsers: {

@@ -7,9 +7,2 @@ import { getParser } from "./parser.js";

const options = {
jsdocParser: {
name: "jsdocParser",
type: "boolean",
category: "jsdoc",
default: true,
description: "Enable/Disable jsdoc parser",
},
jsdocSpaces: {

@@ -54,5 +47,30 @@ name: "jsdocSpaces",

category: "jsdoc",
deprecated: "use jsdocCommentLineStrategy instead will be remove on v2",
default: true,
description: "Should compact single line comment",
},
jsdocCommentLineStrategy: {
name: "jsdocCommentLineStrategy",
type: "choice",
choices: [
{
since: "1.1.0",
value: "singleLine",
description: `Should compact single line comment, if possible`,
},
{
since: "1.1.0",
value: "multiline",
description: `Should compact multi line comment`,
},
{
since: "1.1.0",
value: "keep",
description: `Should keep original line comment`,
},
],
category: "jsdoc",
default: "singleLine",
description: "How comments line should be",
},
jsdocSeparateReturnsFromParam: {

@@ -123,3 +141,2 @@ name: "jsdocSeparateReturnsFromParam",

const defaultOptions = {
jsdocParser: options.jsdocParser.default,
jsdocSpaces: options.jsdocSpaces.default,

@@ -133,2 +150,4 @@ jsdocPrintWidth: options.jsdocPrintWidth.default,

jsdocSingleLineComment: options.jsdocSingleLineComment.default,
jsdocCommentLineStrategy: options.jsdocCommentLineStrategy
.default,
jsdocSeparateReturnsFromParam: options.jsdocSeparateReturnsFromParam

@@ -174,2 +193,3 @@ .default,

const jsDocPreprocess = (text, options) => {
normalizeOptions(options);
const tsPluginParser = findPluginByParser(parserName, options);

@@ -198,2 +218,13 @@ if (!tsPluginParser) {

export { options, parsers, defaultOptions };
function normalizeOptions(options) {
if (options.jsdocCommentLineStrategy) {
return;
}
if (options.jsdocSingleLineComment) {
options.jsdocCommentLineStrategy = "singleLine";
}
else {
options.jsdocCommentLineStrategy = "multiline";
}
}
//# sourceMappingURL=index.js.map
+46
-15

@@ -280,5 +280,7 @@ (function (global, factory) {

}
function addStarsToTheBeginningOfTheLines(comment, options) {
if (options.jsdocSingleLineComment &&
numberOfAStringInString(comment.trim(), "\n") === 0) {
function addStarsToTheBeginningOfTheLines(originalComment, comment, options) {
if ((options.jsdocCommentLineStrategy === "singleLine" &&
numberOfAStringInString(comment.trim(), "\n") === 0) ||
(options.jsdocCommentLineStrategy === "keep" &&
numberOfAStringInString(originalComment, "\n") === 0)) {
return `* ${comment.trim()} `;

@@ -745,5 +747,2 @@ }

const ast = prettierParse(text, options);
if (options.jsdocParser === false) {
return ast;
}
options = {

@@ -760,2 +759,3 @@ ...options,

const paramsOrder = getParamsOrders(ast, tokenIndex);
const originalValue = comment.value;
comment.value = comment.value.replace(/^([*]+)/g, "*");

@@ -870,3 +870,3 @@ const commentString = `/*${comment.value.replace(/\r\n?/g, "\n")}*/`;

if (comment.value) {
comment.value = addStarsToTheBeginningOfTheLines(comment.value, options);
comment.value = addStarsToTheBeginningOfTheLines(originalValue, comment.value, options);
}

@@ -1132,9 +1132,2 @@ if (eol === "cr") {

const options = {
jsdocParser: {
name: "jsdocParser",
type: "boolean",
category: "jsdoc",
default: true,
description: "Enable/Disable jsdoc parser",
},
jsdocSpaces: {

@@ -1179,5 +1172,30 @@ name: "jsdocSpaces",

category: "jsdoc",
deprecated: "use jsdocCommentLineStrategy instead will be remove on v2",
default: true,
description: "Should compact single line comment",
},
jsdocCommentLineStrategy: {
name: "jsdocCommentLineStrategy",
type: "choice",
choices: [
{
since: "1.1.0",
value: "singleLine",
description: `Should compact single line comment, if possible`,
},
{
since: "1.1.0",
value: "multiline",
description: `Should compact multi line comment`,
},
{
since: "1.1.0",
value: "keep",
description: `Should keep original line comment`,
},
],
category: "jsdoc",
default: "singleLine",
description: "How comments line should be",
},
jsdocSeparateReturnsFromParam: {

@@ -1248,3 +1266,2 @@ name: "jsdocSeparateReturnsFromParam",

const defaultOptions = {
jsdocParser: options.jsdocParser.default,
jsdocSpaces: options.jsdocSpaces.default,

@@ -1258,2 +1275,4 @@ jsdocPrintWidth: options.jsdocPrintWidth.default,

jsdocSingleLineComment: options.jsdocSingleLineComment.default,
jsdocCommentLineStrategy: options.jsdocCommentLineStrategy
.default,
jsdocSeparateReturnsFromParam: options.jsdocSeparateReturnsFromParam

@@ -1299,2 +1318,3 @@ .default,

const jsDocPreprocess = (text, options) => {
normalizeOptions(options);
const tsPluginParser = findPluginByParser(parserName, options);

@@ -1322,2 +1342,13 @@ if (!tsPluginParser) {

}
function normalizeOptions(options) {
if (options.jsdocCommentLineStrategy) {
return;
}
if (options.jsdocSingleLineComment) {
options.jsdocCommentLineStrategy = "singleLine";
}
else {
options.jsdocCommentLineStrategy = "multiline";
}
}

@@ -1324,0 +1355,0 @@ exports.defaultOptions = defaultOptions;

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("comment-parser"),require("prettier"),require("binary-searching"),require("mdast-util-from-markdown"),require("prettier/plugins/babel"),require("prettier/plugins/flow"),require("prettier/plugins/typescript")):"function"==typeof define&&define.amd?define(["exports","comment-parser","prettier","binary-searching","mdast-util-from-markdown","prettier/plugins/babel","prettier/plugins/flow","prettier/plugins/typescript"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).sayHello={},e.commentParser,e.prettier,e.BSearch,e.mdastUtilFromMarkdown,e.parserBabel,e.parserFlow,e.parserTypescript)}(this,(function(e,t,n,r,a,s,i,o){"use strict";function c(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var l=c(r),p=c(s),d=c(i),u=c(o);const g="abstract",f="borrows",m="callback",h="category",y="class",j="constant",b="deprecated",$="description",w="example",v="extends",S="external",x="file",P="fires",D="function",W="ignore",k="license",A="member",T="memberof",C="module",L="namespace",E="overload",F="override",O="param",I="privateRemarks",M="property",_="remarks",z="returns",R="since",q="throws",U="todo",K="type",V="typedef",G="satisfies",B="yields",H={tag:"this_is_for_space",name:"",optional:!1,type:"",description:"",source:[],problems:[]},Y={arg:O,argument:O,const:j,constructor:y,desc:$,emits:P,examples:w,exception:q,fileoverview:x,func:D,host:S,method:D,overview:x,params:O,prop:M,return:z,var:A,virtual:g,yield:B,hidden:W},J=["default","defaultValue"],N=[f,h,b,$,w,v,k,C,L,E,F,I,_,z,R,q,U,B,x,...J],Q=[f,f,b,$,w,W,k,C,L,E,F,I,_,R,U,x],X=[f,...J,T,C,"see"],Z=[f,h,$,w,I,_,R,U],ee=[v,O,M,z,q,K,G,V,B],te=[m,V],ne=[...te,K,M,O,z,B,q],re=[_,I,"providesModule",C,k,"flow","async","private",W,T,"version",x,"author",b,R,h,$,w,g,"augments",j,...J,S,E,P,"template","typeParam",D,L,f,y,v,A,V,K,G,M,m,O,B,z,q,"other","see",U];function ae(e,t){return t.jsdocSingleLineComment&&0===(n=e.trim(),r="\n",(n.match(new RegExp(r,"g"))||[]).length)?`* ${e.trim()} `:`*${e.replace(/(\n(?!$))/g,"\n * ")}\n `;var n,r}function se(e){return e?e.match(/^https?:\/\//i)?e:e.startsWith("- ")?e.slice(0,2)+se(e.slice(2)):e[0].toUpperCase()+e.slice(1):e}async function ie(e,t,r){const{printWidth:a,jsdocKeepUnParseAbleExampleIndent:s}=r;e.split("\n").slice(1).every((e=>!e.trim()||e.startsWith(t)))&&(e=e.replace(new RegExp(`\n${t.replace(/[\t]/g,"[\\t]")}`,"g"),"\n"));try{let s="";const i=a-4;s=e.trim().startsWith("{")?await n.format(e||"",{...r,parser:"json",printWidth:i}):await n.format(e||"",{...r,printWidth:i}),e=s.replace(/(^|\n)/g,`\n${t}`)}catch(n){e=(e=`\n${e.split("\n").map((e=>`${t}${s?e:e.trim()}`)).join("\n")}\n`).replace(/^\n[\s]+\n/g,"\n")}return e}const oe=(e,t)=>{const n=t.plugins.find((t=>"object"==typeof t&&t.name&&t.parsers&&t.parsers.hasOwnProperty(e)));return!n||"prettier-plugin-jsdoc"===n.name||n.parsers?.hasOwnProperty("jsdoc-parser")?void 0:n.parsers?.[e]},ce=e=>J.includes(e),le="2@^5!~#sdE!_TABLE";async function pe(e,t,r,s){if(!t)return t;const{printWidth:i}=r,{tagStringLength:o=0,beginningSpace:c}=s,l=[...(t=(t=t.replace(/^(\d+)[-][\s|]+/g,"$1. ")).replace(/\n+(\s*\d+)[-][\s]+/g,"\n$1. ")).matchAll(/```\S*?\n[\s\S]+?```/gm),...t.matchAll(/^\r?\n^(?:(?:(?:[ ]{4}|\t).*(?:\r?\n|$))+)/gm)],p=[];t=t.replace(/((\n|^)\|[\s\S]*?)((\n[^|])|$)/g,((e,t,n,r,a,s)=>{for(const t of l)if(void 0!==t.index&&t.index<=s+1&&s+e.length+1<=t.index+t[0].length)return e;return e=r?e.slice(0,-1):e,p.push(e),`\n\n${le}\n\n${r?r.slice(1):""}`})),r.jsdocCapitalizeDescription&&!X.includes(e)&&(t=se(t)),t=`${o?`${"!".repeat(o-1)}?`:""}${t.startsWith("```")?"\n":""}${t}`;let d=0;t=t.replace(new RegExp(`\\n[ ]{${c.length}}`,"g"),"\n");const u=a.fromMarkdown(t);let g=await async function t(a,s,o){return Array.isArray(a.children)?(await Promise.all(a.children.map((async(n,c)=>{switch(n.type){case"listItem":{let e=`\n${s}- `;if("number"==typeof a.start){const t=c+(a.start??1);e=`\n${s}${t}. `}const r=s+" ".repeat(e.length-1);return`${e}${(await t(n,r,a)).trim()}`}case"list":{let r="";return e!==$&&"root"===a.type&&c===a.children.length-1&&(r="\n"),`\n${await t(n,s,a)}${r}`}case"paragraph":{const a=await t(n,s,o);return n.costumeType===le?a:`\n\n${a.split("\\\n").map((t=>{const n=[];t=t.replace(/{@(link|linkcode|linkplain)[\s](([^{}])*)}/g,((e,t,r)=>(n.push(r),`{@${t}${"_".repeat(r.length)}}`))),t=t.replace(/\s+/g," "),r.jsdocCapitalizeDescription&&!X.includes(e)&&(t=se(t)),r.jsdocDescriptionWithDot&&(t=t.replace(/([\w\p{L}])$/u,"$1."));let a=function(e,t,n){let r=e.trim();if(!r)return r;let a="";for(;r.length>t;){let e=r.lastIndexOf(" ",r.startsWith("\n")?t+1:t);e<=n.length&&(e=r.indexOf(" ",n.length+1)),-1===e&&(e=r.length),a+=r.substring(0,e),r=r.substring(e+1),r&&(r=`${n}${r}`,r=`\n${r}`)}return a+=r,`${n}${a}`}(t,i,s);return a=a.replace(/{@(link|linkcode|linkplain)([_]+)}/g,((e,t,r)=>{const a=n[0];return a.length===r.length?(n.shift(),`{@${t} ${a}}`):e})),a})).join("\\\n")}`}case"strong":return`**${await t(n,s,a)}**`;case"emphasis":return`_${await t(n,s,a)}_`;case"heading":return`\n\n${s}${"#".repeat(n.depth)} ${await t(n,s,a)}`;case"link":case"image":return`[${await t(n,s,a)}](${n.url})`;case"linkReference":return`[${await t(n,s,a)}][${n.label}]`;case"definition":return`\n\n[${n.label}]: ${n.url}`;case"blockquote":{const e=await t(n,"",a);return`${s}> ${e.trim().replace(/(\n+)/g,`$1${s}> `)}`}}return t(n,s,a)})))).join(""):async function(e,t,a){if("inlineCode"===e.type)return`\`${e.value}\``;if("code"===e.type){let n=e.value||"",a=t;if(n)if(e.lang){const a=(e=>{switch(e){case"js":case"javascript":case"jsx":return["babel","babel-flow","vue"];case"ts":case"typescript":case"tsx":return["typescript","babel-ts","angular"];case"json":case"css":return["css"];case"less":return["less"];case"scss":return["scss"];case"html":return["html"];case"yaml":return["yaml"];default:return["babel"]}})(e.lang.toLowerCase()),s=a?.includes(r.parser)?r.parser:a?.[0]||e.lang;n=await ie(n,t,{...r,parser:s,jsdocKeepUnParseAbleExampleIndent:!0})}else r.jsdocPreferCodeFences||(a=t+" ".repeat(4)),n=await ie(n,a,{...r,jsdocKeepUnParseAbleExampleIndent:!0});const s=r.jsdocPreferCodeFences||!!e.lang;return n=s?n:n.trimEnd(),n?s?`\n\n${a}\`\`\`${e.lang||""}${n}\`\`\``:`\n${n}`:""}if(e.value===le&&(a&&(a.costumeType=le),p.length>0)){let a=p?.[d]||"";return d++,a&&(a=(await n.format(a,{...r,parser:"markdown"})).trim()),`${a?`\n\n${t}${a.split("\n").join(`\n${t}`)}`:e.value}`}return"break"===e.type?"\\\n":e.value||e.title||e.alt||""}(a,s,o)}(u,c,null);return g=g.replace(/^[\s\n]+/g,""),g=g.replace(/^([!]+\?)/g,""),g}const de=async({name:e,description:t,type:n,tag:r},a,s,i,o,c,l)=>{let p="\n";if(r===H.tag)return p;const{printWidth:d,jsdocSpaces:u,jsdocVerticalAlignment:g,jsdocDescriptionTag:f,tsdoc:m,useTabs:h,tabWidth:y,jsdocSeparateTagGroups:j}=i,b=" ".repeat(u);let v=0,S=0,x=0,P=0;g&&ee.includes(r)&&(r?v+=o-r.length:o&&(P+=o+b.length),n?S+=c-n.length:c&&(P+=c+b.length),e?x+=l-e.length:l&&(P=l+b.length));const D=r!==$||f;if(D&&(p+=`@${r}${" ".repeat(v||0)}`),n){p+=b+(()=>{if(!ce(r))return`{${n}}`;if("[]"===n)return"[ ]";if("{}"===n)return"{ }";return/^{.*[A-z0-9_]+ ?:.*}$/.test(n)?n.replace(/; ([A-z0-9_])/g,", $1"):n})()+" ".repeat(S)}if(e&&(p+=`${b}${e}${" ".repeat(x)}`),r!==w||m){if(t){let e="";if(D&&(p+=b+" ".repeat(P)),X.includes(r)||!re.includes(r))e=t;else{const[,n]=/^\s*(\S+)/.exec(t)||["",""],a=r===$||[w,_,I].includes(r)&&m?"":" ";e=r!==$&&p.length+n.length>d||[_,I].includes(r)?`\n${a}`+await pe(r,t,i,{beginningSpace:a}):await pe(r,t,i,{tagStringLength:p.length-1,beginningSpace:a})}j&&(e=e.trimEnd()),p+=e.startsWith("\n")?e.replace(/^\n[\s]+\n/g,"\n"):e.trimStart()}}else{const e=t.match(/<caption>([\s\S]*?)<\/caption>/i);e&&(t=t.replace(e[0],""),p=`${p} ${e[0]}`);const n=h?"\t":" ".repeat(y);p+=(await ie(t,n,i)).replace(new RegExp(`^\\n${n.replace(/[\t]/g,"[\\t]").replace(/[^S\r\n]/g,"[^S\\r\\n]")}\\n`),"").trimEnd()}return p+=function({tag:e,isEndTag:t}){return[$,w,U].includes(e)&&!t?"\n":""}({tag:r,isEndTag:a===s.length-1}),p},{name:ue,tag:ge,type:fe,description:me}=t.tokenizers,he=(e,r)=>async function(a,s,i){let o=i??s;const c=(oe(r,o)?.parse||e)(a,o);if(!1===o.jsdocParser)return c;o={...o,printWidth:o.jsdocPrintWidth??o.printWidth};const p="auto"===o.endOfLine?function(e){const t={"\r":0,"\r\n":0,"\n":0},n=/\r\n?|\n/g;let r;for(;r=n.exec(e);)t[r[0]]++;const a=t["\r"],s=t["\r\n"],i=t["\n"],o=Math.max(a,s,i);return i===o?"lf":s===o?"crlf":"cr"}(a):o.endOfLine;return o={...o,endOfLine:"lf"},await Promise.all(c.comments.map((async e=>{if(!be(e))return;const r=(s=c.tokens,i=e,l.default.eq(s,i,((e,t)=>e.loc.start.line===t.loc.start.line?e.loc.start.column-t.loc.start.column:e.loc.start.line-t.loc.start.line)));var s,i;const d=function(e,t){let n;try{const r=e.tokens[t+1]?.type;if("object"!=typeof r)return;if("function"===r.label){let r=1;const a=e.tokens.slice(t+4),s=a.findIndex((({type:e})=>"string"!=typeof e&&("("===e.label?r++:")"===e.label&&r--,0===r)));n=a.slice(0,s+1)}if("const"===r.label){let r=1,a=e.tokens.slice(t+1);const s=a.findIndex((({type:e})=>"object"==typeof e&&"("===e.label));a=a.slice(s+1);const i=a.findIndex((({type:e})=>"string"!=typeof e&&("("===e.label?r++:")"===e.label&&r--,0===r))),o=a[i+1];"object"==typeof o?.type&&"=>"===o.type.label&&(n=a.slice(0,i+1))}return n?.filter((({type:e})=>"object"==typeof e&&"name"===e.label)).map((({value:e})=>e))}catch{}return}(c,r);e.value=e.value.replace(/^([*]+)/g,"*");const u=`/*${e.value.replace(/\r\n?/g,"\n")}*/`;if(!/^\/\*\*[\s\S]+?\*\/$/.test(u))return;const g=t.parse(u,{spacing:"preserve",tokenizers:[ge(),e=>ce(e.tag)?e:fe("preserve")(e),ue(),me("preserve")]})[0];if(e.value="",!g)return;!function(e){e.tags=e.tags.map((({tag:e,type:t,name:n,description:r,default:a,...s})=>{e=e||"",t=t||"",n=n||"",r=r||"",a=a?.trim();const i=e.indexOf("{");-1!==i&&"}"===e[e.length-1]&&(t=e.slice(i+1,-1)+" "+t,e=e.slice(0,i));const o=(e=e.trim()).toLowerCase(),c=$e.indexOf(o);return c>=0?e=re[c]:o in Y&&(e=Y[o]),t=t.trim(),(n=n.trim())&&N.includes(e)&&(r=`${n} ${r}`,n=""),t&&Q.includes(e)&&(r=`{${t}} ${r}`,t=""),{tag:e,type:t,name:n,description:r,default:a,...s}}))}(g),function(e){let t=e.description||"";e.description="",e.tags=e.tags.filter((({description:e,tag:n})=>n.toLowerCase()!==$||(e.trim()&&(t+="\n\n"+e),!1))),t&&e.tags.unshift({tag:$,description:t,name:void 0,type:void 0,source:[],optional:!1,problems:[]})}(g);const f=function(e,t,n){const r=t.split(/\r\n?|\n/g)[e.loc.start.line-1];let a=0,s=0;for(let t=e.loc.start.column-1;t>=0;t--){const e=r[t];if(" "===e)a++;else{if("\t"!==e)break;s++}}return n.printWidth-(a+s*n.tabWidth)-" * ".length}(e,a,o);let m=0,h=0,y=0,j=g.tags.map((({type:e,optional:t,...n})=>(e&&(e=e.replace(/[=]$/,(()=>(t=!0,""))),e=function(e,t){const n=[];let r=e.replace(/(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/g,(e=>(n.push(e),`String$${n.length-1}$`)));return r.includes("`")?e:(r=t(r),r.replace(/String\$(\d+)\$/g,((e,t)=>n[t])))}(e,(e=>{e=(e=(e=(e=e.trim()).replace(/\.</g,"<")).replace(/\*/g," any ")).replace(/^\?\s*(\w+)$/,"$1 | null").replace(/^(\w+)\s*\?$/,"$1 | null");let t=!0;for(;t;)t=!1,e=e.replace(/(^|[^$\w\xA0-\uFFFF])Array\s*<((?:[^<>=]|=>|=(?!>)|<(?:[^<>=]|=>|=(?!>))+>)+)>/g,((e,n,r)=>(t=!0,`${n}(${r})[]`)));return e}))),{...n,type:e,optional:t})));j=ye(j,d,o),o.jsdocSeparateReturnsFromParam&&(j=j.flatMap(((e,t)=>e.tag===z&&j[t-1]?.tag===O?[H,e]:[e]))),o.jsdocAddDefaultToDescription&&(j=j.map(we)),j=await Promise.all(j.map(ve).map((async({type:e,...t})=>(e&&(e=await async function(e,t){try{const r="type name = ";let a=e,s=!1;return a.startsWith("...")&&(s=!0,a=`(${a.slice(3)})[]`),a=await n.format(`${r}${a}`,{...t,parser:"typescript",plugins:[],filepath:"file.ts"}),a=a.slice(r.length),a=a.replace(/^\s*/g,"").replace(/[;\n]*$/g,"").replace(/^\|/g,"").trim(),s&&(a="..."+a.replace(/\[\s*\]$/,"")),a}catch(t){return e}}(e,{...o,printWidth:f})),{...t,type:e})))).then((e=>e.map((({type:e,name:t,description:n,tag:r,...a})=>(ee.includes(r)&&(m=Math.max(m,r.length),h=Math.max(h,e.length),y=Math.max(y,t.length)),{type:e,name:t,description:n,tag:r,...a}))))),o.jsdocSeparateTagGroups&&(j=j.flatMap(((e,t)=>{const n=j[t-1];return n&&n.tag!==$&&n.tag!==w&&n.tag!==H.tag&&e.tag!==H.tag&&n.tag!==e.tag?[H,e]:[e]})));const b=j.filter((({description:e,tag:t})=>!(!e&&Z.includes(t))));for(const[t,n]of b.entries()){const r=await de(n,t,b,{...o,printWidth:f},m,h,y);e.value+=r}e.value=e.value.trimEnd(),e.value&&(e.value=ae(e.value,o)),"cr"===p?e.value=e.value.replace(/\n/g,"\r"):"crlf"===p&&(e.value=e.value.replace(/\n/g,"\r\n"))}))),c.comments=c.comments.filter((e=>!(be(e)&&!e.value))),c};function ye(e,t,n){let r=!1,a=!1;return e=e.reduce(((e,t)=>((0===e.length||te.includes(t.tag)&&r)&&(r=!1,e.push([])),ne.includes(t.tag)&&(r=!0),e[e.length-1].push(t),e)),[]).flatMap(((e,r,s)=>(e.sort(((e,r)=>{if(t&&t.length>1&&e.tag===O&&r.tag===O){const n=t.indexOf(e.name),a=t.indexOf(r.name);return n>-1&&a>-1?n-a:0}return je(e.tag,n)-je(r.tag,n)})),s.length-1!==r&&e.push(H),r>0&&e[0]?.tag&&!te.includes(e[0].tag)&&(a=!0),e))),a?ye(e,t,n):e}function je(e,t){if(e===$&&!t.jsdocDescriptionTag)return-1;const n=re.indexOf(e);return-1===n?re.indexOf("other"):n}function be(e){return"CommentBlock"===e.type||"Block"===e.type}const $e=re.map((e=>e.toLowerCase()));function we(e){if(e.optional&&e.default){let{description:t}=e;return t=t.replace(/[\s]*Default[\s]*is[\s]*`.*`\.?$/,""),t&&!/[.\n]$/.test(t)&&(t+="."),t+=` Default is \`${e.default}\``,{...e,description:t.trim()}}return e}function ve({name:e,optional:t,default:n,tag:r,type:a,source:s,description:i,...o}){if(ce(r)){const t=(s.find((e=>e.source.includes(`@${r}`)))?.source||"").match(/@default(Value)? (\[.*]|{.*}|\(.*\)|'.*'|".*"|`.*`| \w+)( ((?!\*\/).+))?/),n=t?.[2]||"",o=t?.[4]||"";t&&(a=n,e="",i=o)}else t&&(e?e=n?`[${e}=${n}]`:`[${e}]`:a=`${a} | undefined`);return{...o,tag:r,name:e,description:i,optional:t,type:a,source:s,default:n}}const Se={jsdocParser:{name:"jsdocParser",type:"boolean",category:"jsdoc",default:!0,description:"Enable/Disable jsdoc parser"},jsdocSpaces:{name:"jsdocSpaces",type:"int",category:"jsdoc",default:1,description:"How many spaces will be used to separate tag elements."},jsdocDescriptionWithDot:{name:"jsdocDescriptionWithDot",type:"boolean",category:"jsdoc",default:!1,description:"Should dot be inserted at the end of description"},jsdocDescriptionTag:{name:"jsdocDescriptionTag",type:"boolean",category:"jsdoc",default:!1,description:"Should description tag be used"},jsdocVerticalAlignment:{name:"jsdocVerticalAlignment",type:"boolean",category:"jsdoc",default:!1,description:"Should tags, types, names and description be aligned"},jsdocKeepUnParseAbleExampleIndent:{name:"jsdocKeepUnParseAbleExampleIndent",type:"boolean",category:"jsdoc",default:!1,description:"Should unParseAble example (pseudo code or no js code) keep its indentation"},jsdocSingleLineComment:{name:"jsdocSingleLineComment",type:"boolean",category:"jsdoc",default:!0,description:"Should compact single line comment"},jsdocSeparateReturnsFromParam:{name:"jsdocSeparateReturnsFromParam",type:"boolean",category:"jsdoc",default:!1,description:"Add an space between last @param and @returns"},jsdocSeparateTagGroups:{name:"jsdocSeparateTagGroups",type:"boolean",category:"jsdoc",default:!1,description:"Add an space between tag groups"},jsdocCapitalizeDescription:{name:"jsdocCapitalizeDescription",type:"boolean",category:"jsdoc",default:!0,description:"Should capitalize first letter of description"},tsdoc:{name:"tsdoc",type:"boolean",category:"jsdoc",default:!1,description:"Should format as tsdoc"},jsdocPrintWidth:{name:"jsdocPrintWidth",type:"int",category:"jsdoc",default:void 0,description:"If You don't set value to jsdocPrintWidth, the printWidth will be use as jsdocPrintWidth."},jsdocAddDefaultToDescription:{name:"jsdocAddDefaultToDescription",type:"boolean",category:"jsdoc",default:!0,description:"Add Default value of a param to end description"},jsdocPreferCodeFences:{name:"jsdocPreferCodeFences",type:"boolean",category:"jsdoc",default:!1,description:'Prefer to render code blocks using "fences" (triple backticks). If not set, blocks without a language tag will be rendered with a four space indentation.'},jsdocLineWrappingStyle:{name:"jsdocLineWrappingStyle",type:"choice",choices:[{since:"0.3.39",value:"greedy",description:"Lines wrap as soon as they reach the print width"}],category:"jsdoc",default:"greedy",description:"Strategy for wrapping lines for the given print width. More options may be added in the future."}},xe={jsdocParser:Se.jsdocParser.default,jsdocSpaces:Se.jsdocSpaces.default,jsdocPrintWidth:Se.jsdocPrintWidth.default,jsdocDescriptionWithDot:Se.jsdocDescriptionWithDot.default,jsdocDescriptionTag:Se.jsdocDescriptionTag.default,jsdocVerticalAlignment:Se.jsdocVerticalAlignment.default,jsdocKeepUnParseAbleExampleIndent:Se.jsdocKeepUnParseAbleExampleIndent.default,jsdocSingleLineComment:Se.jsdocSingleLineComment.default,jsdocSeparateReturnsFromParam:Se.jsdocSeparateReturnsFromParam.default,jsdocSeparateTagGroups:Se.jsdocSeparateTagGroups.default,jsdocCapitalizeDescription:Se.jsdocCapitalizeDescription.default,jsdocAddDefaultToDescription:Se.jsdocAddDefaultToDescription.default,jsdocPreferCodeFences:Se.jsdocPreferCodeFences.default,tsdoc:Se.tsdoc.default,jsdocLineWrappingStyle:Se.jsdocLineWrappingStyle.default},Pe={get babel(){return De(p.default.parsers.babel,"babel")},get"babel-flow"(){return De(p.default.parsers["babel-flow"],"babel-flow")},get"babel-ts"(){return De(p.default.parsers["babel-ts"],"babel-ts")},get flow(){return De(d.default.parsers.flow,"flow")},get typescript(){return De(u.default.parsers.typescript,"typescript")},get"jsdoc-parser"(){return De(p.default.parsers["babel-ts"],"babel-ts")}};function De(e,t){const n=he(e.parse,t),r=(s,i)=>{const o=oe(t,i);if(!o)return e.preprocess?e.preprocess(s,i):s;const c=o.preprocess||e.preprocess;return Object.assign(a,{...a,...o,preprocess:r,parse:n}),c?c(s,i):s},a={...e,preprocess:r,parse:n};return a}e.defaultOptions=xe,e.options=Se,e.parsers=Pe,Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("comment-parser"),require("prettier"),require("binary-searching"),require("mdast-util-from-markdown"),require("prettier/plugins/babel"),require("prettier/plugins/flow"),require("prettier/plugins/typescript")):"function"==typeof define&&define.amd?define(["exports","comment-parser","prettier","binary-searching","mdast-util-from-markdown","prettier/plugins/babel","prettier/plugins/flow","prettier/plugins/typescript"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).sayHello={},e.commentParser,e.prettier,e.BSearch,e.mdastUtilFromMarkdown,e.parserBabel,e.parserFlow,e.parserTypescript)}(this,(function(e,t,n,r,a,s,i,o){"use strict";function c(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var l=c(r),p=c(s),d=c(i),u=c(o);const g="abstract",f="borrows",m="callback",h="category",y="class",j="constant",b="deprecated",$="description",w="example",S="extends",v="external",x="file",W="fires",k="function",D="ignore",L="license",P="member",C="memberof",A="module",T="namespace",E="overload",F="override",O="param",I="privateRemarks",M="property",_="remarks",z="returns",R="since",q="throws",U="todo",K="type",V="typedef",G="satisfies",B="yields",H={tag:"this_is_for_space",name:"",optional:!1,type:"",description:"",source:[],problems:[]},Y={arg:O,argument:O,const:j,constructor:y,desc:$,emits:W,examples:w,exception:q,fileoverview:x,func:k,host:v,method:k,overview:x,params:O,prop:M,return:z,var:P,virtual:g,yield:B,hidden:D},J=["default","defaultValue"],N=[f,h,b,$,w,S,L,A,T,E,F,I,_,z,R,q,U,B,x,...J],Q=[f,f,b,$,w,D,L,A,T,E,F,I,_,R,U,x],X=[f,...J,C,A,"see"],Z=[f,h,$,w,I,_,R,U],ee=[S,O,M,z,q,K,G,V,B],te=[m,V],ne=[...te,K,M,O,z,B,q],re=[_,I,"providesModule",A,L,"flow","async","private",D,C,"version",x,"author",b,R,h,$,w,g,"augments",j,...J,v,E,W,"template","typeParam",k,T,f,y,S,P,V,K,G,M,m,O,B,z,q,"other","see",U];function ae(e,t){return(e.match(new RegExp(t,"g"))||[]).length}function se(e){return e?e.match(/^https?:\/\//i)?e:e.startsWith("- ")?e.slice(0,2)+se(e.slice(2)):e[0].toUpperCase()+e.slice(1):e}async function ie(e,t,r){const{printWidth:a,jsdocKeepUnParseAbleExampleIndent:s}=r;e.split("\n").slice(1).every((e=>!e.trim()||e.startsWith(t)))&&(e=e.replace(new RegExp(`\n${t.replace(/[\t]/g,"[\\t]")}`,"g"),"\n"));try{let s="";const i=a-4;s=e.trim().startsWith("{")?await n.format(e||"",{...r,parser:"json",printWidth:i}):await n.format(e||"",{...r,printWidth:i}),e=s.replace(/(^|\n)/g,`\n${t}`)}catch(n){e=(e=`\n${e.split("\n").map((e=>`${t}${s?e:e.trim()}`)).join("\n")}\n`).replace(/^\n[\s]+\n/g,"\n")}return e}const oe=(e,t)=>{const n=t.plugins.find((t=>"object"==typeof t&&t.name&&t.parsers&&t.parsers.hasOwnProperty(e)));return!n||"prettier-plugin-jsdoc"===n.name||n.parsers?.hasOwnProperty("jsdoc-parser")?void 0:n.parsers?.[e]},ce=e=>J.includes(e),le="2@^5!~#sdE!_TABLE";async function pe(e,t,r,s){if(!t)return t;const{printWidth:i}=r,{tagStringLength:o=0,beginningSpace:c}=s,l=[...(t=(t=t.replace(/^(\d+)[-][\s|]+/g,"$1. ")).replace(/\n+(\s*\d+)[-][\s]+/g,"\n$1. ")).matchAll(/```\S*?\n[\s\S]+?```/gm),...t.matchAll(/^\r?\n^(?:(?:(?:[ ]{4}|\t).*(?:\r?\n|$))+)/gm)],p=[];t=t.replace(/((\n|^)\|[\s\S]*?)((\n[^|])|$)/g,((e,t,n,r,a,s)=>{for(const t of l)if(void 0!==t.index&&t.index<=s+1&&s+e.length+1<=t.index+t[0].length)return e;return e=r?e.slice(0,-1):e,p.push(e),`\n\n${le}\n\n${r?r.slice(1):""}`})),r.jsdocCapitalizeDescription&&!X.includes(e)&&(t=se(t)),t=`${o?`${"!".repeat(o-1)}?`:""}${t.startsWith("```")?"\n":""}${t}`;let d=0;t=t.replace(new RegExp(`\\n[ ]{${c.length}}`,"g"),"\n");const u=a.fromMarkdown(t);let g=await async function t(a,s,o){return Array.isArray(a.children)?(await Promise.all(a.children.map((async(n,c)=>{switch(n.type){case"listItem":{let e=`\n${s}- `;if("number"==typeof a.start){const t=c+(a.start??1);e=`\n${s}${t}. `}const r=s+" ".repeat(e.length-1);return`${e}${(await t(n,r,a)).trim()}`}case"list":{let r="";return e!==$&&"root"===a.type&&c===a.children.length-1&&(r="\n"),`\n${await t(n,s,a)}${r}`}case"paragraph":{const a=await t(n,s,o);return n.costumeType===le?a:`\n\n${a.split("\\\n").map((t=>{const n=[];t=t.replace(/{@(link|linkcode|linkplain)[\s](([^{}])*)}/g,((e,t,r)=>(n.push(r),`{@${t}${"_".repeat(r.length)}}`))),t=t.replace(/\s+/g," "),r.jsdocCapitalizeDescription&&!X.includes(e)&&(t=se(t)),r.jsdocDescriptionWithDot&&(t=t.replace(/([\w\p{L}])$/u,"$1."));let a=function(e,t,n){let r=e.trim();if(!r)return r;let a="";for(;r.length>t;){let e=r.lastIndexOf(" ",r.startsWith("\n")?t+1:t);e<=n.length&&(e=r.indexOf(" ",n.length+1)),-1===e&&(e=r.length),a+=r.substring(0,e),r=r.substring(e+1),r&&(r=`${n}${r}`,r=`\n${r}`)}return a+=r,`${n}${a}`}(t,i,s);return a=a.replace(/{@(link|linkcode|linkplain)([_]+)}/g,((e,t,r)=>{const a=n[0];return a.length===r.length?(n.shift(),`{@${t} ${a}}`):e})),a})).join("\\\n")}`}case"strong":return`**${await t(n,s,a)}**`;case"emphasis":return`_${await t(n,s,a)}_`;case"heading":return`\n\n${s}${"#".repeat(n.depth)} ${await t(n,s,a)}`;case"link":case"image":return`[${await t(n,s,a)}](${n.url})`;case"linkReference":return`[${await t(n,s,a)}][${n.label}]`;case"definition":return`\n\n[${n.label}]: ${n.url}`;case"blockquote":{const e=await t(n,"",a);return`${s}> ${e.trim().replace(/(\n+)/g,`$1${s}> `)}`}}return t(n,s,a)})))).join(""):async function(e,t,a){if("inlineCode"===e.type)return`\`${e.value}\``;if("code"===e.type){let n=e.value||"",a=t;if(n)if(e.lang){const a=(e=>{switch(e){case"js":case"javascript":case"jsx":return["babel","babel-flow","vue"];case"ts":case"typescript":case"tsx":return["typescript","babel-ts","angular"];case"json":case"css":return["css"];case"less":return["less"];case"scss":return["scss"];case"html":return["html"];case"yaml":return["yaml"];default:return["babel"]}})(e.lang.toLowerCase()),s=a?.includes(r.parser)?r.parser:a?.[0]||e.lang;n=await ie(n,t,{...r,parser:s,jsdocKeepUnParseAbleExampleIndent:!0})}else r.jsdocPreferCodeFences||(a=t+" ".repeat(4)),n=await ie(n,a,{...r,jsdocKeepUnParseAbleExampleIndent:!0});const s=r.jsdocPreferCodeFences||!!e.lang;return n=s?n:n.trimEnd(),n?s?`\n\n${a}\`\`\`${e.lang||""}${n}\`\`\``:`\n${n}`:""}if(e.value===le&&(a&&(a.costumeType=le),p.length>0)){let a=p?.[d]||"";return d++,a&&(a=(await n.format(a,{...r,parser:"markdown"})).trim()),`${a?`\n\n${t}${a.split("\n").join(`\n${t}`)}`:e.value}`}return"break"===e.type?"\\\n":e.value||e.title||e.alt||""}(a,s,o)}(u,c,null);return g=g.replace(/^[\s\n]+/g,""),g=g.replace(/^([!]+\?)/g,""),g}const de=async({name:e,description:t,type:n,tag:r},a,s,i,o,c,l)=>{let p="\n";if(r===H.tag)return p;const{printWidth:d,jsdocSpaces:u,jsdocVerticalAlignment:g,jsdocDescriptionTag:f,tsdoc:m,useTabs:h,tabWidth:y,jsdocSeparateTagGroups:j}=i,b=" ".repeat(u);let S=0,v=0,x=0,W=0;g&&ee.includes(r)&&(r?S+=o-r.length:o&&(W+=o+b.length),n?v+=c-n.length:c&&(W+=c+b.length),e?x+=l-e.length:l&&(W=l+b.length));const k=r!==$||f;if(k&&(p+=`@${r}${" ".repeat(S||0)}`),n){p+=b+(()=>{if(!ce(r))return`{${n}}`;if("[]"===n)return"[ ]";if("{}"===n)return"{ }";return/^{.*[A-z0-9_]+ ?:.*}$/.test(n)?n.replace(/; ([A-z0-9_])/g,", $1"):n})()+" ".repeat(v)}if(e&&(p+=`${b}${e}${" ".repeat(x)}`),r!==w||m){if(t){let e="";if(k&&(p+=b+" ".repeat(W)),X.includes(r)||!re.includes(r))e=t;else{const[,n]=/^\s*(\S+)/.exec(t)||["",""],a=r===$||[w,_,I].includes(r)&&m?"":" ";e=r!==$&&p.length+n.length>d||[_,I].includes(r)?`\n${a}`+await pe(r,t,i,{beginningSpace:a}):await pe(r,t,i,{tagStringLength:p.length-1,beginningSpace:a})}j&&(e=e.trimEnd()),p+=e.startsWith("\n")?e.replace(/^\n[\s]+\n/g,"\n"):e.trimStart()}}else{const e=t.match(/<caption>([\s\S]*?)<\/caption>/i);e&&(t=t.replace(e[0],""),p=`${p} ${e[0]}`);const n=h?"\t":" ".repeat(y);p+=(await ie(t,n,i)).replace(new RegExp(`^\\n${n.replace(/[\t]/g,"[\\t]").replace(/[^S\r\n]/g,"[^S\\r\\n]")}\\n`),"").trimEnd()}return p+=function({tag:e,isEndTag:t}){return[$,w,U].includes(e)&&!t?"\n":""}({tag:r,isEndTag:a===s.length-1}),p},{name:ue,tag:ge,type:fe,description:me}=t.tokenizers,he=(e,r)=>async function(a,s,i){let o=i??s;const c=(oe(r,o)?.parse||e)(a,o);o={...o,printWidth:o.jsdocPrintWidth??o.printWidth};const p="auto"===o.endOfLine?function(e){const t={"\r":0,"\r\n":0,"\n":0},n=/\r\n?|\n/g;let r;for(;r=n.exec(e);)t[r[0]]++;const a=t["\r"],s=t["\r\n"],i=t["\n"],o=Math.max(a,s,i);return i===o?"lf":s===o?"crlf":"cr"}(a):o.endOfLine;return o={...o,endOfLine:"lf"},await Promise.all(c.comments.map((async e=>{if(!be(e))return;const r=(s=c.tokens,i=e,l.default.eq(s,i,((e,t)=>e.loc.start.line===t.loc.start.line?e.loc.start.column-t.loc.start.column:e.loc.start.line-t.loc.start.line)));var s,i;const d=function(e,t){let n;try{const r=e.tokens[t+1]?.type;if("object"!=typeof r)return;if("function"===r.label){let r=1;const a=e.tokens.slice(t+4),s=a.findIndex((({type:e})=>"string"!=typeof e&&("("===e.label?r++:")"===e.label&&r--,0===r)));n=a.slice(0,s+1)}if("const"===r.label){let r=1,a=e.tokens.slice(t+1);const s=a.findIndex((({type:e})=>"object"==typeof e&&"("===e.label));a=a.slice(s+1);const i=a.findIndex((({type:e})=>"string"!=typeof e&&("("===e.label?r++:")"===e.label&&r--,0===r))),o=a[i+1];"object"==typeof o?.type&&"=>"===o.type.label&&(n=a.slice(0,i+1))}return n?.filter((({type:e})=>"object"==typeof e&&"name"===e.label)).map((({value:e})=>e))}catch{}return}(c,r),u=e.value;e.value=e.value.replace(/^([*]+)/g,"*");const g=`/*${e.value.replace(/\r\n?/g,"\n")}*/`;if(!/^\/\*\*[\s\S]+?\*\/$/.test(g))return;const f=t.parse(g,{spacing:"preserve",tokenizers:[ge(),e=>ce(e.tag)?e:fe("preserve")(e),ue(),me("preserve")]})[0];if(e.value="",!f)return;!function(e){e.tags=e.tags.map((({tag:e,type:t,name:n,description:r,default:a,...s})=>{e=e||"",t=t||"",n=n||"",r=r||"",a=a?.trim();const i=e.indexOf("{");-1!==i&&"}"===e[e.length-1]&&(t=e.slice(i+1,-1)+" "+t,e=e.slice(0,i));const o=(e=e.trim()).toLowerCase(),c=$e.indexOf(o);return c>=0?e=re[c]:o in Y&&(e=Y[o]),t=t.trim(),(n=n.trim())&&N.includes(e)&&(r=`${n} ${r}`,n=""),t&&Q.includes(e)&&(r=`{${t}} ${r}`,t=""),{tag:e,type:t,name:n,description:r,default:a,...s}}))}(f),function(e){let t=e.description||"";e.description="",e.tags=e.tags.filter((({description:e,tag:n})=>n.toLowerCase()!==$||(e.trim()&&(t+="\n\n"+e),!1))),t&&e.tags.unshift({tag:$,description:t,name:void 0,type:void 0,source:[],optional:!1,problems:[]})}(f);const m=function(e,t,n){const r=t.split(/\r\n?|\n/g)[e.loc.start.line-1];let a=0,s=0;for(let t=e.loc.start.column-1;t>=0;t--){const e=r[t];if(" "===e)a++;else{if("\t"!==e)break;s++}}return n.printWidth-(a+s*n.tabWidth)-" * ".length}(e,a,o);let h=0,y=0,j=0,b=f.tags.map((({type:e,optional:t,...n})=>(e&&(e=e.replace(/[=]$/,(()=>(t=!0,""))),e=function(e,t){const n=[];let r=e.replace(/(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/g,(e=>(n.push(e),`String$${n.length-1}$`)));return r.includes("`")?e:(r=t(r),r.replace(/String\$(\d+)\$/g,((e,t)=>n[t])))}(e,(e=>{e=(e=(e=(e=e.trim()).replace(/\.</g,"<")).replace(/\*/g," any ")).replace(/^\?\s*(\w+)$/,"$1 | null").replace(/^(\w+)\s*\?$/,"$1 | null");let t=!0;for(;t;)t=!1,e=e.replace(/(^|[^$\w\xA0-\uFFFF])Array\s*<((?:[^<>=]|=>|=(?!>)|<(?:[^<>=]|=>|=(?!>))+>)+)>/g,((e,n,r)=>(t=!0,`${n}(${r})[]`)));return e}))),{...n,type:e,optional:t})));b=ye(b,d,o),o.jsdocSeparateReturnsFromParam&&(b=b.flatMap(((e,t)=>e.tag===z&&b[t-1]?.tag===O?[H,e]:[e]))),o.jsdocAddDefaultToDescription&&(b=b.map(we)),b=await Promise.all(b.map(Se).map((async({type:e,...t})=>(e&&(e=await async function(e,t){try{const r="type name = ";let a=e,s=!1;return a.startsWith("...")&&(s=!0,a=`(${a.slice(3)})[]`),a=await n.format(`${r}${a}`,{...t,parser:"typescript",plugins:[],filepath:"file.ts"}),a=a.slice(r.length),a=a.replace(/^\s*/g,"").replace(/[;\n]*$/g,"").replace(/^\|/g,"").trim(),s&&(a="..."+a.replace(/\[\s*\]$/,"")),a}catch(t){return e}}(e,{...o,printWidth:m})),{...t,type:e})))).then((e=>e.map((({type:e,name:t,description:n,tag:r,...a})=>(ee.includes(r)&&(h=Math.max(h,r.length),y=Math.max(y,e.length),j=Math.max(j,t.length)),{type:e,name:t,description:n,tag:r,...a}))))),o.jsdocSeparateTagGroups&&(b=b.flatMap(((e,t)=>{const n=b[t-1];return n&&n.tag!==$&&n.tag!==w&&n.tag!==H.tag&&e.tag!==H.tag&&n.tag!==e.tag?[H,e]:[e]})));const S=b.filter((({description:e,tag:t})=>!(!e&&Z.includes(t))));for(const[t,n]of S.entries()){const r=await de(n,t,S,{...o,printWidth:m},h,y,j);e.value+=r}e.value=e.value.trimEnd(),e.value&&(e.value=function(e,t,n){return"singleLine"===n.jsdocCommentLineStrategy&&0===ae(t.trim(),"\n")||"keep"===n.jsdocCommentLineStrategy&&0===ae(e,"\n")?`* ${t.trim()} `:`*${t.replace(/(\n(?!$))/g,"\n * ")}\n `}(u,e.value,o)),"cr"===p?e.value=e.value.replace(/\n/g,"\r"):"crlf"===p&&(e.value=e.value.replace(/\n/g,"\r\n"))}))),c.comments=c.comments.filter((e=>!(be(e)&&!e.value))),c};function ye(e,t,n){let r=!1,a=!1;return e=e.reduce(((e,t)=>((0===e.length||te.includes(t.tag)&&r)&&(r=!1,e.push([])),ne.includes(t.tag)&&(r=!0),e[e.length-1].push(t),e)),[]).flatMap(((e,r,s)=>(e.sort(((e,r)=>{if(t&&t.length>1&&e.tag===O&&r.tag===O){const n=t.indexOf(e.name),a=t.indexOf(r.name);return n>-1&&a>-1?n-a:0}return je(e.tag,n)-je(r.tag,n)})),s.length-1!==r&&e.push(H),r>0&&e[0]?.tag&&!te.includes(e[0].tag)&&(a=!0),e))),a?ye(e,t,n):e}function je(e,t){if(e===$&&!t.jsdocDescriptionTag)return-1;const n=re.indexOf(e);return-1===n?re.indexOf("other"):n}function be(e){return"CommentBlock"===e.type||"Block"===e.type}const $e=re.map((e=>e.toLowerCase()));function we(e){if(e.optional&&e.default){let{description:t}=e;return t=t.replace(/[\s]*Default[\s]*is[\s]*`.*`\.?$/,""),t&&!/[.\n]$/.test(t)&&(t+="."),t+=` Default is \`${e.default}\``,{...e,description:t.trim()}}return e}function Se({name:e,optional:t,default:n,tag:r,type:a,source:s,description:i,...o}){if(ce(r)){const t=(s.find((e=>e.source.includes(`@${r}`)))?.source||"").match(/@default(Value)? (\[.*]|{.*}|\(.*\)|'.*'|".*"|`.*`| \w+)( ((?!\*\/).+))?/),n=t?.[2]||"",o=t?.[4]||"";t&&(a=n,e="",i=o)}else t&&(e?e=n?`[${e}=${n}]`:`[${e}]`:a=`${a} | undefined`);return{...o,tag:r,name:e,description:i,optional:t,type:a,source:s,default:n}}const ve={jsdocSpaces:{name:"jsdocSpaces",type:"int",category:"jsdoc",default:1,description:"How many spaces will be used to separate tag elements."},jsdocDescriptionWithDot:{name:"jsdocDescriptionWithDot",type:"boolean",category:"jsdoc",default:!1,description:"Should dot be inserted at the end of description"},jsdocDescriptionTag:{name:"jsdocDescriptionTag",type:"boolean",category:"jsdoc",default:!1,description:"Should description tag be used"},jsdocVerticalAlignment:{name:"jsdocVerticalAlignment",type:"boolean",category:"jsdoc",default:!1,description:"Should tags, types, names and description be aligned"},jsdocKeepUnParseAbleExampleIndent:{name:"jsdocKeepUnParseAbleExampleIndent",type:"boolean",category:"jsdoc",default:!1,description:"Should unParseAble example (pseudo code or no js code) keep its indentation"},jsdocSingleLineComment:{name:"jsdocSingleLineComment",type:"boolean",category:"jsdoc",deprecated:"use jsdocCommentLineStrategy instead will be remove on v2",default:!0,description:"Should compact single line comment"},jsdocCommentLineStrategy:{name:"jsdocCommentLineStrategy",type:"choice",choices:[{since:"1.1.0",value:"singleLine",description:"Should compact single line comment, if possible"},{since:"1.1.0",value:"multiline",description:"Should compact multi line comment"},{since:"1.1.0",value:"keep",description:"Should keep original line comment"}],category:"jsdoc",default:"singleLine",description:"How comments line should be"},jsdocSeparateReturnsFromParam:{name:"jsdocSeparateReturnsFromParam",type:"boolean",category:"jsdoc",default:!1,description:"Add an space between last @param and @returns"},jsdocSeparateTagGroups:{name:"jsdocSeparateTagGroups",type:"boolean",category:"jsdoc",default:!1,description:"Add an space between tag groups"},jsdocCapitalizeDescription:{name:"jsdocCapitalizeDescription",type:"boolean",category:"jsdoc",default:!0,description:"Should capitalize first letter of description"},tsdoc:{name:"tsdoc",type:"boolean",category:"jsdoc",default:!1,description:"Should format as tsdoc"},jsdocPrintWidth:{name:"jsdocPrintWidth",type:"int",category:"jsdoc",default:void 0,description:"If You don't set value to jsdocPrintWidth, the printWidth will be use as jsdocPrintWidth."},jsdocAddDefaultToDescription:{name:"jsdocAddDefaultToDescription",type:"boolean",category:"jsdoc",default:!0,description:"Add Default value of a param to end description"},jsdocPreferCodeFences:{name:"jsdocPreferCodeFences",type:"boolean",category:"jsdoc",default:!1,description:'Prefer to render code blocks using "fences" (triple backticks). If not set, blocks without a language tag will be rendered with a four space indentation.'},jsdocLineWrappingStyle:{name:"jsdocLineWrappingStyle",type:"choice",choices:[{since:"0.3.39",value:"greedy",description:"Lines wrap as soon as they reach the print width"}],category:"jsdoc",default:"greedy",description:"Strategy for wrapping lines for the given print width. More options may be added in the future."}},xe={jsdocSpaces:ve.jsdocSpaces.default,jsdocPrintWidth:ve.jsdocPrintWidth.default,jsdocDescriptionWithDot:ve.jsdocDescriptionWithDot.default,jsdocDescriptionTag:ve.jsdocDescriptionTag.default,jsdocVerticalAlignment:ve.jsdocVerticalAlignment.default,jsdocKeepUnParseAbleExampleIndent:ve.jsdocKeepUnParseAbleExampleIndent.default,jsdocSingleLineComment:ve.jsdocSingleLineComment.default,jsdocCommentLineStrategy:ve.jsdocCommentLineStrategy.default,jsdocSeparateReturnsFromParam:ve.jsdocSeparateReturnsFromParam.default,jsdocSeparateTagGroups:ve.jsdocSeparateTagGroups.default,jsdocCapitalizeDescription:ve.jsdocCapitalizeDescription.default,jsdocAddDefaultToDescription:ve.jsdocAddDefaultToDescription.default,jsdocPreferCodeFences:ve.jsdocPreferCodeFences.default,tsdoc:ve.tsdoc.default,jsdocLineWrappingStyle:ve.jsdocLineWrappingStyle.default},We={get babel(){return ke(p.default.parsers.babel,"babel")},get"babel-flow"(){return ke(p.default.parsers["babel-flow"],"babel-flow")},get"babel-ts"(){return ke(p.default.parsers["babel-ts"],"babel-ts")},get flow(){return ke(d.default.parsers.flow,"flow")},get typescript(){return ke(u.default.parsers.typescript,"typescript")},get"jsdoc-parser"(){return ke(p.default.parsers["babel-ts"],"babel-ts")}};function ke(e,t){const n=he(e.parse,t),r=(s,i)=>{!function(e){if(e.jsdocCommentLineStrategy)return;e.jsdocSingleLineComment?e.jsdocCommentLineStrategy="singleLine":e.jsdocCommentLineStrategy="multiline"}(i);const o=oe(t,i);if(!o)return e.preprocess?e.preprocess(s,i):s;const c=o.preprocess||e.preprocess;return Object.assign(a,{...a,...o,preprocess:r,parse:n}),c?c(s,i):s},a={...e,preprocess:r,parse:n};return a}e.defaultOptions=xe,e.options=ve,e.parsers=We,Object.defineProperty(e,"__esModule",{value:!0})}));

@@ -12,5 +12,2 @@ import { parse, tokenizers } from "comment-parser";

const ast = prettierParse(text, options);
if (options.jsdocParser === false) {
return ast;
}
options = {

@@ -27,2 +24,3 @@ ...options,

const paramsOrder = getParamsOrders(ast, tokenIndex);
const originalValue = comment.value;
comment.value = comment.value.replace(/^([*]+)/g, "*");

@@ -137,3 +135,3 @@ const commentString = `/*${comment.value.replace(/\r\n?/g, "\n")}*/`;

if (comment.value) {
comment.value = addStarsToTheBeginningOfTheLines(comment.value, options);
comment.value = addStarsToTheBeginningOfTheLines(originalValue, comment.value, options);
}

@@ -140,0 +138,0 @@ if (eol === "cr") {

import { ParserOptions } from "prettier";
export interface JsdocOptions {
jsdocParser: boolean;
jsdocSpaces: number;

@@ -11,2 +10,3 @@ jsdocPrintWidth?: number;

jsdocSingleLineComment: boolean;
jsdocCommentLineStrategy: "singleLine" | "multiline" | "keep";
jsdocSeparateReturnsFromParam: boolean;

@@ -13,0 +13,0 @@ jsdocSeparateTagGroups: boolean;

@@ -5,3 +5,3 @@ import { Options, ParserOptions } from "prettier";

declare function formatType(type: string, options?: Options): Promise<string>;
declare function addStarsToTheBeginningOfTheLines(comment: string, options: AllOptions): string;
declare function addStarsToTheBeginningOfTheLines(originalComment: string, comment: string, options: AllOptions): string;
declare function capitalizer(str: string): string;

@@ -8,0 +8,0 @@ declare function detectEndOfLine(text: string): "cr" | "crlf" | "lf";

@@ -65,5 +65,7 @@ import { format } from "prettier";

}
function addStarsToTheBeginningOfTheLines(comment, options) {
if (options.jsdocSingleLineComment &&
numberOfAStringInString(comment.trim(), "\n") === 0) {
function addStarsToTheBeginningOfTheLines(originalComment, comment, options) {
if ((options.jsdocCommentLineStrategy === "singleLine" &&
numberOfAStringInString(comment.trim(), "\n") === 0) ||
(options.jsdocCommentLineStrategy === "keep" &&
numberOfAStringInString(originalComment, "\n") === 0)) {
return `* ${comment.trim()} `;

@@ -70,0 +72,0 @@ }

{
"name": "prettier-plugin-jsdoc",
"version": "1.0.5",
"version": "1.1.0",
"description": "A Prettier plugin to format JSDoc comments.",

@@ -26,3 +26,3 @@ "private": false,

"clean": "rm -fr dist",
"build": "node script.mjs"
"build": "chmod +x ./script.sh && ./script.sh"
},

@@ -51,3 +51,3 @@ "keywords": [

"@types/jest": "^29.5.4",
"@types/mdast": "^3.0.10",
"@types/mdast": "^4.0.1",
"@typescript-eslint/eslint-plugin": "^6.6.0",

@@ -76,3 +76,3 @@ "@typescript-eslint/parser": "^6.6.0",

"comment-parser": "^1.4.0",
"mdast-util-from-markdown": "^1.2.0"
"mdast-util-from-markdown": "^2.0.0"
},

@@ -79,0 +79,0 @@ "engines": {

+15
-15

@@ -185,17 +185,17 @@ [![NPM](https://nodei.co/npm/prettier-plugin-jsdoc.png)](https://nodei.co/npm/prettier-plugin-jsdoc/)

| Key | type | Default | description |
| :-------------------------------- | :------ | :-------- | ----------------------------------------------------------------------------------------- |
| jsdocSpaces | Number | 1 |
| jsdocDescriptionWithDot | Boolean | false |
| jsdocDescriptionTag | Boolean | false |
| jsdocVerticalAlignment | Boolean | false |
| jsdocKeepUnParseAbleExampleIndent | Boolean | false |
| jsdocSingleLineComment | Boolean | true |
| jsdocCapitalizeDescription | Boolean | true |
| jsdocSeparateReturnsFromParam | Boolean | false | Add an space between last @param and @returns |
| jsdocSeparateTagGroups | Boolean | false | Add an space between tag groups |
| jsdocPreferCodeFences | Boolean | false | Always fence code blocks (surround them by triple backticks) |
| tsdoc | Boolean | false |
| jsdocPrintWidth | Number | undefined | If You don't set value to jsdocPrintWidth, the printWidth will be use as jsdocPrintWidth. |
| jsdocLineWrappingStyle | String | "greedy" | "greedy": Lines wrap as soon as they reach the print width |
| Key | type | Default | description |
| :-------------------------------- | :-------------------------------- | :-------- | ----------------------------------------------------------------------------------------- |
| jsdocSpaces | Number | 1 |
| jsdocDescriptionWithDot | Boolean | false |
| jsdocDescriptionTag | Boolean | false |
| jsdocVerticalAlignment | Boolean | false |
| jsdocKeepUnParseAbleExampleIndent | Boolean | false |
| jsdocCommentLineStrategy | ("singleLine","multiline","keep") | true |
| jsdocCapitalizeDescription | Boolean | true |
| jsdocSeparateReturnsFromParam | Boolean | false | Add an space between last @param and @returns |
| jsdocSeparateTagGroups | Boolean | false | Add an space between tag groups |
| jsdocPreferCodeFences | Boolean | false | Always fence code blocks (surround them by triple backticks) |
| tsdoc | Boolean | false |
| jsdocPrintWidth | Number | undefined | If You don't set value to jsdocPrintWidth, the printWidth will be use as jsdocPrintWidth. |
| jsdocLineWrappingStyle | String | "greedy" | "greedy": Lines wrap as soon as they reach the print width |

@@ -202,0 +202,0 @@ Full up to date list and description of options can be found in Prettier help. First install plugin then run Prettier with "--help" option.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet