@moneko/core 4.7.1 → 4.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1,7 @@
1
- import{dirname as e}from"node:path";import t from"typescript";import{getGitInfo as n}from"./git.mjs";let r=n(),l=t.ScriptKind,o=t.ScriptTarget,i=t.SyntaxKind,a=t.createSourceFile,c=t.forEachChild,s=t.getLeadingCommentRanges,u=t.isInterfaceDeclaration,f=t.isQuestionToken,p=t.isPropertySignature,m=t.isFunctionTypeNode,g=t.isUnionTypeNode,$=t.isMethodSignature,d={};function h(e){let t=s(e.getSourceFile().text,e.pos);if(t){let n=e.getSourceFile().text.slice(t[0].pos,t[0].end).match(/\/\*\*([\s\S]*?)\*\//);if(n)return n[1].replaceAll(/^\s*\* ?/gm,"").replace(/\s+$/,"").trim()}}function b(e){if(!e)return;let t=e.match(/@since\s+([^\n]+)/);return t?t[1].trim():void 0}function y(e){let t;if(!e)return;let n=/@author\s+([^<\n]+?)(?:\s*<([^>]+)>)?(?=\s*(?:\n|$))/g,l=[];for(;null!==(t=n.exec(e));){let e,n=t[1].trim(),o=t[2]?.trim();if(o){let t=/^[\w.-]+@[\w-]+(\.[\w-]+)+$/.test(o),n=/^https?:\/\/.+/i.test(o);e=t?`mailto:${o}`:n?o:`${r?.domain}/${o}`}else/^[a-z\d](?:[a-z\d-]{0,38})$/i.test(n)&&(e=`${r?.domain}/${n}`);let i=e?`[![${n}-alt](${r?.type==="github"?`https://avatars.githubusercontent.com/${e.split("/").pop()}?s=48`:`https://www.gravatar.com/avatar/${n}?s=48&d=identicon`})${n}](${e})`:n;l.includes(i)||l.push(i)}return l.join(" ")}function x(e){if(!e)return;let t=e.match(/@ignore\s+([^\n]+)/);return t?t[1].trim():void 0}let A=/(?<!['"])(unknown|any|void|bigint|object|undefined|null|boolean|number|string|symbol)(?!['"])/g;function j(e,t,n){if(!t)return;let r=t.replaceAll(/\b([A-Z][a-zA-Z0-9]*)\b/g,t=>{if(d[t]){let r=`/${[e,d[t]].join("/").split("/").filter(Boolean).join("/")}`;return n?`[\\color{#009688}{${t}}](${r})`:`[${t}](${r})`}return n?`\\color{#009688}{${t}}`:t});return n&&(r=r.replaceAll(A,e=>`\\color{#009688}{${e}}`)),r}function S(e){if(e)return(function(e){let t;if(!e)return;let n=[];for(;t=/\\color{([^|}]*)\|?([^|}]*)\|?([^|}]*)\|?([^}]*)}{([^}]*)}/g.exec(e);)n.push(t[0]);return e.replaceAll(/[{}[\]()=>]|keyof|typeof|true|false/g,e=>n.some(t=>t.includes(e))?e:`\\color{#569cd6}{${e}}`)})(e)?.replaceAll(/^\s*\|\s*|\s*\|\s*$/gm,"").replaceAll(/\n/g,"<br/>").replaceAll(/\*/g,"\\*").replaceAll(/\|/g,"\\|").replaceAll(/(['"])((?:(?!\1).)*)\1/g,"\\color{#ce9178}{$1$2$1}")}function T(e){if(e)return e.replaceAll(/@example\s*([\s\S]*?)(?=@[a-zA-Z]|\n*$)/g,"").replaceAll(/^@[a-z].+/gm,"").replaceAll(/(\n\s+)+/g,"<br />").replaceAll(/\n/g,"<br />").replaceAll(/(<br \/>)$/g,"")}export function declToMd(n,r,s,A){let v=a(r,n,o.Latest,!0,l.TS),w="";return c(v,n=>{u(n)?w+=function(n,r,l){let o=r.name.text;Object.assign(d,{[r.name.text]:e(r.getSourceFile().fileName).replace(l,"")});let a=h(r),c=b(a),s=T(a),u=x(a)?.split("|")||[],A=u.includes("comment"),v=u.includes("initial"),w=u.includes("optional"),k=u.includes("version"),B=u.includes("author"),z=s?`\\color{|4||0.45}{${o}}`:o,F=(function(e){let n=[];if(e.heritageClauses){for(let r of e.heritageClauses)if(r.token===t.SyntaxKind.ExtendsKeyword)for(let e of r.types)n.push(e.getText())}return n})(r)?.map(e=>`<n-tag color="#4c81db" css=".tag{gap:0px;}">${j(n,S(e))}</n-tag>`),N=[s,z,c&&`\\color{#52c11b|1||0.9}{${c}}`,F.length>0&&`<sub>\`extends\`</sub> ${F.join(" ")}`].filter(Boolean).join(" "),K=`## ${N}`,C=r.members.filter(e=>p(e)&&e.type?.kind!==i.NeverKeyword||$(e)),Z=[];if(C.length>0){for(let e=0,t=C.length;e<t;e++){let t=C[e],r=j(n,S($(t)?`(${t.parameters.map(e=>`${e.name.getText()}: ${e.type?.getText()||"any"}`).join(", ")}): ${t.type?.getText()||"any"}`:t.type?.getText()||"any"),!0),l=h(t),o=S(t.name.getText());o&&!o.startsWith("\\color")&&($(t)||function(e){if(e.type){if(!g(e.type))return m(e.type);else for(let t of e.type.types)if(m(t))return!0}return!1}(t)||r?.includes("=>")?o=`\\color{#f9a913}{${o}}`:/^["'](.+)["']$/.test(o)||(o=`\\color{#4c81db}{${o}}`));let i=t.questionToken&&f(t.questionToken);Z.push([o,!w&&`\\color{${i?"#f9a913":"#52c11b"}\\|\\|\\|0.9}{${i?"✘":"✔"}}`,!A&&S(T(l)),r,!v&&S(function(e){if(!e)return;let t=e.match(/@default\s+([^\n]+)/);return t?t[1].trim():void 0}(l)),!k&&S(b(l)),!B&&(y(l)||y(a)),function(e){if(!e)return;let t=e.match(/@example\s*([\s\S]*?)(?=@[a-zA-Z]|\n*$)/);return t?t[1].trim():void 0}(l)])}let e=!1,t=!1,r=!1,l=!1;for(let n=0,o=Z.length;n<o;n++){let o=Z[n];!A&&o[2]&&(l=!0),!v&&o[4]&&(r=!0),!k&&o[5]&&(t=!0),!B&&o[6]&&(e=!0)}K+="\n";let o=["属性",!w&&"必要",l&&"说明","类型",r&&"默认值",t&&"版本",e&&"作者"].filter(Boolean).join("|");K+=`|${o}|`;let i=[":-",!w&&":-",l&&":-",":-",r&&":-",t&&":-",e&&":-"].filter(Boolean);K+="\n";let c=i.join("|");K+=`|${c}|`;for(let n=0,o=Z.length;n<o;n++){let o=Z[n];K+="\n";let i=[(o[7]?`<n-popover arrow="true" trigger="click" content=${JSON.stringify(`<n-md css=.n-md-body{margin-bottom:0;padding:0.5rem;background-color:transparent;backdrop-filter:none;box-shadow:none;}>${o[7]}</n-md>`)}><n-button size="small" type="primary" circle="true" style="margin-right:8px;">?</n-button></n-popover>`:"")+(o[0]||"-"),!w&&(o[1]||"-"),l&&(o[2]||"-"),o[3]||"-",r&&(o[4]||"-"),t&&(o[5]||"-"),e&&(o[6]||"-")].filter(Boolean).join("|");K+=`|${i}|`}K+="\n"}return K+"\n"}(s,n,A):t.isEnumDeclaration(n)&&(w+=function(n,r){let l=n.name.text,o=h(n),i=T(o),a=b(o);Object.assign(d,{[n.name.text]:e(n.getSourceFile().fileName).replace(r,"")});let c=i?`\\color{|4||0.45}{${l}}`:l,s=[i,c,a&&`\\color{#52c11b|1||0.9}{${a}}`].filter(Boolean).join(" "),u=x(o)?.split("|")||[],f=u.includes("comment"),p=u.includes("version"),m=u.includes("author"),g=`## ${s}`;if(n.members.length>0){let e=[];for(let r=0,l=n.members.length;r<l;r++){let l=n.members[r],i=S(l.name.getText()),a=h(l),c=S(function(e){let n=e.initializer;if(n&&t.isStringLiteral(n))return` '${n.text}'`}(l)),s=S(b(a)),u=S(T(a));!i||i.startsWith("\\color")||/^["'](.+)["']$/.test(i)||(i=`\\color{#4c81db}{${i}}`),e.push([i,!f&&u,c,!p&&s,!m&&(y(a)||y(o))])}let r=!1,l=!1,i=!1;for(let t=0,n=e.length;t<n;t++){let n=e[t];!f&&n[1]&&(i=!0),!p&&n[3]&&(l=!0),!m&&n[4]&&(r=!0)}g+="\n";let a=["属性",i&&"说明","值",l&&"版本",r&&"作者"].filter(Boolean).join("|");g+=`|${a}|`;let c=[":-",i&&":-",":-",l&&":-",r&&":-"].filter(Boolean);g+="\n";let s=c.join("|");g+=`|${s}|`;for(let t=0,n=e.length;t<n;t++){let n=e[t];g+="\n";let o=[n[0]||"-",i&&(n[1]||"-"),n[2]||"-",l&&(n[3]||"-"),r&&(n[4]||"-")].filter(Boolean).join("|");g+=`|${o}|`}}return g+"\n\n"}(n,A))}),w}
1
+ import{dirname as e}from"node:path";import t from"typescript";import{getGitInfo as n}from"./git.mjs";let l=n(),r=t.ScriptKind,o=t.ScriptTarget,i=t.SyntaxKind,a=t.createSourceFile,c=t.forEachChild,s=t.getLeadingCommentRanges,u=t.isInterfaceDeclaration,f=t.isQuestionToken,p=t.isPropertySignature,m=t.isFunctionTypeNode,g=t.isUnionTypeNode,d=t.isMethodSignature,$={};function h(e){let t=s(e.getSourceFile().text,e.pos);if(t){let n=e.getSourceFile().text.slice(t[0].pos,t[0].end).match(/\/\*\*([\s\S]*?)\*\//);if(n)return n[1].replaceAll(/^\s*\* ?/gm,"").replace(/\s+$/,"").trim()}}function b(e){if(!e)return;let t=e.match(/@since\s+([^\n]+)/);return t?t[1].trim():void 0}function y(e){let t;if(!e)return;let n=/@author\s+([^<\n]+?)(?:\s*<([^>]+)>)?(?=\s*(?:\n|$))/g,r=[];for(;null!==(t=n.exec(e));){let e,n=t[1].trim(),o=t[2]?.trim();if(o){let t=/^[\w.-]+@[\w-]+(\.[\w-]+)+$/.test(o),n=/^https?:\/\/.+/i.test(o);e=t?`mailto:${o}`:n?o:`${l?.domain}/${o}`}else/^[a-z\d](?:[a-z\d-]{0,38})$/i.test(n)&&(e=`${l?.domain}/${n}`);let i=e?`[![${n}-alt](${l?.type==="github"?`https://avatars.githubusercontent.com/${e.split("/").pop()}?s=48`:`https://www.gravatar.com/avatar/${n}?s=48&d=identicon`})${n}](${e})`:n;r.includes(i)||r.push(i)}return r.join(" ")}function x(e){if(!e)return;let t=e.match(/@ignore\s+([^\n]+)/);return t?t[1].trim():void 0}let S=/(?<!['"])(unknown|any|void|bigint|object|undefined|null|boolean|number|string|symbol)(?!['"])/g;function A(e,t,n){if(!t)return;let l=t.replaceAll(/\b([A-Z][a-zA-Z0-9]*)\b/g,t=>{if($[t]){let l=`/${[e,$[t]].join("/").split("/").filter(Boolean).join("/")}`;return n?`[\\color{#009688}{${t}}](${l})`:`[${t}](${l})`}return n?`\\color{#009688}{${t}}`:t});return n&&(l=l.replaceAll(S,e=>`\\color{#009688}{${e}}`)),l}function j(e){if(e)return(function(e){let t;if(!e)return;let n=[];for(;t=/\\color{([^|}]*)\|?([^|}]*)\|?([^|}]*)\|?([^}]*)}{([^}]*)}/g.exec(e);)n.push(t[0]);return e.replaceAll(/[{}[\]()=>]|keyof|typeof|true|false/g,e=>n.some(t=>t.includes(e))?e:`\\color{#569cd6}{${e}}`)})(e)?.replaceAll(/^\s*\|\s*|\s*\|\s*$/gm,"").replaceAll(/\n/g,"<br/>").replaceAll(/\*/g,"\\*").replaceAll(/\|/g,"\\|").replaceAll(/(['"])((?:(?!\1).)*)\1/g,"\\color{#ce9178}{$1$2$1}")}function T(e){if(e)return e.replaceAll(/@example\s*([\s\S]*?)(?=@[a-zA-Z]|\n*$)/g,"").replaceAll(/^@[a-z].+/gm,"").replaceAll(/(\n\s+)+/g,"<br />").replaceAll(/\n/g,"<br />").replaceAll(/(<br \/>)$/g,"")}export function declToMd(n,l,s,S){let v=a(l,n,o.Latest,!0,r.TS),k="";return c(v,function l(r){if(t.isModuleDeclaration(r)&&r.name&&t.isStringLiteral(r.name)){let e=r.name.text,l=r.body;for(;l&&t.isModuleDeclaration(l);)l=l.body;if(l&&t.isModuleBlock(l)){let t=n.slice(l.getStart(v)+1,l.getEnd()-1);k+=`
2
+ `,k+=`
3
+ `,k+=`# Module \`${e}\``,k+=`
4
+ `,k+=`
5
+ `,k+=declToMd(t,e,s,S),k+=`
6
+ `,k+=`
7
+ `}}else u(r)?k+=function(n,l,r){let o=l.name.text;Object.assign($,{[l.name.text]:e(l.getSourceFile().fileName).replace(r,"")});let a=h(l),c=b(a),s=T(a),u=x(a)?.split("|")||[],S=u.includes("comment"),v=u.includes("initial"),k=u.includes("optional"),w=u.includes("version"),B=u.includes("author"),z=s?`\\color{|4||0.45}{${o}}`:o,M=(function(e){let n=[];if(e.heritageClauses){for(let l of e.heritageClauses)if(l.token===t.SyntaxKind.ExtendsKeyword)for(let e of l.types)n.push(e.getText())}return n})(l)?.map(e=>`<n-tag color="#4c81db" css=".tag{gap:0px;}">${A(n,j(e))}</n-tag>`),F=[s,z,c&&`\\color{#52c11b|1||0.9}{${c}}`,M.length>0&&`<sub>\`extends\`</sub> ${M.join(" ")}`].filter(Boolean).join(" "),N=`## ${F}`,C=l.members.filter(e=>p(e)&&e.type?.kind!==i.NeverKeyword||d(e)),K=[];if(C.length>0){for(let e=0,t=C.length;e<t;e++){let t=C[e],l=A(n,j(d(t)?`(${t.parameters.map(e=>`${e.name.getText()}: ${e.type?.getText()||"any"}`).join(", ")}): ${t.type?.getText()||"any"}`:t.type?.getText()||"any"),!0),r=h(t),o=j(t.name.getText());o&&!o.startsWith("\\color")&&(d(t)||function(e){if(e.type){if(!g(e.type))return m(e.type);else for(let t of e.type.types)if(m(t))return!0}return!1}(t)||l?.includes("=>")?o=`\\color{#f9a913}{${o}}`:/^["'](.+)["']$/.test(o)||(o=`\\color{#4c81db}{${o}}`));let i=t.questionToken&&f(t.questionToken);K.push([o,!k&&`\\color{${i?"#f9a913":"#52c11b"}\\|\\|\\|0.9}{${i?"✘":"✔"}}`,!S&&j(T(r)),l,!v&&j(function(e){if(!e)return;let t=e.match(/@default\s+([^\n]+)/);return t?t[1].trim():void 0}(r)),!w&&j(b(r)),!B&&(y(r)||y(a)),function(e){if(!e)return;let t=e.match(/@example\s*([\s\S]*?)(?=@[a-zA-Z]|\n*$)/);return t?t[1].trim():void 0}(r)])}let e=!1,t=!1,l=!1,r=!1;for(let n=0,o=K.length;n<o;n++){let o=K[n];!S&&o[2]&&(r=!0),!v&&o[4]&&(l=!0),!w&&o[5]&&(t=!0),!B&&o[6]&&(e=!0)}N+="\n";let o=["属性",!k&&"必要",r&&"说明","类型",l&&"默认值",t&&"版本",e&&"作者"].filter(Boolean).join("|");N+=`|${o}|`;let i=[":-",!k&&":-",r&&":-",":-",l&&":-",t&&":-",e&&":-"].filter(Boolean);N+="\n";let c=i.join("|");N+=`|${c}|`;for(let n=0,o=K.length;n<o;n++){let o=K[n];N+="\n";let i=[(o[7]?`<n-popover arrow="true" trigger="click" encode-uri="true" content=${JSON.stringify(encodeURIComponent(`<n-md code-classic="false" css=.n-md-body{margin-bottom:0;padding:0.5rem;background-color:transparent;backdrop-filter:none;box-shadow:none;}>${o[7]}</n-md>`))}><n-button size="small" type="primary" circle="true" style="margin-right:8px;">?</n-button></n-popover>`:"")+(o[0]||"-"),!k&&(o[1]||"-"),r&&(o[2]||"-"),o[3]||"-",l&&(o[4]||"-"),t&&(o[5]||"-"),e&&(o[6]||"-")].filter(Boolean).join("|");N+=`|${i}|`}N+="\n"}return N+"\n"}(s,r,S):t.isEnumDeclaration(r)&&(k+=function(n,l){let r=n.name.text,o=h(n),i=T(o),a=b(o);Object.assign($,{[n.name.text]:e(n.getSourceFile().fileName).replace(l,"")});let c=i?`\\color{|4||0.45}{${r}}`:r,s=[i,c,a&&`\\color{#52c11b|1||0.9}{${a}}`].filter(Boolean).join(" "),u=x(o)?.split("|")||[],f=u.includes("comment"),p=u.includes("version"),m=u.includes("author"),g=`## ${s}`;if(n.members.length>0){let e=[];for(let l=0,r=n.members.length;l<r;l++){let r=n.members[l],i=j(r.name.getText()),a=h(r),c=j(function(e){let n=e.initializer;if(n&&t.isStringLiteral(n))return` '${n.text}'`}(r)),s=j(b(a)),u=j(T(a));!i||i.startsWith("\\color")||/^["'](.+)["']$/.test(i)||(i=`\\color{#4c81db}{${i}}`),e.push([i,!f&&u,c,!p&&s,!m&&(y(a)||y(o))])}let l=!1,r=!1,i=!1;for(let t=0,n=e.length;t<n;t++){let n=e[t];!f&&n[1]&&(i=!0),!p&&n[3]&&(r=!0),!m&&n[4]&&(l=!0)}g+="\n";let a=["属性",i&&"说明","值",r&&"版本",l&&"作者"].filter(Boolean).join("|");g+=`|${a}|`;let c=[":-",i&&":-",":-",r&&":-",l&&":-"].filter(Boolean);g+="\n";let s=c.join("|");g+=`|${s}|`;for(let t=0,n=e.length;t<n;t++){let n=e[t];g+="\n";let o=[n[0]||"-",i&&(n[1]||"-"),n[2]||"-",r&&(n[3]||"-"),l&&(n[4]||"-")].filter(Boolean).join("|");g+=`|${o}|`}}return g+"\n\n"}(r,S));c(r,l)}),k}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moneko/core",
3
- "version": "4.7.1",
3
+ "version": "4.7.2",
4
4
  "description": "core",
5
5
  "main": "lib/index.mjs",
6
6
  "type": "module",