Comparing version 2.0.3 to 2.0.4
## 21 April 2020 | ||
### [2.0.4](https://gitlab.com/artdeco/typal/compare/v2.0.3...v2.0.4) | ||
- [feature] Print imports in interface automatically. | ||
- [feature] Pass `super-args` in interfaces. | ||
### [2.0.3](https://gitlab.com/artdeco/typal/compare/v2.0.2...v2.0.3) | ||
@@ -4,0 +9,0 @@ |
@@ -6,8 +6,9 @@ #!/usr/bin/env node | ||
const stream = require('stream'); | ||
const path = require('path'); var aa="function"==typeof Object.defineProperties?Object.defineProperty:function(a,b,c){a!=Array.prototype&&a!=Object.prototype&&(a[b]=c.value)};function ba(a){a=["object"==typeof window&&window,"object"==typeof self&&self,"object"==typeof global&&global,a];for(var b=0;b<a.length;++b){var c=a[b];if(c&&c.Math==Math)return c}throw Error("Cannot find global object");}var ca=ba(this); | ||
function da(a,b){if(b){var c=ca;a=a.split(".");for(var d=0;d<a.length-1;d++){var e=a[d];e in c||(c[e]={});c=c[e]}a=a[a.length-1];d=c[a];b=b(d);b!=d&&null!=b&&aa(c,a,{configurable:!0,writable:!0,value:b})}}da("String.prototype.trimRight",function(a){function b(){return this.replace(/[\s\xa0]+$/,"")}return a||b});const ea=(a,b,c,d=!1,e=!1)=>{const g=c?new RegExp(`^-(${c}|-${b})$`):new RegExp(`^--${b}$`);b=a.findIndex(f=>g.test(f));if(-1==b)return{argv:a};if(d)return{value:!0,index:b,length:1};d=a[b+1];if(!d||"string"==typeof d&&d.startsWith("--"))return{argv:a};e&&(d=parseInt(d,10));return{value:d,index:b,length:2}},fa=a=>{const b=[];for(let c=0;c<a.length;c++){const d=a[c];if(d.startsWith("-"))break;b.push(d)}return b},ia=()=>{var a=ha;return Object.keys(a).reduce((b,c)=>{const d=a[c];if("string"==typeof d)return b[`-${d}`]= | ||
const path = require('path'); | ||
const _module = require('module'); var aa="function"==typeof Object.defineProperties?Object.defineProperty:function(a,b,c){a!=Array.prototype&&a!=Object.prototype&&(a[b]=c.value)};function ba(a){a=["object"==typeof window&&window,"object"==typeof self&&self,"object"==typeof global&&global,a];for(var b=0;b<a.length;++b){var c=a[b];if(c&&c.Math==Math)return c}throw Error("Cannot find global object");}var ca=ba(this); | ||
function da(a,b){if(b){var c=ca;a=a.split(".");for(var d=0;d<a.length-1;d++){var e=a[d];e in c||(c[e]={});c=c[e]}a=a[a.length-1];d=c[a];b=b(d);b!=d&&null!=b&&aa(c,a,{configurable:!0,writable:!0,value:b})}}da("String.prototype.trimRight",function(a){function b(){return this.replace(/[\s\xa0]+$/,"")}return a||b});const ea=(a,b,c,d=!1,e=!1)=>{const f=c?new RegExp(`^-(${c}|-${b})$`):new RegExp(`^--${b}$`);b=a.findIndex(g=>f.test(g));if(-1==b)return{argv:a};if(d)return{value:!0,index:b,length:1};d=a[b+1];if(!d||"string"==typeof d&&d.startsWith("--"))return{argv:a};e&&(d=parseInt(d,10));return{value:d,index:b,length:2}},fa=a=>{const b=[];for(let c=0;c<a.length;c++){const d=a[c];if(d.startsWith("-"))break;b.push(d)}return b},ia=()=>{var a=ha;return Object.keys(a).reduce((b,c)=>{const d=a[c];if("string"==typeof d)return b[`-${d}`]= | ||
"",b;c=d.command?c:`--${c}`;d.short&&(c=`${c}, -${d.short}`);let e=d.description;d.default&&(e=`${e}\nDefault: ${d.default}.`);b[c]=e;return b},{})};const ha={source:{description:"The path to the source file or directory with files to embed types into. Can specify multiple values, e.g., `typal types/index.js types/vendor.js`.",command:!0,multiple:!0},output:{description:"The destination where to save output.\nIf not passed, the file will be overwritten.\nIf `-` is passed, prints to stdout.",short:"o"},closure:{description:"Whether to generate types in _Closure_ mode.",boolean:!0,short:"c"},useNamespace:{description:"Generate JSDoc for functions using namespaces.", | ||
boolean:!0,short:"u"},externs:{description:"Whether to generate externs for _GCC_.",boolean:!0,short:"e"},types:{description:"Comma-separated location of files to read types from.",short:"t"},template:{description:"Scans the input file for `@type` comment in functions' JSDoc, and inserts the annotations from types' files.",short:"T"},migrate:{description:"Extracts types from JavaScript source code and saves them\ninto the types.xml file specified in the output option.",boolean:!0,short:"m"},help:{description:"Print the help information and exit.", | ||
boolean:!0,short:"h"},version:{description:"Show the version's number and exit.",boolean:!0,short:"v"}},p=function(a={},b=process.argv){let [,,...c]=b;const d=fa(c);c=c.slice(d.length);a=Object.entries(a).reduce((f,[h,k])=>{f[h]="string"==typeof k?{short:k}:k;return f},{});const e=[];a=Object.entries(a).reduce((f,[h,k])=>{let l;try{const m=k.short,n=k.boolean,q=k.number,r=k.command,t=k.multiple;if(r&&t&&d.length)l=d;else if(r&&d.length)l=d[0];else{const u=ea(c,h,m,n,q);({value:l}=u);const v=u.index, | ||
w=u.length;void 0!==v&&w&&e.push({index:v,length:w})}}catch(m){return f}return void 0===l?f:{...f,[h]:l}},{});let g=c;e.forEach(({index:f,length:h})=>{Array.from({length:h}).forEach((k,l)=>{g[f+l]=null})});g=g.filter(f=>null!==f);Object.assign(a,{$:g});return a}(ha),x=p.source,ja=p.output,ka=p.closure,la=p.useNamespace,ma=p.externs,na=p.types,oa=p.template,pa=p.migrate,qa=p.version;function ra(a={usage:{}}){const {usage:b={},description:c,line:d,example:e}=a;a=Object.keys(b);const g=Object.values(b),[f]=a.reduce(([l=0,m=0],n)=>{const q=b[n].split("\n").reduce((r,t)=>t.length>r?t.length:r,0);q>m&&(m=q);n.length>l&&(l=n.length);return[l,m]},[]),h=(l,m)=>{m=" ".repeat(m-l.length);return`${l}${m}`};a=a.reduce((l,m,n)=>{n=g[n].split("\n");m=h(m,f);const [q,...r]=n;m=`${m}\t${q}`;const t=h("",f);n=r.map(u=>`${t}\t${u}`);return[...l,m,...n]},[]).map(l=>`\t${l}`);const k=[c,` ${d|| | ||
boolean:!0,short:"h"},version:{description:"Show the version's number and exit.",boolean:!0,short:"v"}},q=function(a={},b=process.argv){let [,,...c]=b;const d=fa(c);c=c.slice(d.length);a=Object.entries(a).reduce((g,[h,k])=>{g[h]="string"==typeof k?{short:k}:k;return g},{});const e=[];a=Object.entries(a).reduce((g,[h,k])=>{let l;try{const m=k.short,n=k.boolean,r=k.number,t=k.command,p=k.multiple;if(t&&p&&d.length)l=d;else if(t&&d.length)l=d[0];else{const u=ea(c,h,m,n,r);({value:l}=u);const v=u.index, | ||
w=u.length;void 0!==v&&w&&e.push({index:v,length:w})}}catch(m){return g}return void 0===l?g:{...g,[h]:l}},{});let f=c;e.forEach(({index:g,length:h})=>{Array.from({length:h}).forEach((k,l)=>{f[g+l]=null})});f=f.filter(g=>null!==g);Object.assign(a,{ba:f});return a}(ha),x=q.source,ja=q.output,ka=q.closure,la=q.useNamespace,ma=q.externs,na=q.types,oa=q.template,pa=q.migrate,qa=q.version;function ra(a={usage:{}}){const {usage:b={},description:c,line:d,example:e}=a;a=Object.keys(b);const f=Object.values(b),[g]=a.reduce(([l=0,m=0],n)=>{const r=b[n].split("\n").reduce((t,p)=>p.length>t?p.length:t,0);r>m&&(m=r);n.length>l&&(l=n.length);return[l,m]},[]),h=(l,m)=>{m=" ".repeat(m-l.length);return`${l}${m}`};a=a.reduce((l,m,n)=>{n=f[n].split("\n");m=h(m,g);const [r,...t]=n;m=`${m}\t${r}`;const p=h("",g);n=t.map(u=>`${p}\t${u}`);return[...l,m,...n]},[]).map(l=>`\t${l}`);const k=[c,` ${d|| | ||
""}`].filter(l=>l?l.trim():l).join("\n\n");a=`${k?`${k}\n`:""} | ||
@@ -19,69 +20,73 @@ ${a.join("\n")} | ||
${e} | ||
`:a};const sa=fs.createReadStream,ta=fs.createWriteStream,z=fs.lstat,ua=fs.readFileSync,va=fs.readdir;var wa=stream;const A=stream.Transform,xa=stream.Writable;const ya=(a,b=0,c=!1)=>{if(0===b&&!c)return a;a=a.split("\n",c?b+1:void 0);return c?a[a.length-1]:a.slice(b).join("\n")},za=(a,b=!1)=>ya(a,2+(b?1:0)),Aa=a=>{({callee:{caller:a}}=a);return a};const B=os.EOL,Ba=os.homedir;const Ca=/\s+at.*(?:\(|\s)(.*)\)?/,Da=/^(?:(?:(?:node|(?:internal\/[\w/]*|.*node_modules\/(?:IGNORED_MODULES)\/.*)?\w+)\.js:\d+:\d+)|native)/,Ea=a=>{const {pretty:b=!1,ignoredModules:c=["pirates","@artdeco/pirates"]}={},d=c.join("|"),e=new RegExp(Da.source.replace("IGNORED_MODULES",d));return a.replace(/\\/g,"/").split("\n").filter(g=>{g=g.match(Ca);if(null===g||!g[1])return!0;g=g[1];return g.includes(".app/Contents/Resources/electron.asar")||g.includes(".app/Contents/Resources/default_app.asar")? | ||
!1:!e.test(g)}).filter(g=>g.trim()).map(g=>{if(b){const f=Ba().replace(/\\/g,"/");return g.replace(/\s+at.*(?:\(|\s)(.*)\)?/,(h,k)=>h.replace(k,k.replace(f,"~")))}return g}).join("\n")};function Fa(a,b,c=!1){return function(d){var e=Aa(arguments),{stack:g}=Error();const f=ya(g,2,!0),h=(g=d instanceof Error)?d.message:d;e=[`Error: ${h}`,...null!==e&&a===e||c?[b]:[f,b]].join("\n");e=Ea(e);return Object.assign(g?d:Error(),{message:h,stack:e})}};function C(a){var {stack:b}=Error();const c=Aa(arguments);b=za(b,a);return Fa(c,b,a)};const Ga=(a,b)=>{b.once("error",c=>{a.emit("error",c)});return b};class Ha extends xa{constructor(a){const {binary:b=!1,rs:c=null,...d}=a||{},{T:e=C(!0),proxyError:g}=a||{},f=(h,k)=>e(k);super(d);this.b=[];this.P=new Promise((h,k)=>{this.on("finish",()=>{let l;b?l=Buffer.concat(this.b):l=this.b.join("");h(l);this.b=[]});this.once("error",l=>{if(-1==l.stack.indexOf("\n"))f`${l}`;else{const m=Ea(l.stack);l.stack=m;g&&f`${l}`}k(l)});c&&Ga(this,c).pipe(this)})}_write(a,b,c){this.b.push(a);c()}get f(){return this.P}}const D=async a=>{({f:a}=new Ha({rs:a,T:C(!0)}));return await a};async function F(a){a=sa(a);return await D(a)};async function G(a,b){if(!a)throw Error("No path is given.");const c=C(!0),d=ta(a);await new Promise((e,g)=>{d.on("error",f=>{f=c(f);g(f)}).on("close",e).end(b)})};async function H(a,b,c){const d=C(!0);if("function"!=typeof a)throw Error("Function must be passed.");if(!a.length)throw Error(`Function${a.name?` ${a.name}`:""} does not accept any arguments.`);return await new Promise((e,g)=>{const f=(k,l)=>k?(k=d(k),g(k)):e(c||l);let h=[f];Array.isArray(b)?h=[...b,f]:1<Array.from(arguments).length&&(h=[b,f]);a(...h)})};const Ia=path.dirname,Ja=path.join,Ka=path.relative,La=path.resolve;async function Ma(a,b){b=b.map(async c=>{const d=Ja(a,c);return{lstat:await H(z,d),path:d,relativePath:c}});return await Promise.all(b)}const Na=a=>a.lstat.isDirectory(),Oa=a=>!a.lstat.isDirectory(); | ||
async function I(a){if(!a)throw Error("Please specify a path to the directory");const {ignore:b=[]}={};if(!(await H(z,a)).isDirectory()){var c=Error("Path is not a directory");c.code="ENOTDIR";throw c;}c=await H(va,a);var d=await Ma(a,c);c=d.filter(Na);d=d.filter(Oa).reduce((e,g)=>{var f=g.lstat.isDirectory()?"Directory":g.lstat.isFile()?"File":g.lstat.isSymbolicLink()?"SymbolicLink":void 0;return{...e,[g.relativePath]:{type:f}}},{});c=await c.reduce(async(e,{path:g,relativePath:f})=>{const h=Ka(a, | ||
g);if(b.includes(h))return e;e=await e;g=await I(g);return{...e,[f]:g}},{});return{content:{...d,...c},type:"Directory"}}const J=(a,b)=>{let c=[],d=[];Object.keys(a).forEach(g=>{const {type:f}=a[g];"File"==f?c.push(Ja(b,g)):"Directory"==f&&d.push(g)});const e=d.reduce((g,f)=>{const {content:h}=a[f];f=J(h,Ja(b,f));return[...g,...f]},[]);return[...c,...e]};function Pa(a){if("object"!=typeof a)return!1;const b=a.re instanceof RegExp;a=-1!=["string","function"].indexOf(typeof a.replacement);return b&&a}const Qa=(a,b)=>{if(!(b instanceof Error))throw b;[,,a]=a.stack.split("\n",3);a=b.stack.indexOf(a);if(-1==a)throw b;a=b.stack.substr(0,a-1);const c=a.lastIndexOf("\n");b.stack=a.substr(0,c);throw b;};function Ra(a,b){function c(){return b.filter(Pa).reduce((d,{re:e,replacement:g})=>{if(this.l)return d;if("string"==typeof g)return d=d.replace(e,g);{let f;return d.replace(e,(h,...k)=>{f=Error();try{return this.l?h:g.call(this,h,...k)}catch(l){Qa(f,l)}})}},`${a}`)}c.b=()=>{c.l=!0};return c.call(c)};const Sa=a=>new RegExp(`%%_RESTREAM_${a.toUpperCase()}_REPLACEMENT_(\\d+)_%%`,"g"),Ta=(a,b)=>`%%_RESTREAM_${a.toUpperCase()}_REPLACEMENT_${b}_%%`,Ua=()=>{var a={U:/^\/\*\*? (documentary|typal) (.+?) externs (.*?)\*\/\r?\n(?:([^\r\n][\s\S]+?\r?\n))?$/mg};return Object.keys(a).reduce((b,c)=>{{var d=a[c];const {getReplacement:e=Ta,getRegex:g=Sa}={},f=g(c);d={name:c,re:d,regExp:f,getReplacement:e,map:{},lastIndex:0}}return{...b,[c]:d}},{})},Va=a=>{var b=[];const c=a.map;return{re:a.regExp,replacement(d, | ||
e){d=c[e];delete c[e];return Ra(d,Array.isArray(b)?b:[b])}}},Wa=a=>{const b=a.map,c=a.getReplacement,d=a.name;return{re:a.re,replacement(e){const g=a.lastIndex;b[g]=e;a.lastIndex+=1;return c(d,g)}}};async function Xa(a,b){return Ya(a,b)} | ||
class Za extends A{constructor(a,b){super(b);this.g=(Array.isArray(a)?a:[a]).filter(Pa);this.l=!1;this.h=b}async replace(a,b){const c=new Za(this.g,this.h);b&&Object.assign(c,b);a=await Xa(c,a);c.l&&(this.l=!0);b&&Object.keys(b).forEach(d=>{b[d]=c[d]});return a}async reduce(a){return await this.g.reduce(async(b,{re:c,replacement:d})=>{b=await b;if(this.l)return b;if("string"==typeof d)b=b.replace(c,d);else{const e=[];let g;const f=b.replace(c,(h,...k)=>{g=Error();try{if(this.l)return e.length?e.push(Promise.resolve(h)): | ||
h;const l=d.call(this,h,...k);l instanceof Promise&&e.push(l);return l}catch(l){Qa(g,l)}});if(e.length)try{const h=await Promise.all(e);b=b.replace(c,()=>h.shift())}catch(h){Qa(g,h)}else b=f}return b},`${a}`)}async _transform(a,b,c){try{const d=await this.reduce(a);this.push(d);c()}catch(d){a=Ea(d.stack),d.stack=a,c(d)}}}async function Ya(a,b){b instanceof wa?b.pipe(a):a.end(b);return await D(a)};function $a(){var a=ab;let b="";const c=new A({transform(d,e,g){let f;for(b+=d.toString();(d=a.exec(b))&&(c.push(d),f=d,a.global););f&&(b=b.slice(f.index+f[0].length));g()},objectMode:!0});return c};const cb=(a,b,c,d)=>{if(!a)throw Error("The name of the property is not given");a=`${d?`${d}.`:""}${a}`;if(null===b)return a;b=bb(c,b);return`${a}=${b}`},bb=(a,b,c='"')=>Number.isInteger(b)||[!0,!1,"null"].includes(b)||["number","boolean"].includes(a)?b:`${c}${b}${c}`,db=({number:a,N:b,boolean:c,type:d})=>b?"string":a?"number":c?"boolean":d?d:"*",eb=a=>`${/[^\w\d._]/.test(a)?`(${a})`:a}|undefined`,K=a=>a?`/**${B}${a}${B} */${B}`:`/**${B} */${B}`,L=a=>` * @suppress {nonStandardJsDocs}${B}${a}`,fb= | ||
(a,b,c)=>{let d=a?`${a}.`:"";a=a?"":"var ";b.includes("-")&&(b=`['${b}']`,d=d.replace(/\.$/,""));b=`${a}${d}${b}`;c&&(b+=` = ${c}`);return b},gb=a=>{const b=a.split(/\r?\n/).map(c=>{let d=Infinity;c.replace(/\S/,(e,g)=>{d=g});return d}).reduce((c,d)=>d<c?d:c,Infinity);return a.replace(new RegExp(`^ {${b}}`,"gm"),"")},M=a=>{a=a.trimRight();a=a.replace(/^\s*\r?\n( *\S)/,"$1");return gb(a)},hb=(a,b,c=null)=>{const {async:d,"void":e,"return":g=e?"void":"",...f}=a;({args:a=""}=a);a||(a=b.map(({J:h,name:k})=> | ||
"this"==k?`${k}: ${h}`:k.startsWith("...")?`...${h}`:h).join(","));b=g.replace(/\r?\n\s*/g," ");d&&b?b=`!Promise<${b}>`:d&&(b="!Promise");c=`function(${"constructor"==f.name?`new: ${c}, `:""}${a})`;b&&(c+=`: ${b}`);return{X:{...f,async:d,return:b},I:c}};function N(a,b){const c=a.example;c&&c.startsWith(".")&&b&&(a.example=La(Ia(b),c))}const O=(...a)=>a.join(B);function ib(a,b,c){const d=[];b.replace(a,(e,...g)=>{e=g.slice(0,g.length-2).reduce((f,h,k)=>{k=c[k];if(!k||void 0===h)return f;f[k]=h;return f},{});d.push(e)});return d};const jb=new RegExp(`${/([^\s>=/]+)/.source}(?:\\s*=\\s*${/(?:"([\s\S]*?)"|'([\s\S]*?)')/.source})?`,"g"),kb=new RegExp(`(?:\\s+((?:${jb.source}\\s*)*))`);const P=(a,b)=>{a=(Array.isArray(a)?a:[a]).join("|");return ib(new RegExp(`<(${a})${kb.source}?(?:${/\s*\/>/.source}|${/>([\s\S]+?)?<\/\1>/.source})`,"g"),b,"t a v v1 v2 c".split(" ")).map(({t:c,a:d="",c:e=""})=>{d=d.replace(/\/$/,"").trim();d=lb(d);return{content:e,props:d,tag:c}})},lb=a=>ib(jb,a,["key","val","def","f"]).reduce((b,{key:c,val:d})=>{if(void 0===d)return b[c]=!0,b;b[c]="true"==d?!0:"false"==d?!1:/^\d+$/.test(d)?parseInt(d,10):d;return b},{});const mb=a=>a.split(/([!?=*(),:.<>{}|\s+])/g).filter(b=>/\S/.test(b)).map(b=>{switch(b){case "function":return"function";case "Function":return"Function";case "!":return"nonNullable";case "?":return"nullable";case "=":return"=";case "*":return"any"}return b}); | ||
function nb(a){let b=0;const c=(e=1)=>a[b+e],d=(e=!0,g=[])=>{var f={};let h=a[b];if(["nullable","nonNullable"].includes(h)){if(!e)throw Error(`${h} not allowed after .`);f.nullable="nullable"===h;b++}h=a[b];if("("==h){b++;f={...d(!0,[]),...f};if(")"!=a[b])throw Error("Expecting closing )");b++;if("|"!=a[b])return f}else if("{"==h){b++;g=f;for(e={};"}"!=a[b];){var k=a[b];b++;e[k]=null;if(":"==a[b]){b++;try{var l=d();e[k]=l}catch(n){throw n.message+=`(when parsing ${k} property)`,n;}}if("}"==a[b]){b++; | ||
break}if(","!=a[b])throw Error(`Expecting , for record after ${k}`);b++}g.record=e;return f}if(["nonNullable","nullable"].includes(h))throw Error("Nullability already defined.");if(/[=),:.<>}|]/.test(h))throw Error(`Unexpected token ${h}.`);"|"!=a[b]&&(f.name=a[b],b++);if("function"==h){l=f;k={return:null,args:[]};if("("!=a[b])throw Error("Expecting opening (");b++;for(var m;")"!=a[b];){if(m&&"this"==a[b])throw Error("this must come first in function arguments");if(m&&"new"==a[b])throw Error("new must come first in function arguments"); | ||
`:a};const sa=fs.createReadStream,ta=fs.createWriteStream,z=fs.lstat,ua=fs.readFileSync,va=fs.readdir;var wa=stream;const A=stream.Transform,xa=stream.Writable;const ya=(a,b=0,c=!1)=>{if(0===b&&!c)return a;a=a.split("\n",c?b+1:void 0);return c?a[a.length-1]:a.slice(b).join("\n")},za=(a,b=!1)=>ya(a,2+(b?1:0)),Aa=a=>{({callee:{caller:a}}=a);return a};const B=os.EOL,Ba=os.homedir;const Ca=/\s+at.*(?:\(|\s)(.*)\)?/,Da=/^(?:(?:(?:node|(?:internal\/[\w/]*|.*node_modules\/(?:IGNORED_MODULES)\/.*)?\w+)\.js:\d+:\d+)|native)/,Ea=a=>{const {pretty:b=!1,ignoredModules:c=["pirates","@artdeco/pirates"]}={},d=c.join("|"),e=new RegExp(Da.source.replace("IGNORED_MODULES",d));return a.replace(/\\/g,"/").split("\n").filter(f=>{f=f.match(Ca);if(null===f||!f[1])return!0;f=f[1];return f.includes(".app/Contents/Resources/electron.asar")||f.includes(".app/Contents/Resources/default_app.asar")? | ||
!1:!e.test(f)}).filter(f=>f.trim()).map(f=>{if(b){const g=Ba().replace(/\\/g,"/");return f.replace(/\s+at.*(?:\(|\s)(.*)\)?/,(h,k)=>h.replace(k,k.replace(g,"~")))}return f}).join("\n")};function Fa(a,b,c=!1){return function(d){var e=Aa(arguments),{stack:f}=Error();const g=ya(f,2,!0),h=(f=d instanceof Error)?d.message:d;e=[`Error: ${h}`,...null!==e&&a===e||c?[b]:[g,b]].join("\n");e=Ea(e);return Object.assign(f?d:Error(),{message:h,stack:e})}};function C(a){var {stack:b}=Error();const c=Aa(arguments);b=za(b,a);return Fa(c,b,a)};const Ga=(a,b)=>{b.once("error",c=>{a.emit("error",c)});return b};class Ha extends xa{constructor(a){const {binary:b=!1,rs:c=null,...d}=a||{},{U:e=C(!0),proxyError:f}=a||{},g=(h,k)=>e(k);super(d);this.b=[];this.R=new Promise((h,k)=>{this.on("finish",()=>{let l;b?l=Buffer.concat(this.b):l=this.b.join("");h(l);this.b=[]});this.once("error",l=>{if(-1==l.stack.indexOf("\n"))g`${l}`;else{const m=Ea(l.stack);l.stack=m;f&&g`${l}`}k(l)});c&&Ga(this,c).pipe(this)})}_write(a,b,c){this.b.push(a);c()}get f(){return this.R}}const D=async a=>{({f:a}=new Ha({rs:a,U:C(!0)}));return await a};async function G(a){a=sa(a);return await D(a)};async function H(a,b){if(!a)throw Error("No path is given.");const c=C(!0),d=ta(a);await new Promise((e,f)=>{d.on("error",g=>{g=c(g);f(g)}).on("close",e).end(b)})};async function I(a,b,c){const d=C(!0);if("function"!=typeof a)throw Error("Function must be passed.");if(!a.length)throw Error(`Function${a.name?` ${a.name}`:""} does not accept any arguments.`);return await new Promise((e,f)=>{const g=(k,l)=>k?(k=d(k),f(k)):e(c||l);let h=[g];Array.isArray(b)?h=[...b,g]:1<Array.from(arguments).length&&(h=[b,g]);a(...h)})};const Ia=path.dirname,Ja=path.join,Ka=path.relative,La=path.resolve;async function Ma(a,b){b=b.map(async c=>{const d=Ja(a,c);return{lstat:await I(z,d),path:d,relativePath:c}});return await Promise.all(b)}const Na=a=>a.lstat.isDirectory(),Oa=a=>!a.lstat.isDirectory(); | ||
async function J(a){if(!a)throw Error("Please specify a path to the directory");const {ignore:b=[]}={};if(!(await I(z,a)).isDirectory()){var c=Error("Path is not a directory");c.code="ENOTDIR";throw c;}c=await I(va,a);var d=await Ma(a,c);c=d.filter(Na);d=d.filter(Oa).reduce((e,f)=>{var g=f.lstat.isDirectory()?"Directory":f.lstat.isFile()?"File":f.lstat.isSymbolicLink()?"SymbolicLink":void 0;return{...e,[f.relativePath]:{type:g}}},{});c=await c.reduce(async(e,{path:f,relativePath:g})=>{const h=Ka(a, | ||
f);if(b.includes(h))return e;e=await e;f=await J(f);return{...e,[g]:f}},{});return{content:{...d,...c},type:"Directory"}}const K=(a,b)=>{let c=[],d=[];Object.keys(a).forEach(f=>{const {type:g}=a[f];"File"==g?c.push(Ja(b,f)):"Directory"==g&&d.push(f)});const e=d.reduce((f,g)=>{const {content:h}=a[g];g=K(h,Ja(b,g));return[...f,...g]},[]);return[...c,...e]};function Pa(a){if("object"!=typeof a)return!1;const b=a.re instanceof RegExp;a=-1!=["string","function"].indexOf(typeof a.replacement);return b&&a}const Qa=(a,b)=>{if(!(b instanceof Error))throw b;[,,a]=a.stack.split("\n",3);a=b.stack.indexOf(a);if(-1==a)throw b;a=b.stack.substr(0,a-1);const c=a.lastIndexOf("\n");b.stack=a.substr(0,c);throw b;};function Ra(a,b){function c(){return b.filter(Pa).reduce((d,{re:e,replacement:f})=>{if(this.l)return d;if("string"==typeof f)return d=d.replace(e,f);{let g;return d.replace(e,(h,...k)=>{g=Error();try{return this.l?h:f.call(this,h,...k)}catch(l){Qa(g,l)}})}},`${a}`)}c.b=()=>{c.l=!0};return c.call(c)};const Sa=a=>new RegExp(`%%_RESTREAM_${a.toUpperCase()}_REPLACEMENT_(\\d+)_%%`,"g"),Ta=(a,b)=>`%%_RESTREAM_${a.toUpperCase()}_REPLACEMENT_${b}_%%`,Ua=()=>{var a={V:/^\/\*\*? (documentary|typal) (.+?) externs (.*?)\*\/\r?\n(?:([^\r\n][\s\S]+?\r?\n))?$/mg};return Object.keys(a).reduce((b,c)=>{{var d=a[c];const {getReplacement:e=Ta,getRegex:f=Sa}={},g=f(c);d={name:c,re:d,regExp:g,getReplacement:e,map:{},lastIndex:0}}return{...b,[c]:d}},{})},Va=a=>{var b=[];const c=a.map;return{re:a.regExp,replacement(d, | ||
e){d=c[e];delete c[e];return Ra(d,Array.isArray(b)?b:[b])}}},Wa=a=>{const b=a.map,c=a.getReplacement,d=a.name;return{re:a.re,replacement(e){const f=a.lastIndex;b[f]=e;a.lastIndex+=1;return c(d,f)}}};async function Xa(a,b){return Ya(a,b)} | ||
class Za extends A{constructor(a,b){super(b);this.g=(Array.isArray(a)?a:[a]).filter(Pa);this.l=!1;this.h=b}async replace(a,b){const c=new Za(this.g,this.h);b&&Object.assign(c,b);a=await Xa(c,a);c.l&&(this.l=!0);b&&Object.keys(b).forEach(d=>{b[d]=c[d]});return a}async reduce(a){return await this.g.reduce(async(b,{re:c,replacement:d})=>{b=await b;if(this.l)return b;if("string"==typeof d)b=b.replace(c,d);else{const e=[];let f;const g=b.replace(c,(h,...k)=>{f=Error();try{if(this.l)return e.length?e.push(Promise.resolve(h)): | ||
h;const l=d.call(this,h,...k);l instanceof Promise&&e.push(l);return l}catch(l){Qa(f,l)}});if(e.length)try{const h=await Promise.all(e);b=b.replace(c,()=>h.shift())}catch(h){Qa(f,h)}else b=g}return b},`${a}`)}async _transform(a,b,c){try{const d=await this.reduce(a);this.push(d);c()}catch(d){a=Ea(d.stack),d.stack=a,c(d)}}}async function Ya(a,b){b instanceof wa?b.pipe(a):a.end(b);return await D(a)};function $a(){var a=ab;let b="";const c=new A({transform(d,e,f){let g;for(b+=d.toString();(d=a.exec(b))&&(c.push(d),g=d,a.global););g&&(b=b.slice(g.index+g[0].length));f()},objectMode:!0});return c};const cb=(a,b,c,d)=>{if(!a)throw Error("The name of the property is not given");a=`${d?`${d}.`:""}${a}`;if(null===b)return a;b=bb(c,b);return`${a}=${b}`},bb=(a,b,c='"')=>Number.isInteger(b)||[!0,!1,"null"].includes(b)||["number","boolean"].includes(a)?b:`${c}${b}${c}`,db=({number:a,O:b,boolean:c,type:d})=>b?"string":a?"number":c?"boolean":d?d:"*",L=a=>a?`/**${B}${a}${B} */${B}`:`/**${B} */${B}`,M=a=>` * @suppress {nonStandardJsDocs}${B}${a}`,eb=(a,b,c)=>{let d=a?`${a}.`:"";a=a?"":"var ";b.includes("-")&& | ||
(b=`['${b}']`,d=d.replace(/\.$/,""));b=`${a}${d}${b}`;c&&(b+=` = ${c}`);return b},fb=a=>{const b=a.split(/\r?\n/).map(c=>{let d=Infinity;c.replace(/\S/,(e,f)=>{d=f});return d}).reduce((c,d)=>d<c?d:c,Infinity);return a.replace(new RegExp(`^ {${b}}`,"gm"),"")},N=a=>{a=a.trimRight();a=a.replace(/^\s*\r?\n( *\S)/,"$1");return fb(a)},gb=(a,b,c=null)=>{const {async:d,"void":e,"return":f=e?"void":"",...g}=a;({args:a=""}=a);a||(a=b.map(({K:h,name:k})=>"this"==k?`${k}: ${h}`:k.startsWith("...")?`...${h}`: | ||
h).join(","));b=f.replace(/\r?\n\s*/g," ");d&&b?b=`!Promise<${b}>`:d&&(b="!Promise");c=`function(${"constructor"==g.name?`new: ${c}, `:""}${a})`;b&&(c+=`: ${b}`);return{Y:{...g,async:d,return:b},J:c}};function O(a,b){const c=a.example;c&&c.startsWith(".")&&b&&(a.example=La(Ia(b),c))}const P=(...a)=>a.join(B);function hb(a,b,c){const d=[];b.replace(a,(e,...f)=>{e=f.slice(0,f.length-2).reduce((g,h,k)=>{k=c[k];if(!k||void 0===h)return g;g[k]=h;return g},{});d.push(e)});return d};const ib=new RegExp(`${/([^\s>=/]+)/.source}(?:\\s*=\\s*${/(?:"([\s\S]*?)"|'([\s\S]*?)')/.source})?`,"g"),jb=new RegExp(`(?:\\s+((?:${ib.source}\\s*)*))`);const Q=(a,b)=>{a=(Array.isArray(a)?a:[a]).join("|");return hb(new RegExp(`<(${a})${jb.source}?(?:${/\s*\/>/.source}|${/>([\s\S]+?)?<\/\1>/.source})`,"g"),b,"t a v v1 v2 c".split(" ")).map(({t:c,a:d="",c:e=""})=>{d=d.replace(/\/$/,"").trim();d=kb(d);return{content:e,props:d,tag:c}})},kb=a=>hb(ib,a,["key","val","def","f"]).reduce((b,{key:c,val:d})=>{if(void 0===d)return b[c]=!0,b;b[c]="true"==d?!0:"false"==d?!1:/^\d+$/.test(d)?parseInt(d,10):d;return b},{});const lb=a=>a.split(/([!?=*(),:.<>{}|\s+])/g).filter(b=>/\S/.test(b)).map(b=>{switch(b){case "function":return"function";case "Function":return"Function";case "!":return"nonNullable";case "?":return"nullable";case "=":return"=";case "*":return"any"}return b}); | ||
function mb(a){let b=0;const c=(e=1)=>a[b+e],d=(e=!0,f=[])=>{var g={};let h=a[b];if(["nullable","nonNullable"].includes(h)){if(!e)throw Error(`${h} not allowed after .`);g.nullable="nullable"===h;b++}h=a[b];if("("==h){b++;g={...d(!0,[]),...g};if(")"!=a[b])throw Error("Expecting closing )");b++;if("|"!=a[b])return g}else if("{"==h){b++;f=g;for(e={};"}"!=a[b];){var k=a[b];b++;e[k]=null;if(":"==a[b]){b++;try{var l=d();e[k]=l}catch(n){throw n.message+=`(when parsing ${k} property)`,n;}}if("}"==a[b]){b++; | ||
break}if(","!=a[b])throw Error(`Expecting , for record after ${k}`);b++}f.record=e;return g}if(["nonNullable","nullable"].includes(h))throw Error("Nullability already defined.");if(/[=),:.<>}|]/.test(h))throw Error(`Unexpected token ${h}.`);"|"!=a[b]&&(g.name=a[b],b++);if("function"==h){l=g;k={return:null,args:[]};if("("!=a[b])throw Error("Expecting opening (");b++;for(var m;")"!=a[b];){if(m&&"this"==a[b])throw Error("this must come first in function arguments");if(m&&"new"==a[b])throw Error("new must come first in function arguments"); | ||
if("this"==a[b]){b++;if(":"!=a[b])throw Error("Expecting :");b++;k.this=d()}else if("new"==a[b]){b++;if(":"!=a[b])throw Error("Expecting :");b++;k.new=d()}else if("."==a[b]&&"."==c()&&"."==c(2)){b++;b++;b++;m=d();if(")"!=a[b])throw Error("Variable args must come last");k.variableArgs=m}else m=d(),k.args.push(m),"="==a[b]&&(m.optional=!0,b++);m=!0;if(")"==a[b])break;if(","==a[b])b++;else throw Error("Expecting , between arguments");}b++;":"==a[b]&&(b++,m=d(),void 0==m.name&&m.nullable&&(m.name=""), | ||
k.return=m);l.function=k}else if("<"==a[b]||(k="."==a[b]&&"<"==c())){b++;k&&b++;l=f;for(k=[];">"!=a[b];){m=d();k.push(m);if(">"==a[b])break;if(","==a[b])b++;else throw Error("Expecting , between applications");}b++;l.application=k}for(;"."==a[b];){f.name+=".";b++;({name:l}=d(!1));if(!l)throw Error("Expected to see the name after .");f.name+=l}if("|"!=a[b]||!e)return f;for(g.push(f);"|"==a[b];)b++,f=d(!0,g),f.union!==g&&g.push(f);return{union:g}};return d()};function ob(a){a=mb(a);return nb(a)};function pb(a,b,{name:c,string:d,"boolean":e,opt:g,number:f,type:h},k){if(!c)throw Error("Argument does not have a name.");a.name=c;b&&(a.description=M(b));b=db({number:f,N:d,boolean:e,type:h});k&&(b=b.replace(new RegExp(`([!?])?${k}\\.`,"g"),"$1"));b.endsWith("=")&&(b=b.replace(/=$/,""),g=!0);a.type=b;g&&(a.optional=!0)}class qb{constructor(){this.name=null;this.type="";this.optional=!1;this.description=""}get J(){return this.optional?`${this.type}=`:this.type}} | ||
const rb=(a,b)=>{let c=a.lastIndexOf("</arg>"),d=a;var e=[];-1!=c&&(c+=6,e=a.slice(0,c),d=a.slice(c),e=P("arg",e),e=e.map(({content:g,props:f})=>{const h=new qb;pb(h,g,f,b);return h}));return{K:d,G:e}};function S(a){if(""==a.name&&a.nullable)return"?";var b="";a.nullable?b="?":!1===a.nullable&&(b="!");if(a.function){b+=a.name+"(";const d=[];if(a.function.this){var c="this: "+S(a.function.this);d.push(c)}a.function.new&&(c="new: "+S(a.function.new),d.push(c));a.function.args.forEach(e=>{let g=S(e);e.optional&&(g+="=");d.push(g)});a.function.variableArgs&&(c="..."+S(a.function.variableArgs),d.push(c));c=d.join(", ");b+=c+")";a.function.return&&(b+=": "+S(a.function.return))}else if(a.record)b+="{ ", | ||
c=Object.keys(a.record).map(d=>{var e=a.record[d];if(!e)return d;e=S(e);return`${d}: ${e}`}),b+=c.join(", "),b+=" }";else if(a.application){if("Promise"==a.name&&!a.application.some(d=>"void"!=d.name))return b+"Promise";b+=a.name+"<";c=a.application.map(d=>S(d));b+=c.join(", ");b+=">"}else a.union?(b+="(",c=a.union.map(d=>S(d)),b+=c.join("|"),b+=")"):b+="any"==a.name?"*":a.name;return b};const T=(a,b=!1)=>a.split("\n").map((c,d)=>{if(b&&!d)return c;d=" *";c.length&&"\r"!=c&&(d+=" ");return d+c}).join("\n"),sb=a=>{const b=a.replace(/^\s*\r?\n/gm,"").split(B).reduce((c,d)=>{[{length:d=0}={}]=/^\s*/.exec(d)||[];return d<c?d:c},Infinity);return a.replace(new RegExp(`^ {${b}}`,"gm"),"")}; | ||
function tb(a,b=""){const c=b.split(/\s*,\s*/);return a.split(/\s*,\s*/).map(d=>{let e=d=ua(d,"utf8");if(d=/\/\* start example \*\/\r?\n([\s\S]+?)\r?\n\s*\/\* end example \*\//.exec(d))[,d]=d,e=sb(d);c.forEach(g=>{const [f,h]=g.split(/\s*=>\s*/);e=e.replace(`'${f}'`,`'${h}'`);e=e.replace(`"${f}"`,`"${h}"`)});return e=e.replace(/@/g,"\uff20")})} | ||
function ub(a,{R:b=!0,V:c=!0}={}){const d=[];b&&d.push(" * @example");a.forEach(e=>{let g=[],f=[],h="",k;e=e.split(B).reduce((l,m)=>{m.startsWith("///")?(k="comment",g.push(m)):(k="block",f.push(m));h||(h=k);k!=h&&("block"==k?(l.push(g.join(B)),g=[]):(l.push(f.join(B)),f=[]),h=k);return l},[]);g.length?e.push(g.join(B)):f.length&&e.push(f.join(B));e=e.reduce((l,m)=>{m.startsWith("///")?(m=m.replace(/^\/\/\/\s+/gm,""),l.push(...m.split(/\r?\n/))):(l.push("```js"),l.push(...m.split(/\r?\n/)),l.push("```")); | ||
return l},[]);c&&(e=e.map(l=>T(l)));d.push(...e)});return d}function vb(a,b,c=new RegExp(`([!?])?${b}\\.`,"g")){b&&(a.f&&(a.f=a.f.replace(c,"$1")),a.type=a.type.replace(c,"$1"))}function wb(a,b=!1){return b?a.closureType:a.isParsedFunction?a.toTypeScriptFunction(S):a.type} | ||
function xb(a,b=null,c=!1,d=!1){if(!a.name)throw Error("Property does not have a name. Has it been constructed using fromXML?");b=cb(a.name,a.optional?a.default:null,a.type,b);b=a.optional?`[${b}]`:b;var e=a.o;e=e?` ${e}`:"";c=`{${wb(a,c)}} ${b}${e}`;d&&(a=ub(a.examples,{R:!1,V:!1}).join(B).replace(/\*/g,"\uff0a"))&&(c+=`${B}${a}`);return c}function yb(a,b=!1){a=xb(a,null,b,!0);return` * @prop ${T(a,!0)}`} | ||
function zb(a,b){const c=[],{function:{args:d,return:e,variableArgs:g,this:f}}=a.parsed;d.map(h=>S(h)).forEach((h,k)=>{const {optional:l}=d[k],{name:m=`arg${k}`,description:n}=a.args[k]||{};c.push(` * @param {${h}${l?"=":""}} ${l?`[${m}]`:m}${n?` ${n}`:""}`)});if(g){const {O:h,Z:k}=Ab(a.args||[]),l=[h,k].filter(Boolean).join(" ");c.push(` * @param {...${S(g)}} ${l}`)}f&&c.push(` * @this {${S(f)}}`);if(e&&"void"!=e.name){if(b&&a.v)return c;b=S(e);c.push(` * @return {${b}}`)}return c} | ||
function Bb(a){if(a.isParsedFunction){const {function:{args:b,variableArgs:c}}=a.parsed,d=b.map((e,g)=>{({name:e=`arg${g}`}=a.m[g]||{});return e});if(c){const {O:e}=Ab(a.args||[]);d.push(`...${e}`)}return` = function(${d.join(", ")}) {}`}return a.type.startsWith("function(")?" = function() {}":""}function Cb(a,b){const c=Object.assign(Object.create(Object.getPrototypeOf(a)),a);c.description=`An alias for \`${a.name}\`.`;c.name=b;return c} | ||
class Db{constructor(a=null){this.h=this.description=this.name=null;this.closureType="";this.default=this.f=null;this.optional=!1;this.aliases=[];this.u=!1;this.parsed=null;this.args=a;this.g=!1;this.examples=[];this.v=!1}toTypeScriptFunction(a){if(!this.parsed)throw Error("The property was not parsed.");let {function:{new:b,args:c,return:d,this:e,variableArgs:g}}=this.parsed;b&&(d=b);var f=c.map(k=>a(k)).map((k,l)=>{const {optional:m}=c[l];let {name:n=`arg${l}`,optional:q=m}=this.m[l]||{};return`${`${n}${q? | ||
"?":""}`}: ${k}`});if(e){var h=a(e);f.unshift(`this: ${h}`)}if(g){h=a(g);let k="...args";try{k=`${this.args[this.args.length-1].name}`}catch(l){}f.push(`${k}: ${h}[]`)}f=f.join(", ");h=d?a(d):"?";f=`(${f}) => ${h}`;b&&(f="new "+f);return f}get static(){return this.g}get hasDefault(){return null!==this.default}b(a,{name:b,string:c,"boolean":d,opt:e,number:g,type:f,"default":h,closure:k,alias:l,aliases:m,example:n,"example-override":q="",noParams:r,"static":t,initial:u,"template-no-return":v}){if(!b)throw Error("Property does not have a name."); | ||
this.name=b;a&&(this.description=M(a));a=db({number:g,N:c,boolean:d,type:f});r&&(this.u=r);k&&(this.f=k);this.type=a;void 0!==h?this.default=h:void 0!==u&&(this.default=u);if(e||void 0!==h)this.optional=!0;l&&(this.aliases=[l]);m&&(this.aliases=m.split(/\s*,\s*/));t&&(this.g=!0);n&&(this.examples=tb(n,q));v&&(this.v=!0)}get type(){return this.h||"*"}set type(a){this.h=a||null;this.closureType=this.f||this.h||"";if(!this.u)try{this.parsed=ob(this.closureType),this.isParsedFunction&&!this.args&&(this.args= | ||
[])}catch(b){this.parsed=null}}get o(){let a=this.description||"";return`${a}${this.hasDefault?`${/``` */.test(this.description)?B:a?" ":""}Default \`${this.default}\`.`:""}`}get m(){var a=this.args;this.args&&this.args[0]&&"this"==this.args[0].name&&([,...a]=this.args);return a}get isParsedFunction(){return!!this.parsed&&"function"==this.parsed.name}j(a="",b=!1){let c=[];var d=this.o;d&&(d=T(d),c.push(...d.split(B)));!this.optional&&this.isParsedFunction?(d=zb(this,b),c.push(...d)):c.push(` * @type {${this.optional? | ||
eb(this.closureType):this.closureType}}`);b&&this.examples.length&&(b=ub(this.examples),c.push(...b));a&&(c=c.map(e=>`${a}${e}`));return c.join(B)}D(a,b="",c=!1){a=xb(this,a,c);const [d,...e]=a.split(B);return[`@param ${d}`,...e].map(g=>`${b} * ${g}`).join(B)}}const Ab=a=>{let b="args";const {name:c="",description:d}=a[a.length-1]||{};c.startsWith("...")&&(b=c.replace("...",""));return{O:b,Z:d}};class U extends Db{constructor(...a){super(...a);this.isConstructor=this.async=!1;this.return=""}b(a,b){super.b(a,b);"constructor"==b.name&&(this.isConstructor=!0);this.async=b.async;this.return=b.return}};function Eb(a,b,c,d){var e=P("prop",a).map(({content:k,props:l})=>{const m=new Db;N(l,c);m.b(k,l);return m});a=P(["function","fn","static"],a).map(({content:k,props:l,tag:m})=>{m="static"==m;const {K:n,G:q}=rb(k,b);k=new U(q);const {X:r,I:t}=hb(l,q,d);r.type=t;N(r,c);k.b(n,r);m&&(k.g=!0);return k});e=[...e,...a];const {H:g,M:f,n:h}=e.reduce((k,l)=>{l.isConstructor?k.H.push(l):l.static?k.M.push(l):k.n.push(l);return k},{H:[],M:[],n:[]});return{constructor:g[0]||null,properties:[...g,...f,...h]}};const Fb=(a,b,c={})=>{let d;if("object"==typeof b)d=b;else try{(d=ob(b))||console.log("Could not parse %s",b)}catch(e){console.log("Could not parse %s",b),console.error(e.message)}return d?V(d,a,c):b},V=(a,b,c={})=>{if(""==a.name&&a.nullable)return"?";var {escapePipe:d=!0}=c;let e="";var g="";a.nullable?g="?":!1===a.nullable&&(g="!");if(a.function){e=e+g+(a.name+"(");const f=[];a.function.this&&(d="this: "+V(a.function.this,b,c),f.push(d));a.function.new&&(d="new: "+V(a.function.new,b,c),f.push(d)); | ||
a.function.args.forEach(h=>{let k=V(h,b,c);h.optional&&(k+="=");f.push(k)});a.function.variableArgs&&(d="..."+V(a.function.variableArgs,b,c),f.push(d));d=f.join(", ");e+=d+")";a.function.return&&(e+=": "+V(a.function.return,b,c))}else a.record?(e+="{ ",d=Object.keys(a.record).map(f=>{var h=a.record[f];if(!h)return f;h=V(h,b,c);return`${f}: ${h}`}),e+=d.join(", "),e+=" }"):a.application?(e+=Gb(a.name,b,g,c)+"<",d=a.application.map(f=>V(f,b,c)),e+=d.join(", "),e+=">"):a.union?(e=e+g+"(",g=a.union.map(f=> | ||
V(f,b,c)),e+=g.join(d?" \\| ":" | "),e+=")"):e+=Gb("any"==a.name?"*":a.name,b,g,c);return e},Gb=(a,b,c="",d={})=>{const {flatten:e=!1,nameProcess:g,link:f=({link:l})=>`#${l}`}=d;d=Hb(b,a);c=`${c}${a}`;if(!d)return c;let {link:h,type:{description:k}}=d;e&&((b=b.find(({fullName:l})=>l==a))&&b.link&&(h=b.link),!k&&b.description&&(k=b.description),"function"==typeof e&&e(a));d.link==h&&(h=f(d));b=g?g(c):c;return k?`<a href="${h}" title="${k.replace(/"/g,""")}">${b}</a>`:`[${b}](${h})`},Hb=(a,b)=> | ||
{a=a.filter(({fullName:d})=>d==b);if(a.length){var c=a.find(({import:d})=>d||!1);a=a.find(({import:d})=>!d)||c;return{link:`${"type"}-${a.fullName.replace(/<\/?code>/g,"").replace(/<\/?strong>/g,"").replace(/<br\/>/g,"").replace(/ /g,"").replace(/[^\w-\d ]/g,"").toLowerCase().replace(/[, ]/g,"-")}`,type:a}}};function Ib(a,b=[],c=[],d={}){const {narrow:e=!1,preprocessDesc:g}=d;if(!b.length)return"";const f=a.isConstructor||a.isInterface,h=b.some(({hasDefault:n})=>n),k={escapePipe:!e,...d};let l;const m=n=>Fb(c,n,{...k,nameProcess:d.nameProcess?q=>d.nameProcess(q,l):void 0});a=b.map((n,q)=>{l=0<(q+1)%2;q=n.args&&n.isParsedFunction?n.toTypeScriptFunction(m):m(n.parsed||n.type);const r=f||n.optional?n.name:`${n.name}*`,t=n.hasDefault?`\`${n.default}\``:"-",u=g?g(n.description):n.description;return{prop:n, | ||
typeName:q,name:r,de:Jb(u,!e),d:t,aa:l}});if(e)return{props:a,anyHaveDefault:h,constr:f};a=a.map(({name:n,typeName:q,de:r,d:t,prop:u})=>[u.optional?n:`__${n}__`,`<em>${q}</em>`,r,...h?[t]:[]]);b=["Name",...e?["Type & Description"]:["Type","Description"],...h?[f?"Initial":"Default"]:[]];return["","","```table",JSON.stringify([b,...a],null,2).replace(/\n/g,B),"```"].join(B)}const Jb=(a="",b=!0)=>{null===a&&(a="");b&&(a=a.replace(/\|/g,"\\|"));return a.replace(/</g,"<").replace(/>/g,">")};const Kb=(a,b,c={})=>{function d(e){e.replace(/^!?/,"");return`\`${e}\``}return a.split(/,\s*/).map(e=>Fb(b,e,{flatten:!0,...c,nameProcess:c.nameProcess?g=>{g=c.nameProcess(g);return/[_*~>]/.test(g)?`<code>${g}</code>`:d(g)}:d})).join(", ")};function Lb(a){var b=a.h();b=K(b.join(B));b+=fb(a.namespace,a.name,Mb(a));const c=a.properties.reduce((d,e)=>{d.push(e);const g=e.aliases.map(f=>Cb(e,f));d.push(...g);return d},[]).filter(d=>d instanceof U&&d.isConstructor?!1:!0).map(d=>{let e=d.j();e=K(e);e+=fb(`${a.fullName}${d.static?"":".prototype"}`,d.name);return e+=Bb(d)});return[b,...c].join(B)}function Nb(a,b=!1){const c=`${a.extends?"$":""}${a.name}`;return b?`${a.ns}${c}`:c} | ||
function Ob(a,b=!1,c=!1,d=b){d=` * @typedef {${(b?a.closureType:a.type)||a.u()}}${` ${Nb(a,d)}${a.m}`}`;a=(a.properties?a.properties.reduce((e,g)=>{if(g.g)return e;e.push(g);const f=g.aliases.map(h=>Cb(g,h));e.push(...f);return e},[]):[]).filter(e=>e instanceof U?!e.isConstructor:!0).map(e=>yb(e,b));a=[d,...a].join(B);b&&!c&&(a=L(a));return a=K(a)}function Mb(a){return a.args?`function(${a.args.filter(({name:b})=>"this"!=b).map(({name:b})=>b).join(", ")}) {}`:null} | ||
class W{constructor(){this.name="";this.description=this.closureType=this.type=null;this.noExpand=this.spread=this.noToc=!1;this.link=null;this.properties=[];this.namespace=null;this.isRecord=this.isInterface=this.isConstructor=!1;this.args=this.extends=null;this.examples=[];this.file=null}get import(){return!1}b(a,{name:b,type:c,desc:d,noToc:e,spread:g,noExpand:f,link:h,closure:k,constructor:l,"extends":m,"interface":n,record:q,example:r,"example-override":t},u,v=null){if(!b)throw Error("Type does not have a name."); | ||
this.name=b;c&&(this.type=c);k?this.closureType=k:this.closureType=this.type;d&&(this.description=M(d));this.noToc=!!e;this.spread=!!g;this.noExpand=!!f;h&&(this.link=h);!0===l&&(this.isConstructor=l);!0===n&&(this.isInterface=n);!0===q&&(this.isRecord=q);m&&(this.extends=m);u&&(this.namespace=u);if(a){const {properties:w,constructor:y}=Eb(a,v,this.file,this.fullName);y&&(this.args=y.args);this.properties=w}r&&(a={example:r},N(a,this.file),this.examples=tb(a.example,t))}get L(){return this.isConstructor|| | ||
this.isInterface||this.isRecord}j(){let a;this.closureType?a=` * @typedef {${this.closureType}}`:this.L||(a=` * @typedef {${Pb(this.properties,!0)}}`);return a?(this.description&&(a=` * ${this.description}${B}${a}`),a=K(a),a+=fb(this.namespace,this.name)):Lb(this)}u(){return"Object"}o(a,b=new RegExp(`([!?])?${a}\\.`,"g")){this.type&&(this.type=this.type.replace(b,"$1"));this.extends&&(this.extends=this.extends.replace(b,"$1"));return b}get m(){return`${this.tag?` \`\uff20${this.tag}\``:""}${this.description? | ||
` ${this.description}`:""}`}g(a=!1,b=!1,c=a){const d=!!this.extends,e=Ob(this,a,b,c),g=[];if(this.namespace&&a){var f=` * @typedef {${this.fullName}} ${this.name}${this.m}`;a&&!b&&(f=L(f));f=K(f);g.push(f)}else this.namespace&&c&&(f=` * @typedef {${this.fullName}} ${this.name}${this.m}`,f=K(f),g.push(f));d&&(c=` * @typedef {${Nb(this,c)} & ${this.extends.split(/,\s*/).join(" & ")}} ${c?this.fullName:this.name}${this.m}`,a&&!b&&(c=L(c)),c=K(c),g.push(c));g.push(e);return g.join("")}get Y(){const a= | ||
this.tag;if(!a)throw Error("Unknown prototype type (not constructor or interface).");return a}get tag(){return this.isConstructor?"constructor":this.isInterface?"interface":this.isRecord?"record":""}h(a="",b=!0,c=!1){let d=[];this.description&&d.push(` * ${this.description}`);const e=this.properties[0];e instanceof U&&e.isConstructor&&e.description&&d.push(T(e.description));this.extends&&this.extends.split(/,\s*/).forEach(g=>{d.push(` * @extends {${g}}`)});this.args&&this.args.forEach(g=>{let {name:f, | ||
description:h,optional:k,type:l}=g;g=h?` ${h}`:"";if(f.startsWith("..."))f=f.slice(3),l=`...${l}`;else if("this"==f){d.push(` * @this {${l}}${g}`);return}d.push(` * @param {${l}${k?"=":""}} ${k?`[${f}]`:f}${g}`)});b&&d.push(` * @${this.Y}`);c&&this.examples.length&&(b=ub(this.examples),d.push(...b));a&&(d=d.map(g=>`${a}${g}`));return d}get ns(){return this.namespace?`${this.namespace}.`:""}get fullName(){return`${this.ns}${this.name}`}D(a,b,c,d,e=!1,g=!1){var f="";!0===d?f="?":!1===d&&(f="!");d=this.description? | ||
` ${this.description}`:"";const h=this.spread?Pb(this.properties):e||g?this.fullName:this.name;b=`${c||""} * @param {${f}${h}} ${b?`[${a}]`:a}${d}`;f=this.properties&&!this.noExpand?this.properties.map(k=>k.D(a,c,e,g)):[];return[b,...f].join(B)}toMarkdown(a=[],b={}){const {flatten:c,details:d=[]}=b,e=d.includes(this.name);var g=this.type?`\`${this.type}\``:"",f=g;this.link?f=`[${g}](${this.link})`:!this.import&&this.type&&(f=Fb(a,this.type,b),g=f!=this.type,f=Qb(f,g));g=Qb(this.fullName);g=this.import? | ||
`[${g}](l-type)`:this.noToc?`[${g}](l-type)`:`[${g}](t-type)`;const h=this.description?`: ${this.description}`:"";f=f?`${f} `:"";let k=/_/.test(g);if(this.extends){const l=Kb(this.extends,a,b),m=` extends ${l}`;k=k||/_/.test(l);f=(k?f+"<strong>":f+"__")+(g+m);"function"==typeof c&&c(this.extends)}else f=(k?f+"<strong>":f+"__")+g;f=(k?f+"</strong>":f+"__")+h;a=Ib(this,this.properties,a,b);return{LINE:f,table:a,displayInDetails:e}}} | ||
const Qb=(a,b=!1)=>`${b?"<code>":"`"}${a}${b?"</code>":"`"}`,Pb=(a=[],b=!1)=>{a=a.reduce((c,d)=>{c.push(d);const e=d.aliases.map(g=>({...d,name:g}));c.push(...e);return c},[]);return`{ ${a.map(c=>{const d=b?c.closureType:c.type;let e=c.name,g=d;c.optional&&!b?e=`${c.name}?`:c.optional&&b&&(g=`(${eb(d)})`);return`${e}: ${g}`}).join(", ")} }`};class Rb extends W{constructor(){super();this.from=""}get import(){return!0}b(a,{from:b,name:c,...d},e,g){if(!b)throw Error("From attribute of import is not given.");this.from=b;this.description=M(a);super.b("",{...d,noToc:!0,name:c,type:`import('${b}').${c}`},e!=g?e:null)}g(a=!0){return` * @typedef {import('${this.from}').${this.name}} ${a?this.fullName:this.name}`}};function Sb(a,b){b=b.reduce((c,d)=>({...c,[d.fullName]:d}),{});a.B={...a.B,...b}}class Tb extends Za{constructor(a,b={}){super(a);this.B={};this.on("types",c=>{Sb(this,c)});this.on("namespace",c=>{this.b.includes(c)||this.b.push(c)});this.f=b;this.b=[];this.i=console.log;this.file=null;this.lines=[]}static get Type(){return W}static get Import(){return Rb}get types(){return this.B}};class Ub extends W{constructor(){super();this.f=null;this.async=!1}get L(){return!1}get isMethod(){return!0}b(a,{async:b,"return":c,"void":d,...e},...g){this.description=M(a);super.b("",e,...g);c&&(this.f=c.replace(/\r?\n\s*/g," "));d&&(this.f="void");b&&(this.async=!0)}get return(){return this.f||"void"}h(a=""){const b=super.h(a,!1),c=this.v;c&&b.push(`${a} * @return {${c}}`);return b}get v(){let a="";this.f&&(a=this.return);this.async&&a?a=`Promise<${a}>`:this.async&&(a="Promise");return a}u(){return`(${this.args.map(({name:a, | ||
type:b,optional:c})=>`${a}${c?"?":""}: ${b}`).join(", ")}) => ${this.v}`}o(a){a=super.o(a);this.f&&(this.f=this.f.replace(a,"$1"))}};const Vb=(a,b)=>{const c=new RegExp(`([!?])?${a}\\.`,"g");b.properties.forEach(d=>{vb(d,a,c)});b.o(a)},Wb=(a,b)=>{var {args:c=[]}=a,d=c.map(({J:g})=>g).join(", ");let e=`new: ${a.fullName}`;d.length&&(e=`${e}, `);d=`function(${e}${d})`;c=new U(c);c.isConstructor=!0;c.b("Constructor method.",{type:d,name:"constructor"});c.examples=a.examples;vb(c,b);a.properties.unshift(c)},Yb=(a,b,c=null)=>{a=P("types",a);if(!a.length)throw Error("XML file should contain root types element.");const [{content:d,props:{namespace:e, | ||
ns:g=e}}]=a,f=b==g?void 0:g;a=P(["embed"],d).map(({props:l})=>l);const h=[],k=P("type interface constructor method import record".split(" "),d).reduce((l,{content:m,props:n,tag:q})=>{"record"==q&&(q="type",n.record=!0);const {alias:r,aliases:t,...u}=n;c&&N(u,c);var v=r?[r]:t?t.split(/, */):[];switch(q){case "type":q=new W;c&&(q.file=c);q.b(m,n,f,b);l.push(q);v.forEach(w=>{const y=new W;c&&(y.file=c);y.b(m,{...u,name:w},f,b);l.push(y)});break;case "interface":n=Xb({content:m,props:n,ns:f,C:b,location:c}); | ||
n.forEach(w=>{w.properties.some(({isConstructor:y})=>y)||Wb(w,b);w.isInterface=!0});l.push(...n);break;case "constructor":n=Xb({content:m,props:n,ns:f,C:b,location:c});n.forEach(w=>{w.properties.some(({isConstructor:y})=>y)||Wb(w,b);w.isConstructor=!0});l.push(...n);break;case "method":n=Xb({content:m,props:n,ns:f,C:b,isMethod:!0,location:c});l.push(...n);break;case "import":v=new Rb,v.b(m,n,n.ns||n.from,b),h.push(v)}return l},[]);b&&k.forEach(l=>Vb(b,l));return{namespace:g,types:k,imports:h,embeds:a}}, | ||
Zb=(a,b,c,d,e=!1,g=null)=>{const f=e?new Ub:new W;f.file=g;g=a.search(/<(prop|function|fn|static) /);let h="",k=a;1!=g&&(h=a.slice(0,g),k=a.slice(g));const {G:l,K:m}=rb(h,d);f.b(e?m:k,b,c,d);({I:a}=hb(b,l));e&&(f.closureType=a);f.args||(f.args=l);return f},Xb=({content:a,props:b,ns:c,C:d,isMethod:e=!1,location:g=null})=>{const f=[],{alias:h,aliases:k,...l}=b;b=Zb(a,b,c,d,e,g);f.push(b);(h?[h]:k?k.split(/, */):[]).forEach(m=>{m=Zb(a,{...l,name:m},c,d,e,g);m.description=`${m.description}${m.description? | ||
" ":""}Alias of \`${l.name}\`.`;f.push(m)});return f},$b=()=>{Object.keys(X).forEach(a=>{delete X[a]});Object.keys(Y).forEach(a=>{delete Y[a]})},X={},Y={},bc=async a=>{var b=Y[a];b?b=await b:(b=F(a),Y[a]=b,b=await b);return ac(b,a,[])},cc=(a,b=[])=>{a in X||(X[a]=ua(a,"utf8"));return ac(X[a],a,b)},ac=(a,b,c)=>{let d,e,g,f;try{({namespace:d=null,types:e,imports:g,embeds:f}=Yb(a,void 0,b))}catch(h){throw h.message=`Error while reading ${b}${B}${h.message}`,h;}e=e.filter(({fullName:h})=>c.includes(h)? | ||
!1:!0);g=g.filter(({fullName:h})=>c.includes(h)?!1:!0);return{types:e,imports:g,namespace:d,embeds:f}};const dc=(a,b,c)=>{b=b.map(d=>d.g(!0,c));a=a.map(d=>{d=d.g();return K(c?d:L(d))});return[...b,...a].join("")},ec=(a,b,c,d=!1)=>{a=a.map(e=>e.j());a=O(...a,...[]);return`${!b||d||c.includes(b)?"":["/** @const */",`var ${b} = {}`,""].join(B)}${a}`};function fc(a,b,c){const [d,...e]=c.split(/\s+/);var g=e.includes("closure");const f=e.includes("externs"),h=e.includes("noSuppress"),k=e.includes("skipNsDecl"),l=e.includes("namespace"),m=e.includes("noEmbed")||e.includes("no-embed");let n=e.find(t=>t.startsWith("ignore:"));n=n?n.replace("ignore:","").split(","):[];let {s:q,A:r}=this.f;g&&(q=!0);f&&(r=!0);try{this.i("Detected type marker: %s",c);const {types:t,imports:u,namespace:v,embeds:w}=cc(d,n);this.emit("types",t);this.emit("types",u);g=[]; | ||
!m&&w.length&&(g=w.map(({src:E,path:nc=E,ignore:Q=n.join(","),namespace:oc=l,s:pc=q,A:qc=r,"no-suppress":rc=h})=>{E=[nc];Q&&E.push(`ignore:${Q}`);oc&&E.push("namespace");pc&&E.push("closure");qc&&E.push("ext");rc&&E.push("noSuppress");Q=E.join(" ");return fc.call(this,`${B} /* typal-embed ${Q} */${B}`,"typal-embed",Q)}));let y=g.join(""),R;q?R=dc(u,t,h):r?(R=ec(t,v,this.b,k)+B,v&&this.emit("namespace",v)):l?(v&&this.emit("namespace",v),R=gc(u,t,!0)):R=gc(u,t);return`/* ${b} ${c} */${B}${R}${y}`}catch(t){return this.i("(%s) Could not process typedef-js: %s", | ||
c,t.message),process.env.b&&console.error(t.stack),a}}const hc={re:/^\/\*\*? (documentary|typal) (.+?) \*\/\r?\n(?:((?!\r?\n)[\s\S]+?\r?\n))?$/mg,replacement:fc},gc=(a,b,c=!1)=>{b=b.map(d=>d.g(!1,!1,c));a=a.map(d=>d.g(c)).map(K).join("");b=b.join("");return`${a}${b}`.replace(ic," * @typedef")},ic=/ \*\/\r?\n\/\*\*\r?\n \* @typedef/g;const kc={re:/( *) \* @param {(.+?)} (\[)?([^\s\]]+)\]?(?: .+)?((?:\r?\n(?: +)\* @param {(?:.+?)} \[?\4\]?(?:(?!\r?\n\s*\*(?:\/|\s*@))[\s\S])*)*)/gm,replacement:jc}; | ||
function jc(a,b,c,d,e,g,f){const h=this.f.s,k=this.f.F;let l;g=()=>{if(this.lines&&this.file){var n;{let t=n=0;for(;t<f;)t+=this.lines[n].length,n++;n={line:n,S:b.length+11}}const {line:q,S:r}=n;this.i("%s:%s:%s",this.file,q,r)}};try{l=ob(c)}catch(n){return this.i("Error while parsing the type %s",c),this.i(process.env.DEBUG?n.stack:n.message),g(),a}if(!l)return this.i("Could not parse the type %s",c),g(),a;const m=Object.values(this.types).map(({name:n,fullName:q})=>h||k?q:n);if(!Z(l,m,this.i,c, | ||
g))return a;c=Object.values(this.types).find(({name:n,fullName:q})=>h||k?q==l.name:n==l.name);return!c||c instanceof Tb.Import?a:c.D(e,d,b,l.nullable,h,k)} | ||
const Z=(a,b,c,d,e)=>{if(a){var g=a.name;if(!g||!"string number boolean null undefined symbol any".split(" ").includes(g)){if(g&&!a.application&&!a.function){let h=b.includes(g);h||(h=lc.includes(g));if(h)return!0;c("Type %s%s was not found.",g,d!=g?` in ${d}`:"");e()}var f=[b,c,d,e];a.application?a.application.forEach(h=>{Z(h,...f)}):a.record?Object.keys(a.record).forEach(h=>{Z(a.record[h],...f)}):a.union?a.union.forEach(h=>{Z(h,...f)}):a.function&&(Z(a.function.this,...f),Z(a.function.new,...f), | ||
a.function.args.forEach(h=>{Z(h,...f)}),Z(a.function.variableArgs,...f),Z(a.function.return,...f))}}},lc="String Boolean Object Date Number Symbol Buffer Function RegExp".split(" ");var mc=(a,b=!1)=>{$b();var {U:c}=Ua();const d=Wa(c);c=Va(c);return new Tb(b?[hc]:[hc,d,kc,c],a)};const sc=/( *) \* @(fnType|methodType) {(.+?)}/gm,tc=(a,b,c,d,e,g,f=d)=>{c=`${b?"static ":""}${c?"async ":""}${d}(${e}) {`;return O("/**",a," */",...null===g?[`${c} }`]:[c,` return ${`${b?g:"super"}.${f}`}(${e})`,"}"])}; | ||
function uc(a,b,c){return a.map(d=>{const e=d.name;var g=d.aliases;const f=d.static,h=d.async;let k=d.j("",!0);k=vc(k,c);const l=d.args.map(({name:m})=>m).join(", ");d=tc(k,f,h,e,l,b);g=g.map(m=>tc(k+`${B} * @alias ${e} An alias for **${e}**.`,f,h,m,l,b,e));return[d,...g].join(B)})}function wc(a){return a.map(b=>{const c=b.name,d=b.default,e=b.type;return["/**",b.j("",!0)," */",`this.${c}${d?` = ${bb(e,d,"'")}`:""}`].join(B)})} | ||
const xc=(a,b)=>({re:/(\/\*\*[\s\S]+?)( *\* *@implements {(.+?)})[\s\S]+?((?:export\s+(?:default\s+)?)?class\s+(\S+).*?){\s*}/gm,replacement(c,d,e,g,f,h){this.isInterface=!0;const k=a.find(({fullName:r})=>r==g);if(!k)return console.error("Type %s in %s not found",g,b),c;c=k.properties.filter(r=>r instanceof U&&!r.isConstructor);var l=k.properties.filter(r=>r instanceof Db&&!(r instanceof U));c=uc(c,null,g);l=wc(l).map(r=>r.replace(/(^|(?:\r?\n))/g,"$1 "));const m=k.properties.find(r=>r instanceof | ||
U&&r.isConstructor),n=m.args.map(({name:r})=>r).join(", "),q=0<l.length;h=O("/**",vc(m.j("",!0),g)," */",`constructor(${n}) {${q||k.extends?"":" }"}`,...k.extends?[" super([arguments])"]:[],...l,q||k.extends?"}"+B+"/**":"/**"," * Sets the implementation on the interface.",` * @param {!${h}} Implementation`," */","static __implement(Implementation) {"," Object.defineProperties(",` ${h}.prototype,`," Object.getOwnPropertyDescriptors(Implementation)"," )","}",...c);h=h.replace(/(^|(?:\r?\n))/g, | ||
"$1 ");return O(d.trimRight(),...k.description?[T(k.description)]:[],e," */",`${f}{`,h,"}")}}); | ||
class yc extends Za{constructor(a,b){super([{re:/\/\*\*(?:\s+( *) \*)? @constructor {(.+?)}[\s\S]+?(class\s+.+?\s+extends\s+(.+?)\s*){\s*}/gm,replacement(c,d,e,g,f){d=a.find(({fullName:k})=>k==e);if(!d)return console.error("Type %s in %s not found",e,b),c;c=d.properties.filter(k=>k instanceof U&&!k.isConstructor);f=uc(c,f,e);c=d.properties.find(k=>k instanceof U&&k.isConstructor);const h=c.args.map(({name:k})=>k).join(", ");f=O("/**",vc(c.j("",!0),e)," */",`constructor(${h}) {`,` super(${h})`,"}", | ||
...f);f=f.replace(/(^|(?:\r?\n))/g,"$1 ");return O(...d.description?["/**",T(d.description)," */"]:[],`${g}{`,f,"}")}},xc(a,b),{re:sc,async replacement(c,d,e,g){const f=g.split(".");let h,k;if("methodType"==e)h=g;else if(2==f.length)[h,k]=f;else if(3==f.length)h=`${f[0]}.${f[1]}`,k=f[2];else throw Error("The @fnType should consist of _namespace.Type.propName or Type.propName");g=a.find(({fullName:l})=>l==h);if(!g)return console.error("Type %s in %s not found",h,b),c;if("constructor"==k||"methodType"== | ||
e)return g.h(d,!1,!0).join(B);e=g.properties.find(({name:l})=>l==k);return e?e.parsed?e.j(d,!0):(console.error("Property %s of type %s in %s wasn't parsed, possibly parser bug.",k,h,b),c):(console.error("Property %s of type %s in %s not found",k,h,b),c)}},{re:/ \* @typedef {import\(.+?} .+/gm,replacement(c,d,e){return!this.isInterface||e.substr(0,d).trim().endsWith("@suppress {nonStandardJsDocs}")?c:` * @suppress {nonStandardJsDocs}${B}${c}`}},{re:/ \* @typedef {import\(.+?} .+\r?\n \* @suppress/gm, | ||
replacement(c){if(!this.isInterface)return c;const [d,e]=c.split(/\r?\n/);return[d," */","/**",e].join(B)}}]);this.isInterface=!1}}const vc=(a,b)=>a.replace(`${B} * @return {${b}}`,"").replace(`${B} * @return {!${b}}`,"").replace(`${B} * @return {?${b}}`,"");const zc=async a=>a?(await Promise.all(a.split(",").map(async b=>{var c=[];const d=await H(z,b);d.isFile()?c=[b]:d.isDirectory()&&(c=await I(b),c=J(c.content,b),c=c.filter(e=>e.endsWith(".xml")));return c}))).reduce((b,c)=>[...b,...c],[]):[],Ac=async a=>(await Promise.all(a.map(async b=>({...await bc(b),location:b})))).reduce((b,{imports:c,types:d})=>{b.push(...c);b.push(...d);return b},[]); | ||
async function Bc(){$b();const a=await zc(na),b=await Ac(a);await Promise.all(x.map(async c=>{var d=await H(z,c);let e;d.isFile()?e=[c]:d.isDirectory()&&(d=await I(c),e=J(d.content,c));await Cc(e,b,oa)}))}const Cc=async(a,b=[],c=null)=>{await Promise.all(a.map(async d=>{var e=await F(d);const g=new yc(b,d);g.end(e);e=await D(g);"-"==c?console.log(e):c?await G(c,e):await G(d,e)}))};var Ec=async()=>{const {s:a=!1,F:b=!1,A:c=!1,W:d,types:e}={s:ka,A:ma,W:ja,types:na,F:la},g=await zc(e);await Promise.all(x.map(async f=>{var h=await H(z,f);let k;h.isFile()?k=[f]:h.isDirectory()&&(h=await I(f),k=J(h.content,f));await Dc(k,a,c,d,g,b)}))}; | ||
const Dc=async(a,b=!1,c=!1,d="",e=[],g=!1)=>{const f=[];await Promise.all(e.map(async h=>{h=await F(h);const {types:k,imports:l}=Yb(h);f.push(k,l)}));await Promise.all(a.map(async h=>{var k=await F(h);const l=mc({s:b,A:c,F:g},c);f.forEach(m=>l.emit("types",m));l.file=h;l.i=console.error;l.lines=k.split(B);l.end(k);k=await D(l);"-"==d?console.log(k):d?await G(d,k):await G(h,k)}))};const Fc=a=>{let b;"true"==a?b=!0:"false"==a?b=!1:/^\d+$/.test(a)&&(b=parseInt(a,10));return void 0!==b?b:a},Gc=/^ \* @prop {(.+?)} (\[)?(.+?)(?:=(["'])?(.+?)\4)?(?:])?(?: (.+?))?(?: Default `(.+?)`.)?$/gm,Hc="type opt name quote defaultValue description Default".split(" "),ab=new RegExp(`^ \\* @typedef {(.+?)} (.+?)(?: (.+))?\\r?\\n((?:${/ \* @prop(?:erty)? .+\r?\n/.source})*)`,"gm"),Ic=(a,b,c,d)=>{d=d.length;a=a&&"Object"!=a?` type="${a}"`:"";c=c?` desc="${c}"`:"";return`${" ".repeat(2)}<type name="${b}"${a}${c}${d? | ||
k.return=m);l.function=k}else if("<"==a[b]||(k="."==a[b]&&"<"==c())){b++;k&&b++;l=g;for(k=[];">"!=a[b];){m=d();k.push(m);if(">"==a[b])break;if(","==a[b])b++;else throw Error("Expecting , between applications");}b++;l.application=k}for(;"."==a[b];){g.name+=".";b++;({name:l}=d(!1));if(!l)throw Error("Expected to see the name after .");g.name+=l}if("|"!=a[b]||!e)return g;for(f.push(g);"|"==a[b];)b++,g=d(!0,f),g.union!==f&&f.push(g);return{union:f}};return d()};function nb(a){a=lb(a);return mb(a)};function ob(a,b,{name:c,string:d,"boolean":e,opt:f,number:g,type:h},k){if(!c)throw Error("Argument does not have a name.");a.name=c;b&&(a.description=N(b));b=db({number:g,O:d,boolean:e,type:h});k&&(b=b.replace(new RegExp(`([!?])?${k}\\.`,"g"),"$1"));b.endsWith("=")&&(b=b.replace(/=$/,""),f=!0);a.type=b;f&&(a.optional=!0)}class pb{constructor(){this.name=null;this.type="";this.optional=!1;this.description=""}get K(){return this.optional?`${this.type}=`:this.type}} | ||
const qb=(a,b)=>{let c=a.lastIndexOf("</arg>"),d=a;var e=[];-1!=c&&(c+=6,e=a.slice(0,c),d=a.slice(c),e=Q("arg",e),e=e.map(({content:f,props:g})=>{const h=new pb;ob(h,f,g,b);return h}));return{L:d,H:e}};function R(a,b={}){if(""==a.name&&a.nullable)return"?";var c="";a.nullable?c="?":!1===a.nullable&&(c="!");if(a.function){c+=a.name+"(";const e=[];if(a.function.this){var d="this: "+R(a.function.this,b);e.push(d)}a.function.new&&(d="new: "+R(a.function.new,b),e.push(d));a.function.args.forEach(f=>{let g=R(f,b);f.optional&&(g+="=");e.push(g)});a.function.variableArgs&&(d="..."+R(a.function.variableArgs,b),e.push(d));d=e.join(", ");c+=d+")";a.function.return&&(c+=": "+R(a.function.return,b))}else if(a.record)c+= | ||
"{ ",d=Object.keys(a.record).map(e=>{var f=a.record[e];if(!f)return e;f=R(f,b);return`${e}: ${f}`}),c+=d.join(", "),c+=" }";else if(a.application){if("Promise"==a.name&&!a.application.some(e=>"void"!=e.name))return c+"Promise";c+=a.name+"<";d=a.application.map(e=>R(e,b));c+=d.join(", ");c+=">"}else a.union?(c+="(",d=a.union.map(e=>R(e,b)),c+=d.join("|"),c+=")"):(d="any"==a.name?"*":a.name,c+=b[d]||d);return c};class rb{constructor(){this.description=this.closureType=this.type=null;this.noExpand=this.spread=this.noToc=!1;this.link=null;this.properties=[];this.namespace=null;this.isRecord=this.isInterface=this.isConstructor=!1;this.args=this.superArgs=this.extends=null;this.examples=[]}toMarkdown(){}get import(){return!1}} | ||
class sb{constructor(){this.default=this.description=null;this.isGetter=this.optional=!1;this.args=null;this.aliases=[];this.examples=[];this.parsed=null}toTypeScriptFunction(){}get type(){return"*"}get hasDefault(){return!1}get isParsedFunction(){return!1}get static(){return!1}};const T=(a,b=!1)=>a.split("\n").map((c,d)=>{if(b&&!d)return c;d=" *";c.length&&"\r"!=c&&(d+=" ");return d+c}).join("\n"),tb=a=>{const b=a.replace(/^\s*\r?\n/gm,"").split(B).reduce((c,d)=>{[{length:d=0}={}]=/^\s*/.exec(d)||[];return d<c?d:c},Infinity);return a.replace(new RegExp(`^ {${b}}`,"gm"),"")}; | ||
function ub(a,b=""){const c=b.split(/\s*,\s*/);return a.split(/\s*,\s*/).map(d=>{let e=d=ua(d,"utf8");if(d=/\/\* start example \*\/\r?\n([\s\S]+?)\r?\n\s*\/\* end example \*\//.exec(d))[,d]=d,e=tb(d);c.forEach(f=>{const [g,h]=f.split(/\s*=>\s*/);e=e.replace(`'${g}'`,`'${h}'`);e=e.replace(`"${g}"`,`"${h}"`)});return e=e.replace(/@/g,"\uff20")})} | ||
function vb(a,{S:b=!0,W:c=!0}={}){const d=[];b&&d.push(" * @example");a.forEach(e=>{let f=[],g=[],h="",k;e=e.split(B).reduce((l,m)=>{m.startsWith("///")?(k="comment",f.push(m)):(k="block",g.push(m));h||(h=k);k!=h&&("block"==k?(l.push(f.join(B)),f=[]):(l.push(g.join(B)),g=[]),h=k);return l},[]);f.length?e.push(f.join(B)):g.length&&e.push(g.join(B));e=e.reduce((l,m)=>{m.startsWith("///")?(m=m.replace(/^\/\/\/\s+/gm,""),l.push(...m.split(/\r?\n/))):(l.push("```js"),l.push(...m.split(/\r?\n/)),l.push("```")); | ||
return l},[]);c&&(e=e.map(l=>T(l)));d.push(...e)});return d}function wb(a,b,c=new RegExp(`([!?])?${b}\\.`,"g")){b&&(a.f&&(a.f=a.f.replace(c,"$1")),a.type=a.type.replace(c,"$1"))}function xb(a,b=!1){return b?a.closureType:a.isParsedFunction?a.toTypeScriptFunction(R):a.type} | ||
function yb(a,b=null,c=!1,d=!1){if(!a.name)throw Error("Property does not have a name. Has it been constructed using fromXML?");b=cb(a.name,a.optional?a.default:null,a.type,b);b=a.optional?`[${b}]`:b;var e=a.o;e=e?` ${e}`:"";c=`{${xb(a,c)}} ${b}${e}`;d&&(a=vb(a.examples,{S:!1,W:!1}).join(B).replace(/\*/g,"\uff0a"))&&(c+=`${B}${a}`);return c}function zb(a,b=!1){a=yb(a,null,b,!0);return` * @prop ${T(a,!0)}`} | ||
function Ab(a,b,c){const d=[],{function:{args:e,return:f,variableArgs:g,this:h}}=a.parsed;e.map(k=>R(k,c)).forEach((k,l)=>{const {optional:m}=e[l],{name:n=`arg${l}`,description:r}=a.args[l]||{};d.push(` * @param {${k}${m?"=":""}} ${m?`[${n}]`:n}${r?` ${r}`:""}`)});if(g){const {P:k,aa:l}=Bb(a.args||[]),m=[k,l].filter(Boolean).join(" ");d.push(` * @param {...${R(g,c)}} ${m}`)}h&&d.push(` * @this {${R(h,c)}}`);if(f&&"void"!=f.name){if(b&&a.v)return d;b=R(f,c);d.push(` * @return {${b}}`)}return d} | ||
function Cb(a){if(a.isParsedFunction){const {function:{args:b,variableArgs:c}}=a.parsed,d=b.map((e,f)=>{({name:e=`arg${f}`}=a.m[f]||{});return e});if(c){const {P:e}=Bb(a.args||[]);d.push(`...${e}`)}return` = function(${d.join(", ")}) {}`}return a.type.startsWith("function(")?" = function() {}":""}function Db(a,b){const c=Object.assign(Object.create(Object.getPrototypeOf(a)),a);c.description=`An alias for \`${a.name}\`.`;c.name=b;return c} | ||
class Eb extends sb{constructor(a=null){super();this.h=this.name=null;this.closureType="";this.default=this.f=null;this.u=!1;this.parsed=null;this.args=a;this.v=this.g=!1}toTypeScriptFunction(a){if(!this.parsed)throw Error("The property was not parsed.");let {function:{new:b,args:c,return:d,this:e,variableArgs:f}}=this.parsed;b&&(d=b);var g=c.map(k=>a(k)).map((k,l)=>{const {optional:m}=c[l];let {name:n=`arg${l}`,optional:r=m}=this.m[l]||{};return`${`${n}${r?"?":""}`}: ${k}`});if(e){var h=a(e);g.unshift(`this: ${h}`)}if(f){h= | ||
a(f);let k="...args";try{k=`${this.args[this.args.length-1].name}`}catch(l){}g.push(`${k}: ${h}[]`)}g=g.join(", ");h=d?a(d):"?";g=`(${g}) => ${h}`;b&&(g="new "+g);return g}get static(){return this.g}get hasDefault(){return null!==this.default}b(a,{name:b,string:c,"boolean":d,opt:e,number:f,type:g,"default":h,closure:k,alias:l,aliases:m,example:n,"example-override":r="",noParams:t,"static":p,initial:u,"template-no-return":v}){if(!b)throw Error("Property does not have a name.");this.name=b;a&&(this.description= | ||
N(a));a=db({number:f,O:c,boolean:d,type:g});t&&(this.u=t);k&&(this.f=k);this.type=a;void 0!==h?this.default=h:void 0!==u&&(this.default=u);if(e||void 0!==h)this.optional=!0;l&&(this.aliases=[l]);m&&(this.aliases=m.split(/\s*,\s*/));p&&(this.g=!0);n&&(this.examples=ub(n,r));v&&(this.v=!0)}get type(){return this.h||"*"}set type(a){this.h=a||null;this.closureType=this.f||this.h||"";if(!this.u)try{this.parsed=nb(this.closureType),this.isParsedFunction&&!this.args&&(this.args=[])}catch(b){this.parsed= | ||
null}}get o(){let a=this.description||"";return`${a}${this.hasDefault?`${/``` */.test(this.description)?B:a?" ":""}Default \`${this.default}\`.`:""}`}get m(){var a=this.args;this.args&&this.args[0]&&"this"==this.args[0].name&&([,...a]=this.args);return a}get isParsedFunction(){return!!this.parsed&&"function"==this.parsed.name}i(a="",b=!1,c={}){let d=[];var e=this.o;e&&(e=T(e),d.push(...e.split(B)));!this.optional&&this.isParsedFunction?(c=Ab(this,b,c),d.push(...c)):(c=this.parsed?R(this.parsed,c): | ||
this.closureType,d.push(` * @type {${this.optional?`${/[^\w\d._]/.test(c)?`(${c})`:c}|undefined`:c}}`));b&&this.examples.length&&(b=vb(this.examples),d.push(...b));a&&(d=d.map(f=>`${a}${f}`));return d.join(B)}F(a,b="",c=!1){a=yb(this,a,c);const [d,...e]=a.split(B);return[`@param ${d}`,...e].map(f=>`${b} * ${f}`).join(B)}}const Bb=a=>{let b="args";const {name:c="",description:d}=a[a.length-1]||{};c.startsWith("...")&&(b=c.replace("...",""));return{P:b,aa:d}};class U extends Eb{constructor(...a){super(...a);this.isConstructor=this.async=!1;this.return=""}b(a,b){super.b(a,b);"constructor"==b.name&&(this.isConstructor=!0);this.async=b.async;this.return=b.return}};function Fb(a,b,c,d){var e=Q(["prop","getter"],a).map(({content:k,props:l,tag:m})=>{const n=new Eb;"getter"==m&&(n.isGetter=!0);O(l,c);n.b(k,l);return n});a=Q(["function","fn","static"],a).map(({content:k,props:l,tag:m})=>{m="static"==m;const {L:n,H:r}=qb(k,b);k=new U(r);const {Y:t,J:p}=gb(l,r,d);t.type=p;O(t,c);k.b(n,t);m&&(k.g=!0);return k});e=[...e,...a];const {I:f,N:g,n:h}=e.reduce((k,l)=>{l.isConstructor?k.I.push(l):l.static?k.N.push(l):k.n.push(l);return k},{I:[],N:[],n:[]});e=f[0]||null;a= | ||
[...f,...g,...h];return{constructor:e,properties:a}};const Gb=(a,b,c={})=>{let d;if("object"==typeof b)d=b;else try{(d=nb(b))||console.log("Could not parse %s",b)}catch(e){console.log("Could not parse %s",b),console.error(e.message)}return d?V(d,a,c):b},V=(a,b,c={})=>{if(""==a.name&&a.nullable)return"?";var {escapePipe:d=!0}=c;let e="";var f="";a.nullable?f="?":!1===a.nullable&&(f="!");if(a.function){e=e+f+(a.name+"(");const g=[];a.function.this&&(d="this: "+V(a.function.this,b,c),g.push(d));a.function.new&&(d="new: "+V(a.function.new,b,c),g.push(d)); | ||
a.function.args.forEach(h=>{let k=V(h,b,c);h.optional&&(k+="=");g.push(k)});a.function.variableArgs&&(d="..."+V(a.function.variableArgs,b,c),g.push(d));d=g.join(", ");e+=d+")";a.function.return&&(e+=": "+V(a.function.return,b,c))}else a.record?(e+="{ ",d=Object.keys(a.record).map(g=>{var h=a.record[g];if(!h)return g;h=V(h,b,c);return`${g}: ${h}`}),e+=d.join(", "),e+=" }"):a.application?(e+=Hb(a.name,b,f,c)+"<",d=a.application.map(g=>V(g,b,c)),e+=d.join(", "),e+=">"):a.union?(e=e+f+"(",f=a.union.map(g=> | ||
V(g,b,c)),e+=f.join(d?" \\| ":" | "),e+=")"):e+=Hb("any"==a.name?"*":a.name,b,f,c);return e},Hb=(a,b,c="",d={})=>{const {flatten:e=!1,nameProcess:f,link:g=({link:l})=>`#${l}`}=d;d=Ib(b,a);c=`${c}${a}`;if(!d)return c;let {link:h,type:{description:k}}=d;e&&((b=b.find(({fullName:l})=>l==a))&&b.link&&(h=b.link),!k&&b.description&&(k=b.description),"function"==typeof e&&e(a));d.link==h&&(h=g(d));b=f?f(c):c;return k?`<a href="${h}" title="${k.replace(/"/g,""")}">${b}</a>`:`[${b}](${h})`},Ib=(a,b)=> | ||
{a=a.filter(({fullName:d})=>d==b);if(a.length){var c=a.find(({import:d})=>d||!1);a=a.find(({import:d})=>!d)||c;return{link:`${"type"}-${a.fullName.replace(/<\/?code>/g,"").replace(/<\/?strong>/g,"").replace(/<br\/>/g,"").replace(/ /g,"").replace(/[^\w-\d ]/g,"").toLowerCase().replace(/[, ]/g,"-")}`,type:a}}};function Jb(a,b=[],c=[],d={}){const {narrow:e=!1,preprocessDesc:f}=d;if(!b.length)return"";const g=a.isConstructor||a.isInterface,h=b.some(({hasDefault:n})=>n),k={escapePipe:!e,...d};let l;const m=n=>Gb(c,n,{...k,nameProcess:d.nameProcess?r=>d.nameProcess(r,l):void 0});a=b.map((n,r)=>{l=0<(r+1)%2;r=n.args&&n.isParsedFunction?n.toTypeScriptFunction(m):m(n.parsed||n.type);const t=g||n.optional?n.name:`${n.name}*`,p=n.hasDefault?`\`${n.default}\``:"-",u=f?f(n.description):n.description;return{prop:n, | ||
typeName:r,name:t,de:Kb(u,!e),d:p,ca:l}});if(e)return{props:a,anyHaveDefault:h,constr:g};a=a.map(({name:n,typeName:r,de:t,d:p,prop:u})=>[u.optional?n:`__${n}__`,`<em>${r}</em>`,t,...h?[p]:[]]);b=["Name",...e?["Type & Description"]:["Type","Description"],...h?[g?"Initial":"Default"]:[]];return["","","```table",JSON.stringify([b,...a],null,2).replace(/\n/g,B),"```"].join(B)}const Kb=(a="",b=!0)=>{null===a&&(a="");b&&(a=a.replace(/\|/g,"\\|"));return a.replace(/</g,"<").replace(/>/g,">")};const Lb=(a,b,c={})=>{function d(e){e.replace(/^!?/,"");return`\`${e}\``}return a.split(/,\s*/).map(e=>Gb(b,e,{flatten:!0,...c,nameProcess:c.nameProcess?f=>{f=c.nameProcess(f);return/[_*~>]/.test(f)?`<code>${f}</code>`:d(f)}:d})).join(", ")};function Mb(a){var b=a.h();b=L(b.join(B));b+=eb(a.namespace,a.name,Nb(a));const c=a.properties.reduce((d,e)=>{d.push(e);const f=e.aliases.map(g=>Db(e,g));d.push(...f);return d},[]).filter(d=>d instanceof U&&d.isConstructor?!1:!0).map(d=>{let e=d.i();e=L(e);e+=eb(`${a.fullName}${d.static?"":".prototype"}`,d.name);return e+=Cb(d)});return[b,...c].join(B)}function Ob(a,b=!1){const c=`${a.extends?"$":""}${a.name}`;return b?`${a.ns}${c}`:c} | ||
function Pb(a,b=!1,c=!1,d=b){d=` * @typedef {${(b?a.closureType:a.type)||a.u()}}${` ${Ob(a,d)}${a.m}`}`;a=(a.properties?a.properties.reduce((e,f)=>{if(f.static)return e;e.push(f);const g=f.aliases.map(h=>Db(f,h));e.push(...g);return e},[]):[]).filter(e=>e instanceof U?!e.isConstructor:!0).map(e=>zb(e,b));a=[d,...a].join(B);b&&!c&&(a=M(a));return a=L(a)}function Nb(a){return a.args?`function(${a.args.filter(({name:b})=>"this"!=b).map(({name:b})=>b).join(", ")}) {}`:null} | ||
class W extends rb{constructor(){super();this.file=this.link=this.closureType=null;this.properties=[]}get import(){return!1}b(a,{name:b,type:c,desc:d,noToc:e,spread:f,noExpand:g,link:h,closure:k,constructor:l,"extends":m,"interface":n,record:r,example:t,"example-override":p,"super-args":u},v,w=null){if(!b)throw Error("Type does not have a name.");this.name=b;c&&(this.type=c);k?this.closureType=k:this.closureType=this.type;d&&(this.description=N(d));this.noToc=!!e;this.spread=!!f;this.noExpand=!!g; | ||
h&&(this.link=h);!0===l&&(this.isConstructor=l);!0===n&&(this.isInterface=n);!0===r&&(this.isRecord=r);m&&(this.extends=m);v&&(this.namespace=v);if(a){const {properties:y,constructor:E}=Fb(a,w,this.file,this.fullName);E&&(this.args=E.args);this.properties=y}t&&(a={example:t},O(a,this.file),this.examples=ub(a.example,p));u&&(this.superArgs=u)}get M(){return this.isConstructor||this.isInterface||this.isRecord}i(){let a;this.closureType?a=` * @typedef {${this.closureType}}`:this.M||(a=` * @typedef {${Qb(this.properties, | ||
!0)}}`);return a?(this.description&&(a=` * ${this.description}${B}${a}`),a=L(a),a+=eb(this.namespace,this.name)):Mb(this)}u(){return"Object"}o(a,b=new RegExp(`([!?])?${a}\\.`,"g")){this.type&&(this.type=this.type.replace(b,"$1"));this.extends&&(this.extends=this.extends.replace(b,"$1"));return b}get m(){return`${this.tag?` \`\uff20${this.tag}\``:""}${this.description?` ${this.description}`:""}`}g(a=!1,b=!1,c=a){const d=!!this.extends,e=Pb(this,a,b,c),f=[];if(this.namespace&&a){var g=` * @typedef {${this.fullName}} ${this.name}${this.m}`; | ||
a&&!b&&(g=M(g));g=L(g);f.push(g)}else this.namespace&&c&&(g=` * @typedef {${this.fullName}} ${this.name}${this.m}`,g=L(g),f.push(g));d&&(c=` * @typedef {${Ob(this,c)} & ${this.extends.split(/,\s*/).join(" & ")}} ${c?this.fullName:this.name}${this.m}`,a&&!b&&(c=M(c)),c=L(c),f.push(c));f.push(e);return f.join("")}get Z(){const a=this.tag;if(!a)throw Error("Unknown prototype type (not constructor or interface).");return a}get tag(){return this.isConstructor?"constructor":this.isInterface?"interface": | ||
this.isRecord?"record":""}h(a="",b=!0,c=!1){let d=[];this.description&&d.push(` * ${this.description}`);const e=this.properties[0];e instanceof U&&e.isConstructor&&e.description&&d.push(T(e.description));this.extends&&this.extends.split(/,\s*/).forEach(f=>{d.push(` * @extends {${f}}`)});this.args&&this.args.forEach(f=>{let {name:g,description:h,optional:k,type:l}=f;f=h?` ${h}`:"";if(g.startsWith("..."))g=g.slice(3),l=`...${l}`;else if("this"==g){d.push(` * @this {${l}}${f}`);return}d.push(` * @param {${l}${k? | ||
"=":""}} ${k?`[${g}]`:g}${f}`)});b&&d.push(` * @${this.Z}`);c&&this.examples.length&&(b=vb(this.examples),d.push(...b));a&&(d=d.map(f=>`${a}${f}`));return d}get ns(){return this.namespace?`${this.namespace}.`:""}get fullName(){return`${this.ns}${this.name}`}F(a,b,c,d,e=!1,f=!1){var g="";!0===d?g="?":!1===d&&(g="!");d=this.description?` ${this.description}`:"";const h=this.spread?Qb(this.properties):e||f?this.fullName:this.name;b=`${c||""} * @param {${g}${h}} ${b?`[${a}]`:a}${d}`;g=this.properties&& | ||
!this.noExpand?this.properties.map(k=>k.F(a,c,e,f)):[];return[b,...g].join(B)}toMarkdown(a=[],b={}){const {flatten:c,details:d=[]}=b,e=d.includes(this.name);var f=this.type?`\`${this.type}\``:"",g=f;this.link?g=`[${f}](${this.link})`:!this.import&&this.type&&(g=Gb(a,this.type,b),f=g!=this.type,g=Rb(g,f));f=Rb(this.fullName);f=this.import?`[${f}](l-type)`:this.noToc?`[${f}](l-type)`:`[${f}](t-type)`;const h=this.description?`: ${this.description}`:"";g=g?`${g} `:"";let k=/_/.test(f);if(this.extends){const l= | ||
Lb(this.extends,a,b),m=` extends ${l}`;k=k||/_/.test(l);g=(k?g+"<strong>":g+"__")+(f+m);"function"==typeof c&&c(this.extends)}else g=(k?g+"<strong>":g+"__")+f;g=(k?g+"</strong>":g+"__")+h;a=Jb(this,this.properties,a,b);return{LINE:g,table:a,displayInDetails:e}}} | ||
const Rb=(a,b=!1)=>`${b?"<code>":"`"}${a}${b?"</code>":"`"}`,Qb=(a=[],b=!1)=>{a=a.reduce((c,d)=>{c.push(d);const e=d.aliases.map(f=>({...d,name:f}));c.push(...e);return c},[]);return`{ ${a.map(c=>{const d=b?c.closureType:c.type;let e=c.name,f=d;c.optional&&!b?e=`${c.name}?`:c.optional&&b&&(f=`(${`${/[^\w\d._]/.test(d)?`(${d})`:d}|undefined`})`);return`${e}: ${f}`}).join(", ")} }`};class Sb extends W{constructor(){super();this.from=""}get import(){return!0}b(a,{from:b,name:c,...d},e,f){if(!b)throw Error("From attribute of import is not given.");this.from=b;this.description=N(a);super.b("",{...d,noToc:!0,name:c,type:`import('${b}').${c}`},e!=f?e:null)}g(a=!0){return` * @typedef {import('${this.from}').${this.name}} ${a?this.fullName:this.name}`}};function Tb(a,b){b=b.reduce((c,d)=>({...c,[d.fullName]:d}),{});a.C={...a.C,...b}}class Ub extends Za{constructor(a,b={}){super(a);this.C={};this.on("types",c=>{Tb(this,c)});this.on("namespace",c=>{this.b.includes(c)||this.b.push(c)});this.f=b;this.b=[];this.j=console.log;this.file=null;this.lines=[]}static get Type(){return W}static get Import(){return Sb}get types(){return this.C}};class Vb extends W{constructor(){super();this.f=null;this.async=!1}get M(){return!1}get isMethod(){return!0}b(a,{async:b,"return":c,"void":d,...e},...f){this.description=N(a);super.b("",e,...f);c&&(this.f=c.replace(/\r?\n\s*/g," "));d&&(this.f="void");b&&(this.async=!0)}get return(){return this.f||"void"}h(a=""){const b=super.h(a,!1),c=this.v;c&&b.push(`${a} * @return {${c}}`);return b}get v(){let a="";this.f&&(a=this.return);this.async&&a?a=`Promise<${a}>`:this.async&&(a="Promise");return a}u(){return`(${this.args.map(({name:a, | ||
type:b,optional:c})=>`${a}${c?"?":""}: ${b}`).join(", ")}) => ${this.v}`}o(a){a=super.o(a);this.f&&(this.f=this.f.replace(a,"$1"))}};const Wb=(a,b)=>{const c=new RegExp(`([!?])?${a}\\.`,"g");b.properties.forEach(d=>{wb(d,a,c)});b.o(a)},Xb=(a,b)=>{var {args:c=[]}=a,d=c.map(({K:f})=>f).join(", ");let e=`new: ${a.fullName}`;d.length&&(e=`${e}, `);d=`function(${e}${d})`;c=new U(c);c.isConstructor=!0;c.b("Constructor method.",{type:d,name:"constructor"});c.examples=a.examples;wb(c,b);a.properties.unshift(c)},Zb=(a,b,c=null)=>{a=Q("types",a);if(!a.length)return console.log("Skipping XML file %s which does not contain root `types` element.", | ||
c),{types:[],imports:[]};const [{content:d,props:{namespace:e,ns:f=e}}]=a,g=b==f?void 0:f;a=Q(["embed"],d).map(({props:l})=>l);const h=[],k=Q("type interface constructor method import record".split(" "),d).reduce((l,{content:m,props:n,tag:r})=>{"record"==r&&(r="type",n.record=!0);const {alias:t,aliases:p,...u}=n;c&&O(u,c);var v=t?[t]:p?p.split(/, */):[];switch(r){case "type":r=new W;c&&(r.file=c);r.b(m,n,g,b);l.push(r);v.forEach(w=>{const y=new W;c&&(y.file=c);y.b(m,{...u,name:w},g,b);l.push(y)}); | ||
break;case "interface":n=Yb({content:m,props:n,ns:g,D:b,location:c});n.forEach(w=>{w.properties.some(({isConstructor:y})=>y)||Xb(w,b);w.isInterface=!0});l.push(...n);break;case "constructor":n=Yb({content:m,props:n,ns:g,D:b,location:c});n.forEach(w=>{w.properties.some(({isConstructor:y})=>y)||Xb(w,b);w.isConstructor=!0});l.push(...n);break;case "method":n=Yb({content:m,props:n,ns:g,D:b,isMethod:!0,location:c});l.push(...n);break;case "import":v=new Sb,v.b(m,n,n.ns||n.from,b),h.push(v)}return l},[]); | ||
b&&k.forEach(l=>Wb(b,l));return{namespace:f,types:k,imports:h,embeds:a}},$b=(a,b,c,d,e=!1,f=null)=>{const g=e?new Vb:new W;g.file=f;f=a.search(/<(prop|function|fn|static|getter) /);let h="",k=a;1!=f&&(h=a.slice(0,f),k=a.slice(f));const {H:l,L:m}=qb(h,d);g.b(e?m:k,b,c,d);({J:a}=gb(b,l));e&&(g.closureType=a);g.args||(g.args=l);return g},Yb=({content:a,props:b,ns:c,D:d,isMethod:e=!1,location:f=null})=>{const g=[],{alias:h,aliases:k,...l}=b;b=$b(a,b,c,d,e,f);g.push(b);(h?[h]:k?k.split(/, */):[]).forEach(m=> | ||
{m=$b(a,{...l,name:m},c,d,e,f);m.description=`${m.description}${m.description?" ":""}Alias of \`${l.name}\`.`;g.push(m)});return g},ac=()=>{Object.keys(X).forEach(a=>{delete X[a]});Object.keys(Y).forEach(a=>{delete Y[a]})},X={},Y={},cc=async a=>{var b=Y[a];b?b=await b:(b=G(a),Y[a]=b,b=await b);return bc(b,a,[])},dc=(a,b=[])=>{a in X||(X[a]=ua(a,"utf8"));return bc(X[a],a,b)},bc=(a,b,c)=>{let d,e,f,g;try{({namespace:d=null,types:e,imports:f,embeds:g}=Zb(a,void 0,b))}catch(h){throw h.message=`Error while reading ${b}${B}${h.message}`, | ||
h;}e=e.filter(({fullName:h})=>c.includes(h)?!1:!0);f=f.filter(({fullName:h})=>c.includes(h)?!1:!0);return{types:e,imports:f,namespace:d,embeds:g}};const ec=(a,b,c)=>{b=b.map(d=>d.g(!0,c));a=a.map(d=>{d=d.g();return L(c?d:M(d))});return[...b,...a].join("")},fc=(a,b,c,d=!1)=>{a=a.map(e=>e.i());a=P(...a,...[]);return`${!b||d||c.includes(b)?"":["/** @const */",`var ${b} = {}`,""].join(B)}${a}`};function gc(a,b,c){const [d,...e]=c.split(/\s+/);var f=e.includes("closure");const g=e.includes("externs"),h=e.includes("noSuppress"),k=e.includes("skipNsDecl"),l=e.includes("namespace"),m=e.includes("noEmbed")||e.includes("no-embed");let n=e.find(p=>p.startsWith("ignore:"));n=n?n.replace("ignore:","").split(","):[];let {s:r,A:t}=this.f;f&&(r=!0);g&&(t=!0);try{this.j("Detected type marker: %s",c);const {types:p,imports:u,namespace:v,embeds:w}=dc(d,n);this.emit("types",p);this.emit("types",u);f=[]; | ||
!m&&w.length&&(f=w.map(({src:F,path:pc=F,ignore:S=n.join(","),namespace:qc=l,s:rc=r,A:sc=t,"no-suppress":tc=h})=>{F=[pc];S&&F.push(`ignore:${S}`);qc&&F.push("namespace");rc&&F.push("closure");sc&&F.push("ext");tc&&F.push("noSuppress");S=F.join(" ");return gc.call(this,`${B} /* typal-embed ${S} */${B}`,"typal-embed",S)}));let y=f.join(""),E;r?E=ec(u,p,h):t?(E=fc(p,v,this.b,k)+B,v&&this.emit("namespace",v)):l?(v&&this.emit("namespace",v),E=hc(u,p,!0)):E=hc(u,p);return`/* ${b} ${c} */${B}${E}${y}`}catch(p){return this.j("(%s) Could not process typedef-js: %s", | ||
c,p.message),process.env.b&&console.error(p.stack),a}}const ic={re:/^\/\*\*? (documentary|typal) (.+?) \*\/\r?\n(?:((?!\r?\n)[\s\S]+?\r?\n))?$/mg,replacement:gc},hc=(a,b,c=!1)=>{b=b.map(d=>d.g(!1,!1,c));a=a.map(d=>d.g(c)).map(L).join("");b=b.join("");return`${a}${b}`.replace(jc," * @typedef")},jc=/ \*\/\r?\n\/\*\*\r?\n \* @typedef/g;const lc={re:/( *) \* @param {(.+?)} (\[)?([^\s\]]+)\]?(?: .+)?((?:\r?\n(?: +)\* @param {(?:.+?)} \[?\4\]?(?:(?!\r?\n\s*\*(?:\/|\s*@))[\s\S])*)*)/gm,replacement:kc}; | ||
function kc(a,b,c,d,e,f,g){const h=this.f.s,k=this.f.G;let l;f=()=>{if(this.lines&&this.file){var n;{let p=n=0;for(;p<g;)p+=this.lines[n].length,n++;n={line:n,T:b.length+11}}const {line:r,T:t}=n;this.j("%s:%s:%s",this.file,r,t)}};try{l=nb(c)}catch(n){return this.j("Error while parsing the type %s",c),this.j(process.env.DEBUG?n.stack:n.message),f(),a}if(!l)return this.j("Could not parse the type %s",c),f(),a;const m=Object.values(this.types).map(({name:n,fullName:r})=>h||k?r:n);if(!Z(l,m,this.j,c, | ||
f))return a;c=Object.values(this.types).find(({name:n,fullName:r})=>h||k?r==l.name:n==l.name);return!c||c instanceof Ub.Import?a:c.F(e,d,b,l.nullable,h,k)} | ||
const Z=(a,b,c,d,e)=>{if(a){var f=a.name;if(!f||!"string number boolean null undefined symbol any".split(" ").includes(f)){if(f&&!a.application&&!a.function){let h=b.includes(f);h||(h=mc.includes(f));if(h)return!0;c("Type %s%s was not found.",f,d!=f?` in ${d}`:"");e()}var g=[b,c,d,e];a.application?a.application.forEach(h=>{Z(h,...g)}):a.record?Object.keys(a.record).forEach(h=>{Z(a.record[h],...g)}):a.union?a.union.forEach(h=>{Z(h,...g)}):a.function&&(Z(a.function.this,...g),Z(a.function.new,...g), | ||
a.function.args.forEach(h=>{Z(h,...g)}),Z(a.function.variableArgs,...g),Z(a.function.return,...g))}}},mc="String Boolean Object Date Number Symbol Buffer Function RegExp".split(" ");var nc=(a,b=!1)=>{ac();var {V:c}=Ua();const d=Wa(c);c=Va(c);return new Ub(b?[ic]:[ic,d,lc,c],a)};const oc=_module.builtinModules;const uc=/( *) \* @(fnType|methodType) {(.+?)}/gm,vc=(a,b,c,d,e,f,g=d)=>{c=`${b?"static ":""}${c?"async ":""}${d}(${e}) {`;return P("/**",a," */",...null===f?[`${c} }`]:[c,` return ${`${b?f:"super"}.${g}`}(${e})`,"}"])}; | ||
function wc(a,b,c,d={}){return a.map(e=>{const f=e.name;var g=e.aliases;const h=e.static,k=e.async;let l=e.i("",!0,d);l=xc(l,c);const m=e.args.map(({name:n})=>n).join(", ");e=vc(l,h,k,f,m,b);g=g.map(n=>vc(l+`${B} * @alias ${f} An alias for **${f}**.`,h,k,n,m,b,f));return[e,...g].join(B)})} | ||
function yc(a,b){return a.map(c=>{const d=c.name;var e=c.default;const f=c.type;c=c.i("",!0,b);let g="";if(e||!1===e)e=bb(f,e,"'"),"'[]'"==e&&(e="[]"),g=` = ${e}`;return["/**",c," */",`this.${d}${g}`].join(B)})}function zc(a,b){return a.map(c=>{const d=c.name;var e=c.default;const f=c.type;c=c.i("",!0,b);let g="";if(e||!1===e)e=bb(f,e,"'"),"'[]'"==e&&(e="[]"),g=`return ${e}`;return P("/**",c," */",...g?[`get ${d}() {`,` ${g}`,"}"]:[`get ${d}() { }`])})} | ||
const Ac=/(\/\*\*[\s\S]+?)( *\* *@implements {(.+?)})[\s\S]+?((?:export\s+(?:default\s+)?)?class\s+(\S+).*?){\s*}/gm,Bc=(a,b)=>({re:Ac,replacement(c,d,e,f,g,h){this.isInterface=!0;const k=a.find(({fullName:p})=>p==f);if(!k)return console.error("Type %s in %s not found",f,b),c;c=k.properties.filter(p=>p instanceof U&&!p.isConstructor);var l=k.properties.filter(p=>p.isGetter),m=k.properties.filter(p=>p instanceof Eb&&!p.isGetter&&!(p instanceof U));c=wc(c,null,f,this.B);m=yc(m,this.B).map(p=>p.replace(/(^|(?:\r?\n))/g, | ||
"$1 "));l=zc(l,this.B);const n=k.properties.find(p=>p instanceof U&&p.isConstructor),r=n.args.map(({name:p})=>p).join(", ");k.extends&&k.extends.split(/,\s*/).forEach(p=>this.$[p]=!0);const t=0<m.length;h=P("/**",xc(n.i("",!0),f)," */",`constructor(${r}) {${t||k.extends?"":" }"}`,...k.extends?[` super(${k.superArgs||""})`]:[],...m,t||k.extends?"}"+B+"/**":"/**"," * Sets the implementation on the interface.",` * @param {!${h}} Implementation`," */","static __implement(Implementation) {"," Object.defineProperties(", | ||
` ${h}.prototype,`," Object.getOwnPropertyDescriptors(Implementation)"," )","}",...c,...l);h=h.replace(/(^|(?:\r?\n))/g,"$1 ");return P(d.trimRight(),...k.description?[T(k.description)]:[],e," */",`${g}{`,h,"}")}}); | ||
class Cc extends Za{constructor(a,b){super([{re:Ac,replacement(d,e,f,g,h,k){this.B[g]=k;return d}},{re:/\/\*\*(?:\s+( *) \*)? @constructor {(.+?)}[\s\S]+?(class\s+.+?\s+extends\s+(.+?)\s*){\s*}/gm,replacement(d,e,f,g,h){e=a.find(({fullName:l})=>l==f);if(!e)return console.error("Type %s in %s not found",f,b),d;d=e.properties.filter(l=>l instanceof U&&!l.isConstructor);h=wc(d,h,f);d=e.properties.find(l=>l instanceof U&&l.isConstructor);const k=d.args.map(({name:l})=>l).join(", ");h=P("/**",xc(d.i("", | ||
!0),f)," */",`constructor(${k}) {`,` super(${k})`,"}",...h);h=h.replace(/(^|(?:\r?\n))/g,"$1 ");return P(...e.description?["/**",T(e.description)," */"]:[],`${g}{`,h,"}")}},Bc(a,b),{re:uc,async replacement(d,e,f,g){const h=g.split(".");let k,l;if("methodType"==f)k=g;else if(2==h.length)[k,l]=h;else if(3==h.length)k=`${h[0]}.${h[1]}`,l=h[2];else throw Error("The @fnType should consist of _namespace.Type.propName or Type.propName");g=a.find(({fullName:m})=>m==k);if(!g)return console.error("Type %s in %s not found", | ||
k,b),d;if("constructor"==l||"methodType"==f)return g.h(e,!1,!0).join(B);f=g.properties.find(({name:m})=>m==l);return f?f.parsed?f.i(e,!0):(console.error("Property %s of type %s in %s wasn't parsed, possibly parser bug.",l,k,b),d):(console.error("Property %s of type %s in %s not found",l,k,b),d)}},{re:/ \* @typedef {import\(.+?} .+/gm,replacement(d,e,f){return!this.isInterface||f.substr(0,e).trim().endsWith("@suppress {nonStandardJsDocs}")?d:M(d)}},{re:/ \* @typedef {import\(.+?} .+\r?\n \* @suppress/gm, | ||
replacement(d){if(!this.isInterface)return d;const [e,f]=d.split(/\r?\n/);return[e," */","/**",f].join(B)}},{re:/[\s\S]+/,replacement(d){const e=Object.keys(c).map(f=>{const [g,h]=f.split(".");return!oc.includes(g)||d.includes(`@typedef {import('${g}').${h}}`)?null:["/**"," * @suppress {nonStandardJsDocs}",` * @typedef {import('${g}').${h}} ${g}.${h}`," */"].join(B)}).filter(Boolean).join(B);return e?[d,"",e].join(B):d}}]);this.isInterface=!1;const c={};this.B=new Proxy({},{get(d,e){c[e]=!0;return d[e]}}); | ||
this.$=c}}const xc=(a,b)=>a.replace(`${B} * @return {${b}}`,"").replace(`${B} * @return {!${b}}`,"").replace(`${B} * @return {?${b}}`,"");const Dc=async a=>a?(await Promise.all(a.split(",").map(async b=>{var c=[];const d=await I(z,b);d.isFile()?c=[b]:d.isDirectory()&&(c=await J(b),c=K(c.content,b),c=c.filter(e=>e.endsWith(".xml")));return c}))).reduce((b,c)=>[...b,...c],[]):[],Ec=async a=>(await Promise.all(a.map(async b=>({...await cc(b),location:b})))).reduce((b,{imports:c,types:d})=>{b.push(...c);b.push(...d);return b},[]); | ||
async function Fc(){ac();const a=await Dc(na),b=await Ec(a);await Promise.all(x.map(async c=>{var d=await I(z,c);let e;d.isFile()?e=[c]:d.isDirectory()&&(d=await J(c),e=K(d.content,c));await Gc(e,b,oa)}))}const Gc=async(a,b=[],c=null)=>{await Promise.all(a.map(async d=>{var e=await G(d);const f=new Cc(b,d);f.end(e);e=await D(f);"-"==c?console.log(e):c?await H(c,e):await H(d,e)}))};var Ic=async()=>{const {s:a=!1,G:b=!1,A:c=!1,X:d,types:e}={s:ka,A:ma,X:ja,types:na,G:la},f=await Dc(e);await Promise.all(x.map(async g=>{var h=await I(z,g);let k;h.isFile()?k=[g]:h.isDirectory()&&(h=await J(g),k=K(h.content,g));await Hc(k,a,c,d,f,b)}))}; | ||
const Hc=async(a,b=!1,c=!1,d="",e=[],f=!1)=>{const g=[];await Promise.all(e.map(async h=>{h=await G(h);const {types:k,imports:l}=Zb(h);g.push(k,l)}));await Promise.all(a.map(async h=>{var k=await G(h);const l=nc({s:b,A:c,G:f},c);g.forEach(m=>l.emit("types",m));l.file=h;l.j=console.error;l.lines=k.split(B);l.end(k);k=await D(l);"-"==d?console.log(k):d?await H(d,k):await H(h,k)}))};const Jc=a=>{let b;"true"==a?b=!0:"false"==a?b=!1:/^\d+$/.test(a)&&(b=parseInt(a,10));return void 0!==b?b:a},Kc=/^ \* @prop {(.+?)} (\[)?(.+?)(?:=(["'])?(.+?)\4)?(?:])?(?: (.+?))?(?: Default `(.+?)`.)?$/gm,Lc="type opt name quote defaultValue description Default".split(" "),ab=new RegExp(`^ \\* @typedef {(.+?)} (.+?)(?: (.+))?\\r?\\n((?:${/ \* @prop(?:erty)? .+\r?\n/.source})*)`,"gm"),Mc=(a,b,c,d)=>{d=d.length;a=a&&"Object"!=a?` type="${a}"`:"";c=c?` desc="${c}"`:"";return`${" ".repeat(2)}<type name="${b}"${a}${c}${d? | ||
"":" /"}>${B}`}; | ||
class Jc extends A{constructor(){super({writableObjectMode:!0})}_transform({type:a,name:b,description:c,properties:d},e,g){a=a&&a.startsWith("import")?Kc(a,b):Ic(a,b,c,d);this.push(a);d.forEach(({type:f,name:h,default:k,description:l,optional:m})=>{{f=["string","number","boolean"].includes(f)?` ${f}`:` type="${f}"`;var n=void 0!==k;k=n?` default="${k}"`:"";m=m&&!n?" opt":"";n=" ".repeat(4);const q=" ".repeat(6);h=`${n}<prop${m}${f} name="${h}"${k}${l?`>${B}${q}${l}${B}${n}</prop>`:"/>"}${B}`}this.push(h)}); | ||
d.length&&this.push(` </type>${B}`);g()}}const Kc=(a,b)=>{const c=/import\((['"])(.+?)\1\)/.exec(a);if(!c)throw Error(`Could not extract package from "${a}"`);[,,a]=c;return`${" ".repeat(2)}<import name="${b}" from="${a}" />${B}`}; | ||
class Lc extends A{constructor(){super({objectMode:!0})}_transform([,a,b,c,d],e,g){d=ib(Gc,d,Hc).map(f=>{const {defaultValue:h,Default:k,opt:l,name:m,type:n,...q}=f;f={...q,name:m,type:n,...h?{defaultValue:Fc(h)}:{},...k?{w:Fc(k)}:{},...l?{optional:!0}:{}};if(h||k){if(h)h!==k&&void 0!==f.w&&(r=cb(m,k,n),console.error("%s[%s] does not match Default `%s`.",b,r,f.w));else{var r=cb(m,k,n);console.error("%s[%s] got from Default.",b,r)}f.default="defaultValue"in f?f.defaultValue:f.w;delete f.defaultValue; | ||
delete f.w}return f});this.push({type:a,name:b,description:c,properties:d});g()}}async function Mc(a){const b=$a(),c=new Lc,d=new Jc;b.pipe(c).pipe(d);b.end(a);b.on("error",e=>{console.error("Error in Transform");d.emit("error",e)});c.on("error",e=>{console.error("Error in RegexTransform");d.emit("error",e)});d.on("error",e=>{console.error("Error in XML");d.emit("error",e)});return["<types>",` ${(await D(d)).trim()}`,"</types>"].join(B)};var Nc=async()=>{await Promise.all(x.map(async a=>{a=await F(a);a=await Mc(a);ja?await G(ja,a):console.log(a)}))};/* | ||
class Nc extends A{constructor(){super({writableObjectMode:!0})}_transform({type:a,name:b,description:c,properties:d},e,f){a=a&&a.startsWith("import")?Oc(a,b):Mc(a,b,c,d);this.push(a);d.forEach(({type:g,name:h,default:k,description:l,optional:m})=>{{g=["string","number","boolean"].includes(g)?` ${g}`:` type="${g}"`;var n=void 0!==k;k=n?` default="${k}"`:"";m=m&&!n?" opt":"";n=" ".repeat(4);const r=" ".repeat(6);h=`${n}<prop${m}${g} name="${h}"${k}${l?`>${B}${r}${l}${B}${n}</prop>`:"/>"}${B}`}this.push(h)}); | ||
d.length&&this.push(` </type>${B}`);f()}}const Oc=(a,b)=>{const c=/import\((['"])(.+?)\1\)/.exec(a);if(!c)throw Error(`Could not extract package from "${a}"`);[,,a]=c;return`${" ".repeat(2)}<import name="${b}" from="${a}" />${B}`}; | ||
class Pc extends A{constructor(){super({objectMode:!0})}_transform([,a,b,c,d],e,f){d=hb(Kc,d,Lc).map(g=>{const {defaultValue:h,Default:k,opt:l,name:m,type:n,...r}=g;g={...r,name:m,type:n,...h?{defaultValue:Jc(h)}:{},...k?{w:Jc(k)}:{},...l?{optional:!0}:{}};if(h||k){if(h)h!==k&&void 0!==g.w&&(t=cb(m,k,n),console.error("%s[%s] does not match Default `%s`.",b,t,g.w));else{var t=cb(m,k,n);console.error("%s[%s] got from Default.",b,t)}g.default="defaultValue"in g?g.defaultValue:g.w;delete g.defaultValue; | ||
delete g.w}return g});this.push({type:a,name:b,description:c,properties:d});f()}}async function Qc(a){const b=$a(),c=new Pc,d=new Nc;b.pipe(c).pipe(d);b.end(a);b.on("error",e=>{console.error("Error in Transform");d.emit("error",e)});c.on("error",e=>{console.error("Error in RegexTransform");d.emit("error",e)});d.on("error",e=>{console.error("Error in XML");d.emit("error",e)});return["<types>",` ${(await D(d)).trim()}`,"</types>"].join(B)};var Rc=async()=>{await Promise.all(x.map(async a=>{a=await G(a);a=await Qc(a);ja?await H(ja,a):console.log(a)}))};/* | ||
@@ -106,2 +111,2 @@ Typal: keep types information in XML files to embed as typedefs, | ||
*/ | ||
if(p.help){const a=ia();console.log(ra({usage:a,description:"Embeds and maintains Closure-compatible types JSDoc in\nJavaScript source code from an external types.xml file.",line:"typal source [--closure|externs] [--migrate] [-o output] [-hv]",example:"typal src/index.js -c"}));process.exit()}else qa&&(console.log(require("../../package.json").version),process.exit());(async()=>{try{return pa?await Nc():oa?await Bc():await Ec()}catch(a){process.env.DEBUG?console.log(a.stack):console.log(a.message)}})(); | ||
if(q.help){const a=ia();console.log(ra({usage:a,description:"Embeds and maintains Closure-compatible types JSDoc in\nJavaScript source code from an external types.xml file.",line:"typal source [--closure|externs] [--migrate] [-o output] [-hv]",example:"typal src/index.js -c"}));process.exit()}else qa&&(console.log(require("../../package.json").version),process.exit());(async()=>{try{return pa?await Rc():oa?await Fc():await Ic()}catch(a){process.env.DEBUG?console.log(a.stack):console.log(a.message)}})(); |
@@ -47,3 +47,3 @@ const { _parseFile, _getLinks } = require('./typal') | ||
* @prop {?string} link The link to the documentation page. Default `null`. | ||
* @prop {!Array<!(_typal.Property|_typal.Fn)>} properties The properties of the type. Default `[]`. | ||
* @prop {!Array<!_typal.Property>} properties The properties of the type. Default `[]`. | ||
* @prop {?string} namespace The type's namespace, e.g., `_typal`. Default `null`. | ||
@@ -77,2 +77,3 @@ * @prop {string} ns The namespace or an empty string. | ||
* @prop {?string} extends Types `@constructor`, `@interface` and `@record` can inherit properties from other types using `@extends`. [Closure Wiki](https://github.com/google/closure-compiler/wiki/Annotating-JavaScript-for-the-Closure-Compiler#extends-type). Default `null`. | ||
* @prop {?string} superArgs The arguments that will be passed to the super constructor, as a string. Used in `@implements` interface generator via templates. Default `null`. | ||
* @prop {Array<!_typal.Arg>} args Constructors and interfaces can have arguments defined in _types.xml_, which will be parsed and stored in this property. Default `null`. | ||
@@ -92,4 +93,5 @@ * @prop {!Array<string>} examples Examples that have been read. Default `[]`. | ||
* @prop {boolean} hasDefault Whether the property has the default value. Default `false`. | ||
* @prop {?(string|boolean|number)} default The default value of the property. Default `null`. | ||
* @prop {?(string|boolean|number)} default The default value of the property. If the default is given as `null` in the XML attribute (e.g., `default="null"`), it will be recorded not as `null` but as `"null"` here. When this value is `null` it means there wasn't a default specified. Default `null`. | ||
* @prop {boolean} optional If the property is optional. Default `false`. | ||
* @prop {boolean} isGetter Whether this property works as a getter. Default `false`. | ||
* @prop {Array<!_typal.Arg>} args Function properties can have arguments specified inside of their tags. Default `null`. | ||
@@ -96,0 +98,0 @@ * @prop {boolean} isParsedFunction Whether the property is a function which was parsed. Default `false`. |
@@ -6,24 +6,25 @@ #!/usr/bin/env node | ||
const path = require('path'); | ||
const stream = require('stream'); var w="function"==typeof Object.defineProperties?Object.defineProperty:function(a,b,d){a!=Array.prototype&&a!=Object.prototype&&(a[b]=d.value)};function x(a){a=["object"==typeof window&&window,"object"==typeof self&&self,"object"==typeof global&&global,a];for(var b=0;b<a.length;++b){var d=a[b];if(d&&d.Math==Math)return d}throw Error("Cannot find global object");}var y=x(this); | ||
function A(a,b){if(b){var d=y;a=a.split(".");for(var c=0;c<a.length-1;c++){var f=a[c];f in d||(d[f]={});d=d[f]}a=a[a.length-1];c=d[a];b=b(c);b!=c&&null!=b&&w(d,a,{configurable:!0,writable:!0,value:b})}}A("String.prototype.trimRight",function(a){function b(){return this.replace(/[\s\xa0]+$/,"")}return a||b});const B=os.EOL;function C(a,b,d){const c=[];b.replace(a,(f,...g)=>{f=g.slice(0,g.length-2).reduce((e,k,h)=>{h=d[h];if(!h||void 0===k)return e;e[h]=k;return e},{});c.push(f)});return c};const D=new RegExp(`${/([^\s>=/]+)/.source}(?:\\s*=\\s*${/(?:"([\s\S]*?)"|'([\s\S]*?)')/.source})?`,"g"),E=new RegExp(`(?:\\s+((?:${D.source}\\s*)*))`);const G=(a,b)=>{a=(Array.isArray(a)?a:[a]).join("|");return C(new RegExp(`<(${a})${E.source}?(?:${/\s*\/>/.source}|${/>([\s\S]+?)?<\/\1>/.source})`,"g"),b,"t a v v1 v2 c".split(" ")).map(({t:d,a:c="",c:f=""})=>{c=c.replace(/\/$/,"").trim();c=F(c);return{content:f,props:c,tag:d}})},F=a=>C(D,a,["key","val","def","f"]).reduce((b,{key:d,val:c})=>{if(void 0===c)return b[d]=!0,b;b[d]="true"==c?!0:"false"==c?!1:/^\d+$/.test(c)?parseInt(c,10):c;return b},{});const aa=a=>a.split(/([!?=*(),:.<>{}|\s+])/g).filter(b=>/\S/.test(b)).map(b=>{switch(b){case "function":return"function";case "Function":return"Function";case "!":return"nonNullable";case "?":return"nullable";case "=":return"=";case "*":return"any"}return b}); | ||
function ba(a){let b=0;const d=(f=1)=>a[b+f],c=(f=!0,g=[])=>{var e={};let k=a[b];if(["nullable","nonNullable"].includes(k)){if(!f)throw Error(`${k} not allowed after .`);e.nullable="nullable"===k;b++}k=a[b];if("("==k){b++;e={...c(!0,[]),...e};if(")"!=a[b])throw Error("Expecting closing )");b++;if("|"!=a[b])return e}else if("{"==k){b++;g=e;for(f={};"}"!=a[b];){var h=a[b];b++;f[h]=null;if(":"==a[b]){b++;try{var l=c();f[h]=l}catch(m){throw m.message+=`(when parsing ${h} property)`,m;}}if("}"==a[b]){b++; | ||
const stream = require('stream'); var v="function"==typeof Object.defineProperties?Object.defineProperty:function(a,b,d){a!=Array.prototype&&a!=Object.prototype&&(a[b]=d.value)};function y(a){a=["object"==typeof window&&window,"object"==typeof self&&self,"object"==typeof global&&global,a];for(var b=0;b<a.length;++b){var d=a[b];if(d&&d.Math==Math)return d}throw Error("Cannot find global object");}var z=y(this); | ||
function A(a,b){if(b){var d=z;a=a.split(".");for(var c=0;c<a.length-1;c++){var f=a[c];f in d||(d[f]={});d=d[f]}a=a[a.length-1];c=d[a];b=b(c);b!=c&&null!=b&&v(d,a,{configurable:!0,writable:!0,value:b})}}A("String.prototype.trimRight",function(a){function b(){return this.replace(/[\s\xa0]+$/,"")}return a||b});const B=os.EOL;function C(a,b,d){const c=[];b.replace(a,(f,...g)=>{f=g.slice(0,g.length-2).reduce((e,k,h)=>{h=d[h];if(!h||void 0===k)return e;e[h]=k;return e},{});c.push(f)});return c};const D=new RegExp(`${/([^\s>=/]+)/.source}(?:\\s*=\\s*${/(?:"([\s\S]*?)"|'([\s\S]*?)')/.source})?`,"g"),E=new RegExp(`(?:\\s+((?:${D.source}\\s*)*))`);const F=(a,b)=>{a=(Array.isArray(a)?a:[a]).join("|");return C(new RegExp(`<(${a})${E.source}?(?:${/\s*\/>/.source}|${/>([\s\S]+?)?<\/\1>/.source})`,"g"),b,"t a v v1 v2 c".split(" ")).map(({t:d,a:c="",c:f=""})=>{c=c.replace(/\/$/,"").trim();c=aa(c);return{content:f,props:c,tag:d}})},aa=a=>C(D,a,["key","val","def","f"]).reduce((b,{key:d,val:c})=>{if(void 0===c)return b[d]=!0,b;b[d]="true"==c?!0:"false"==c?!1:/^\d+$/.test(c)?parseInt(c,10):c;return b},{});const ba=a=>a.split(/([!?=*(),:.<>{}|\s+])/g).filter(b=>/\S/.test(b)).map(b=>{switch(b){case "function":return"function";case "Function":return"Function";case "!":return"nonNullable";case "?":return"nullable";case "=":return"=";case "*":return"any"}return b}); | ||
function ca(a){let b=0;const d=(f=1)=>a[b+f],c=(f=!0,g=[])=>{var e={};let k=a[b];if(["nullable","nonNullable"].includes(k)){if(!f)throw Error(`${k} not allowed after .`);e.nullable="nullable"===k;b++}k=a[b];if("("==k){b++;e={...c(!0,[]),...e};if(")"!=a[b])throw Error("Expecting closing )");b++;if("|"!=a[b])return e}else if("{"==k){b++;g=e;for(f={};"}"!=a[b];){var h=a[b];b++;f[h]=null;if(":"==a[b]){b++;try{var l=c();f[h]=l}catch(m){throw m.message+=`(when parsing ${h} property)`,m;}}if("}"==a[b]){b++; | ||
break}if(","!=a[b])throw Error(`Expecting , for record after ${h}`);b++}g.record=f;return e}if(["nonNullable","nullable"].includes(k))throw Error("Nullability already defined.");if(/[=),:.<>}|]/.test(k))throw Error(`Unexpected token ${k}.`);"|"!=a[b]&&(e.name=a[b],b++);if("function"==k){l=e;h={return:null,args:[]};if("("!=a[b])throw Error("Expecting opening (");b++;for(var n;")"!=a[b];){if(n&&"this"==a[b])throw Error("this must come first in function arguments");if(n&&"new"==a[b])throw Error("new must come first in function arguments"); | ||
if("this"==a[b]){b++;if(":"!=a[b])throw Error("Expecting :");b++;h.this=c()}else if("new"==a[b]){b++;if(":"!=a[b])throw Error("Expecting :");b++;h.new=c()}else if("."==a[b]&&"."==d()&&"."==d(2)){b++;b++;b++;n=c();if(")"!=a[b])throw Error("Variable args must come last");h.variableArgs=n}else n=c(),h.args.push(n),"="==a[b]&&(n.optional=!0,b++);n=!0;if(")"==a[b])break;if(","==a[b])b++;else throw Error("Expecting , between arguments");}b++;":"==a[b]&&(b++,n=c(),void 0==n.name&&n.nullable&&(n.name=""), | ||
h.return=n);l.function=h}else if("<"==a[b]||(h="."==a[b]&&"<"==d())){b++;h&&b++;l=e;for(h=[];">"!=a[b];){n=c();h.push(n);if(">"==a[b])break;if(","==a[b])b++;else throw Error("Expecting , between applications");}b++;l.application=h}for(;"."==a[b];){e.name+=".";b++;({name:l}=c(!1));if(!l)throw Error("Expected to see the name after .");e.name+=l}if("|"!=a[b]||!f)return e;for(g.push(e);"|"==a[b];)b++,e=c(!0,g),e.union!==g&&g.push(e);return{union:g}};return c()};function H(a){a=aa(a);return ba(a)};const ca=path.dirname,da=path.resolve;const I=({A:a,C:b,l:d,type:c})=>b?"string":a?"number":d?"boolean":c?c:"*",ea=a=>{const b=a.split(/\r?\n/).map(d=>{let c=Infinity;d.replace(/\S/,(f,g)=>{c=g});return c}).reduce((d,c)=>c<d?c:d,Infinity);return a.replace(new RegExp(`^ {${b}}`,"gm"),"")},J=a=>{a=a.trimRight();a=a.replace(/^\s*\r?\n( *\S)/,"$1");return ea(a)},K=(a,b,d=null)=>{const {async:c,"void":f,"return":g=f?"void":"",...e}=a;({args:a=""}=a);a||(a=b.map(({s:k,name:h})=>"this"==h?`${h}: ${k}`:h.startsWith("...")?`...${k}`:k).join(",")); | ||
b=g.replace(/\r?\n\s*/g," ");c&&b?b=`!Promise<${b}>`:c&&(b="!Promise");d=`function(${"constructor"==e.name?`new: ${d}, `:""}${a})`;b&&(d+=`: ${b}`);return{F:{...e,async:c,return:b},o:d}};function L(a,b){const d=a.example;d&&d.startsWith(".")&&b&&(a.example=da(ca(b),d))};function fa(a,b,{name:d,string:c,"boolean":f,opt:g,number:e,type:k},h){if(!d)throw Error("Argument does not have a name.");a.name=d;b&&(a.description=J(b));b=I({A:e,C:c,l:f,type:k});h&&(b=b.replace(new RegExp(`([!?])?${h}\\.`,"g"),"$1"));b.endsWith("=")&&(b=b.replace(/=$/,""),g=!0);a.type=b;g&&(a.optional=!0)}class ha{constructor(){this.name=null;this.type="";this.optional=!1;this.description=""}get s(){return this.optional?`${this.type}=`:this.type}} | ||
const M=(a,b)=>{let d=a.lastIndexOf("</arg>"),c=a;var f=[];-1!=d&&(d+=6,f=a.slice(0,d),c=a.slice(d),f=G("arg",f),f=f.map(({content:g,props:e})=>{const k=new ha;fa(k,g,e,b);return k}));return{w:c,j:f}};const ia=fs.readFileSync;const ja=a=>{const b=a.replace(/^\s*\r?\n/gm,"").split(B).reduce((d,c)=>{[{length:c=0}={}]=/^\s*/.exec(c)||[];return c<d?c:d},Infinity);return a.replace(new RegExp(`^ {${b}}`,"gm"),"")}; | ||
function N(a,b=""){const d=b.split(/\s*,\s*/);return a.split(/\s*,\s*/).map(c=>{let f=c=ia(c,"utf8");if(c=/\/\* start example \*\/\r?\n([\s\S]+?)\r?\n\s*\/\* end example \*\//.exec(c))[,c]=c,f=ja(c);d.forEach(g=>{const [e,k]=g.split(/\s*=>\s*/);f=f.replace(`'${e}'`,`'${k}'`);f=f.replace(`"${e}"`,`"${k}"`)});return f=f.replace(/@/g,"\uff20")})}function O(a,b,d=new RegExp(`([!?])?${b}\\.`,"g")){b&&(a.f&&(a.f=a.f.replace(d,"$1")),a.type=a.type.replace(d,"$1"))} | ||
class P{constructor(a=null){this.h=this.description=this.name=null;this.u="";this.default=this.f=null;this.optional=!1;this.aliases=[];this.v=!1;this.parsed=null;this.args=a;this.g=!1;this.examples=[]}toTypeScriptFunction(a){if(!this.parsed)throw Error("The property was not parsed.");let {function:{new:b,args:d,return:c,this:f,variableArgs:g}}=this.parsed;b&&(c=b);var e=d.map(h=>a(h)).map((h,l)=>{const {optional:n}=d[l];let {name:m=`arg${l}`,optional:p=n}=this.D[l]||{};return`${`${m}${p?"?":""}`}: ${h}`}); | ||
if(f){var k=a(f);e.unshift(`this: ${k}`)}if(g){k=a(g);let h="...args";try{h=`${this.args[this.args.length-1].name}`}catch(l){}e.push(`${h}: ${k}[]`)}e=e.join(", ");k=c?a(c):"?";e=`(${e}) => ${k}`;b&&(e="new "+e);return e}get static(){return this.g}get hasDefault(){return null!==this.default}b(a,{name:b,string:d,"boolean":c,opt:f,number:g,type:e,"default":k,closure:h,alias:l,aliases:n,example:m,"example-override":p="",noParams:q,"static":r,initial:t}){if(!b)throw Error("Property does not have a name."); | ||
this.name=b;a&&(this.description=J(a));a=I({A:g,C:d,l:c,type:e});q&&(this.v=q);h&&(this.f=h);this.type=a;void 0!==k?this.default=k:void 0!==t&&(this.default=t);if(f||void 0!==k)this.optional=!0;l&&(this.aliases=[l]);n&&(this.aliases=n.split(/\s*,\s*/));r&&(this.g=!0);m&&(this.examples=N(m,p))}get type(){return this.h||"*"}set type(a){this.h=a||null;this.u=this.f||this.h||"";if(!this.v)try{this.parsed=H(this.u),this.isParsedFunction&&!this.args&&(this.args=[])}catch(b){this.parsed=null}}get D(){var a= | ||
this.args;this.args&&this.args[0]&&"this"==this.args[0].name&&([,...a]=this.args);return a}get isParsedFunction(){return!!this.parsed&&"function"==this.parsed.name}};class Q extends P{constructor(...a){super(...a);this.isConstructor=this.async=!1;this.return=""}b(a,b){super.b(a,b);"constructor"==b.name&&(this.isConstructor=!0);this.async=b.async;this.return=b.return}};function ka(a,b,d,c){var f=G("prop",a).map(({content:h,props:l})=>{const n=new P;L(l,d);n.b(h,l);return n});a=G(["function","fn","static"],a).map(({content:h,props:l,tag:n})=>{n="static"==n;const {w:m,j:p}=M(h,b);h=new Q(p);const {F:q,o:r}=K(l,p,c);q.type=r;L(q,d);h.b(m,q);n&&(h.g=!0);return h});f=[...f,...a];const {m:g,B:e,n:k}=f.reduce((h,l)=>{l.isConstructor?h.m.push(l):l.static?h.B.push(l):h.n.push(l);return h},{m:[],B:[],n:[]});return{constructor:g[0]||null,properties:[...g,...e,...k]}};const S=(a,b,d={})=>{let c;if("object"==typeof b)c=b;else try{(c=H(b))||console.log("Could not parse %s",b)}catch(f){console.log("Could not parse %s",b),console.error(f.message)}return c?R(c,a,d):b},R=(a,b,d={})=>{if(""==a.name&&a.nullable)return"?";var {escapePipe:c=!0}=d;let f="";var g="";a.nullable?g="?":!1===a.nullable&&(g="!");if(a.function){f=f+g+(a.name+"(");const e=[];a.function.this&&(c="this: "+R(a.function.this,b,d),e.push(c));a.function.new&&(c="new: "+R(a.function.new,b,d),e.push(c)); | ||
h.return=n);l.function=h}else if("<"==a[b]||(h="."==a[b]&&"<"==d())){b++;h&&b++;l=e;for(h=[];">"!=a[b];){n=c();h.push(n);if(">"==a[b])break;if(","==a[b])b++;else throw Error("Expecting , between applications");}b++;l.application=h}for(;"."==a[b];){e.name+=".";b++;({name:l}=c(!1));if(!l)throw Error("Expected to see the name after .");e.name+=l}if("|"!=a[b]||!f)return e;for(g.push(e);"|"==a[b];)b++,e=c(!0,g),e.union!==g&&g.push(e);return{union:g}};return c()};function G(a){a=ba(a);return ca(a)};const da=path.dirname,ea=path.resolve;const H=({A:a,C:b,l:d,type:c})=>b?"string":a?"number":d?"boolean":c?c:"*",fa=a=>{const b=a.split(/\r?\n/).map(d=>{let c=Infinity;d.replace(/\S/,(f,g)=>{c=g});return c}).reduce((d,c)=>c<d?c:d,Infinity);return a.replace(new RegExp(`^ {${b}}`,"gm"),"")},I=a=>{a=a.trimRight();a=a.replace(/^\s*\r?\n( *\S)/,"$1");return fa(a)},J=(a,b,d=null)=>{const {async:c,"void":f,"return":g=f?"void":"",...e}=a;({args:a=""}=a);a||(a=b.map(({s:k,name:h})=>"this"==h?`${h}: ${k}`:h.startsWith("...")?`...${k}`:k).join(",")); | ||
b=g.replace(/\r?\n\s*/g," ");c&&b?b=`!Promise<${b}>`:c&&(b="!Promise");d=`function(${"constructor"==e.name?`new: ${d}, `:""}${a})`;b&&(d+=`: ${b}`);return{F:{...e,async:c,return:b},o:d}};function K(a,b){const d=a.example;d&&d.startsWith(".")&&b&&(a.example=ea(da(b),d))};function ha(a,b,{name:d,string:c,"boolean":f,opt:g,number:e,type:k},h){if(!d)throw Error("Argument does not have a name.");a.name=d;b&&(a.description=I(b));b=H({A:e,C:c,l:f,type:k});h&&(b=b.replace(new RegExp(`([!?])?${h}\\.`,"g"),"$1"));b.endsWith("=")&&(b=b.replace(/=$/,""),g=!0);a.type=b;g&&(a.optional=!0)}class ia{constructor(){this.name=null;this.type="";this.optional=!1;this.description=""}get s(){return this.optional?`${this.type}=`:this.type}} | ||
const L=(a,b)=>{let d=a.lastIndexOf("</arg>"),c=a;var f=[];-1!=d&&(d+=6,f=a.slice(0,d),c=a.slice(d),f=F("arg",f),f=f.map(({content:g,props:e})=>{const k=new ia;ha(k,g,e,b);return k}));return{w:c,j:f}};const ja=fs.readFileSync;class ka{constructor(){this.description=this.closureType=this.type=null;this.noExpand=this.spread=this.noToc=!1;this.link=null;this.properties=[];this.namespace=null;this.isRecord=this.isInterface=this.isConstructor=!1;this.args=this.superArgs=this.extends=null;this.examples=[]}toMarkdown(){}get import(){return!1}} | ||
class la{constructor(){this.default=this.description=null;this.isGetter=this.optional=!1;this.args=null;this.aliases=[];this.examples=[];this.parsed=null}toTypeScriptFunction(){}get type(){return"*"}get hasDefault(){return!1}get isParsedFunction(){return!1}get static(){return!1}};const ma=a=>{const b=a.replace(/^\s*\r?\n/gm,"").split(B).reduce((d,c)=>{[{length:c=0}={}]=/^\s*/.exec(c)||[];return c<d?c:d},Infinity);return a.replace(new RegExp(`^ {${b}}`,"gm"),"")}; | ||
function M(a,b=""){const d=b.split(/\s*,\s*/);return a.split(/\s*,\s*/).map(c=>{let f=c=ja(c,"utf8");if(c=/\/\* start example \*\/\r?\n([\s\S]+?)\r?\n\s*\/\* end example \*\//.exec(c))[,c]=c,f=ma(c);d.forEach(g=>{const [e,k]=g.split(/\s*=>\s*/);f=f.replace(`'${e}'`,`'${k}'`);f=f.replace(`"${e}"`,`"${k}"`)});return f=f.replace(/@/g,"\uff20")})}function N(a,b,d=new RegExp(`([!?])?${b}\\.`,"g")){b&&(a.f&&(a.f=a.f.replace(d,"$1")),a.type=a.type.replace(d,"$1"))} | ||
class O extends la{constructor(a=null){super();this.h=this.name=null;this.u="";this.default=this.f=null;this.v=!1;this.parsed=null;this.args=a;this.g=!1}toTypeScriptFunction(a){if(!this.parsed)throw Error("The property was not parsed.");let {function:{new:b,args:d,return:c,this:f,variableArgs:g}}=this.parsed;b&&(c=b);var e=d.map(h=>a(h)).map((h,l)=>{const {optional:n}=d[l];let {name:m=`arg${l}`,optional:p=n}=this.D[l]||{};return`${`${m}${p?"?":""}`}: ${h}`});if(f){var k=a(f);e.unshift(`this: ${k}`)}if(g){k= | ||
a(g);let h="...args";try{h=`${this.args[this.args.length-1].name}`}catch(l){}e.push(`${h}: ${k}[]`)}e=e.join(", ");k=c?a(c):"?";e=`(${e}) => ${k}`;b&&(e="new "+e);return e}get static(){return this.g}get hasDefault(){return null!==this.default}b(a,{name:b,string:d,"boolean":c,opt:f,number:g,type:e,"default":k,closure:h,alias:l,aliases:n,example:m,"example-override":p="",noParams:q,"static":r,initial:t}){if(!b)throw Error("Property does not have a name.");this.name=b;a&&(this.description=I(a));a=H({A:g, | ||
C:d,l:c,type:e});q&&(this.v=q);h&&(this.f=h);this.type=a;void 0!==k?this.default=k:void 0!==t&&(this.default=t);if(f||void 0!==k)this.optional=!0;l&&(this.aliases=[l]);n&&(this.aliases=n.split(/\s*,\s*/));r&&(this.g=!0);m&&(this.examples=M(m,p))}get type(){return this.h||"*"}set type(a){this.h=a||null;this.u=this.f||this.h||"";if(!this.v)try{this.parsed=G(this.u),this.isParsedFunction&&!this.args&&(this.args=[])}catch(b){this.parsed=null}}get D(){var a=this.args;this.args&&this.args[0]&&"this"==this.args[0].name&& | ||
([,...a]=this.args);return a}get isParsedFunction(){return!!this.parsed&&"function"==this.parsed.name}};class P extends O{constructor(...a){super(...a);this.isConstructor=this.async=!1;this.return=""}b(a,b){super.b(a,b);"constructor"==b.name&&(this.isConstructor=!0);this.async=b.async;this.return=b.return}};function na(a,b,d,c){var f=F(["prop","getter"],a).map(({content:h,props:l,tag:n})=>{const m=new O;"getter"==n&&(m.isGetter=!0);K(l,d);m.b(h,l);return m});a=F(["function","fn","static"],a).map(({content:h,props:l,tag:n})=>{n="static"==n;const {w:m,j:p}=L(h,b);h=new P(p);const {F:q,o:r}=J(l,p,c);q.type=r;K(q,d);h.b(m,q);n&&(h.g=!0);return h});f=[...f,...a];const {m:g,B:e,n:k}=f.reduce((h,l)=>{l.isConstructor?h.m.push(l):l.static?h.B.push(l):h.n.push(l);return h},{m:[],B:[],n:[]});f=g[0]||null;a=[...g, | ||
...e,...k];return{constructor:f,properties:a}};const S=(a,b,d={})=>{let c;if("object"==typeof b)c=b;else try{(c=G(b))||console.log("Could not parse %s",b)}catch(f){console.log("Could not parse %s",b),console.error(f.message)}return c?R(c,a,d):b},R=(a,b,d={})=>{if(""==a.name&&a.nullable)return"?";var {escapePipe:c=!0}=d;let f="";var g="";a.nullable?g="?":!1===a.nullable&&(g="!");if(a.function){f=f+g+(a.name+"(");const e=[];a.function.this&&(c="this: "+R(a.function.this,b,d),e.push(c));a.function.new&&(c="new: "+R(a.function.new,b,d),e.push(c)); | ||
a.function.args.forEach(k=>{let h=R(k,b,d);k.optional&&(h+="=");e.push(h)});a.function.variableArgs&&(c="..."+R(a.function.variableArgs,b,d),e.push(c));c=e.join(", ");f+=c+")";a.function.return&&(f+=": "+R(a.function.return,b,d))}else a.record?(f+="{ ",c=Object.keys(a.record).map(e=>{var k=a.record[e];if(!k)return e;k=R(k,b,d);return`${e}: ${k}`}),f+=c.join(", "),f+=" }"):a.application?(f+=T(a.name,b,g,d)+"<",c=a.application.map(e=>R(e,b,d)),f+=c.join(", "),f+=">"):a.union?(f=f+g+"(",g=a.union.map(e=> | ||
R(e,b,d)),f+=g.join(c?" \\| ":" | "),f+=")"):f+=T("any"==a.name?"*":a.name,b,g,d);return f},T=(a,b,d="",c={})=>{const {flatten:f=!1,nameProcess:g,link:e=({link:l})=>`#${l}`}=c;c=la(b,a);d=`${d}${a}`;if(!c)return d;let {link:k,type:{description:h}}=c;f&&((b=b.find(({fullName:l})=>l==a))&&b.link&&(k=b.link),!h&&b.description&&(h=b.description),"function"==typeof f&&f(a));c.link==k&&(k=e(c));b=g?g(d):d;return h?`<a href="${k}" title="${h.replace(/"/g,""")}">${b}</a>`:`[${b}](${k})`},la=(a,b)=>{a= | ||
a.filter(({fullName:c})=>c==b);if(a.length){var d=a.find(({import:c})=>c||!1);a=a.find(({import:c})=>!c)||d;return{link:`${"type"}-${a.fullName.replace(/<\/?code>/g,"").replace(/<\/?strong>/g,"").replace(/<br\/>/g,"").replace(/ /g,"").replace(/[^\w-\d ]/g,"").toLowerCase().replace(/[, ]/g,"-")}`,type:a}}};function ma(a,b=[],d=[],c={}){const {narrow:f=!1,preprocessDesc:g}=c;if(!b.length)return"";const e=a.isConstructor||a.isInterface,k=b.some(({hasDefault:m})=>m),h={escapePipe:!f,...c};let l;const n=m=>S(d,m,{...h,nameProcess:c.nameProcess?p=>c.nameProcess(p,l):void 0});a=b.map((m,p)=>{l=0<(p+1)%2;p=m.args&&m.isParsedFunction?m.toTypeScriptFunction(n):n(m.parsed||m.type);const q=e||m.optional?m.name:`${m.name}*`,r=m.hasDefault?`\`${m.default}\``:"-",t=g?g(m.description):m.description;return{prop:m, | ||
typeName:p,name:q,de:na(t,!f),d:r,G:l}});if(f)return{props:a,anyHaveDefault:k,constr:e};a=a.map(({name:m,typeName:p,de:q,d:r,prop:t})=>[t.optional?m:`__${m}__`,`<em>${p}</em>`,q,...k?[r]:[]]);b=["Name",...f?["Type & Description"]:["Type","Description"],...k?[e?"Initial":"Default"]:[]];return["","","```table",JSON.stringify([b,...a],null,2).replace(/\n/g,B),"```"].join(B)}const na=(a="",b=!0)=>{null===a&&(a="");b&&(a=a.replace(/\|/g,"\\|"));return a.replace(/</g,"<").replace(/>/g,">")};const oa=(a,b,d={})=>{function c(f){f.replace(/^!?/,"");return`\`${f}\``}return a.split(/,\s*/).map(f=>S(b,f,{flatten:!0,...d,nameProcess:d.nameProcess?g=>{g=d.nameProcess(g);return/[_*~>]/.test(g)?`<code>${g}</code>`:c(g)}:c})).join(", ")};class U{constructor(){this.name="";this.description=this.closureType=this.type=null;this.noExpand=this.spread=this.noToc=!1;this.link=null;this.properties=[];this.namespace=null;this.isRecord=this.isInterface=this.isConstructor=!1;this.args=this.extends=null;this.examples=[];this.g=null}get import(){return!1}b(a,{name:b,type:d,desc:c,noToc:f,spread:g,noExpand:e,link:k,closure:h,constructor:l,"extends":n,"interface":m,record:p,example:q,"example-override":r},t,z=null){if(!b)throw Error("Type does not have a name."); | ||
this.name=b;d&&(this.type=d);h?this.closureType=h:this.closureType=this.type;c&&(this.description=J(c));this.noToc=!!f;this.spread=!!g;this.noExpand=!!e;k&&(this.link=k);!0===l&&(this.isConstructor=l);!0===m&&(this.isInterface=m);!0===p&&(this.isRecord=p);n&&(this.extends=n);t&&(this.namespace=t);if(a){const {properties:u,constructor:v}=ka(a,z,this.g,this.fullName);v&&(this.args=v.args);this.properties=u}q&&(a={example:q},L(a,this.g),this.examples=N(a.example,r))}h(a,b=new RegExp(`([!?])?${a}\\.`, | ||
"g")){this.type&&(this.type=this.type.replace(b,"$1"));this.extends&&(this.extends=this.extends.replace(b,"$1"));return b}get tag(){return this.isConstructor?"constructor":this.isInterface?"interface":this.isRecord?"record":""}get ns(){return this.namespace?`${this.namespace}.`:""}get fullName(){return`${this.ns}${this.name}`}toMarkdown(a=[],b={}){const {flatten:d,details:c=[]}=b,f=c.includes(this.name);var g=this.type?`\`${this.type}\``:"",e=g;this.link?e=`[${g}](${this.link})`:!this.import&&this.type&& | ||
(e=S(a,this.type,b),g=e!=this.type,e=V(e,g));g=V(this.fullName);g=this.import?`[${g}](l-type)`:this.noToc?`[${g}](l-type)`:`[${g}](t-type)`;const k=this.description?`: ${this.description}`:"";e=e?`${e} `:"";let h=/_/.test(g);if(this.extends){const l=oa(this.extends,a,b),n=` extends ${l}`;h=h||/_/.test(l);e=(h?e+"<strong>":e+"__")+(g+n);"function"==typeof d&&d(this.extends)}else e=(h?e+"<strong>":e+"__")+g;e=(h?e+"</strong>":e+"__")+k;a=ma(this,this.properties,a,b);return{LINE:e,table:a,displayInDetails:f}}} | ||
const V=(a,b=!1)=>`${b?"<code>":"`"}${a}${b?"</code>":"`"}`;class W extends U{constructor(){super();this.f=null;this.async=!1}get isMethod(){return!0}b(a,{async:b,"return":d,"void":c,...f},...g){this.description=J(a);super.b("",f,...g);d&&(this.f=d.replace(/\r?\n\s*/g," "));c&&(this.f="void");b&&(this.async=!0)}get return(){return this.f||"void"}h(a){a=super.h(a);this.f&&(this.f=this.f.replace(a,"$1"))}};class pa extends U{constructor(){super();this.from=""}get import(){return!0}b(a,{from:b,name:d,...c},f,g){if(!b)throw Error("From attribute of import is not given.");this.from=b;this.description=J(a);super.b("",{...c,noToc:!0,name:d,type:`import('${b}').${d}`},f!=g?f:null)}};const qa=(a,b)=>{const d=new RegExp(`([!?])?${a}\\.`,"g");b.properties.forEach(c=>{O(c,a,d)});b.h(a)},X=(a,b)=>{var {args:d=[]}=a,c=d.map(({s:g})=>g).join(", ");let f=`new: ${a.fullName}`;c.length&&(f=`${f}, `);c=`function(${f}${c})`;d=new Q(d);d.isConstructor=!0;d.b("Constructor method.",{type:c,name:"constructor"});d.examples=a.examples;O(d,b);a.properties.unshift(d)},Y=(a,b,d,c,f=!1,g=null)=>{const e=f?new W:new U;e.g=g;g=a.search(/<(prop|function|fn|static) /);let k="",h=a;1!=g&&(k=a.slice(0, | ||
g),h=a.slice(g));const {j:l,w:n}=M(k,c);e.b(f?n:h,b,d,c);({o:a}=K(b,l));f&&(e.closureType=a);e.args||(e.args=l);return e},Z=({content:a,props:b,ns:d,i:c,isMethod:f=!1,location:g=null})=>{const e=[],{alias:k,aliases:h,...l}=b;b=Y(a,b,d,c,f,g);e.push(b);(k?[k]:h?h.split(/, */):[]).forEach(n=>{n=Y(a,{...l,name:n},d,c,f,g);n.description=`${n.description}${n.description?" ":""}Alias of \`${l.name}\`.`;e.push(n)});return e};/* | ||
R(e,b,d)),f+=g.join(c?" \\| ":" | "),f+=")"):f+=T("any"==a.name?"*":a.name,b,g,d);return f},T=(a,b,d="",c={})=>{const {flatten:f=!1,nameProcess:g,link:e=({link:l})=>`#${l}`}=c;c=oa(b,a);d=`${d}${a}`;if(!c)return d;let {link:k,type:{description:h}}=c;f&&((b=b.find(({fullName:l})=>l==a))&&b.link&&(k=b.link),!h&&b.description&&(h=b.description),"function"==typeof f&&f(a));c.link==k&&(k=e(c));b=g?g(d):d;return h?`<a href="${k}" title="${h.replace(/"/g,""")}">${b}</a>`:`[${b}](${k})`},oa=(a,b)=>{a= | ||
a.filter(({fullName:c})=>c==b);if(a.length){var d=a.find(({import:c})=>c||!1);a=a.find(({import:c})=>!c)||d;return{link:`${"type"}-${a.fullName.replace(/<\/?code>/g,"").replace(/<\/?strong>/g,"").replace(/<br\/>/g,"").replace(/ /g,"").replace(/[^\w-\d ]/g,"").toLowerCase().replace(/[, ]/g,"-")}`,type:a}}};function pa(a,b=[],d=[],c={}){const {narrow:f=!1,preprocessDesc:g}=c;if(!b.length)return"";const e=a.isConstructor||a.isInterface,k=b.some(({hasDefault:m})=>m),h={escapePipe:!f,...c};let l;const n=m=>S(d,m,{...h,nameProcess:c.nameProcess?p=>c.nameProcess(p,l):void 0});a=b.map((m,p)=>{l=0<(p+1)%2;p=m.args&&m.isParsedFunction?m.toTypeScriptFunction(n):n(m.parsed||m.type);const q=e||m.optional?m.name:`${m.name}*`,r=m.hasDefault?`\`${m.default}\``:"-",t=g?g(m.description):m.description;return{prop:m, | ||
typeName:p,name:q,de:qa(t,!f),d:r,G:l}});if(f)return{props:a,anyHaveDefault:k,constr:e};a=a.map(({name:m,typeName:p,de:q,d:r,prop:t})=>[t.optional?m:`__${m}__`,`<em>${p}</em>`,q,...k?[r]:[]]);b=["Name",...f?["Type & Description"]:["Type","Description"],...k?[e?"Initial":"Default"]:[]];return["","","```table",JSON.stringify([b,...a],null,2).replace(/\n/g,B),"```"].join(B)}const qa=(a="",b=!0)=>{null===a&&(a="");b&&(a=a.replace(/\|/g,"\\|"));return a.replace(/</g,"<").replace(/>/g,">")};const ra=(a,b,d={})=>{function c(f){f.replace(/^!?/,"");return`\`${f}\``}return a.split(/,\s*/).map(f=>S(b,f,{flatten:!0,...d,nameProcess:d.nameProcess?g=>{g=d.nameProcess(g);return/[_*~>]/.test(g)?`<code>${g}</code>`:c(g)}:c})).join(", ")};class U extends ka{constructor(){super();this.g=this.link=this.closureType=null;this.properties=[]}get import(){return!1}b(a,{name:b,type:d,desc:c,noToc:f,spread:g,noExpand:e,link:k,closure:h,constructor:l,"extends":n,"interface":m,record:p,example:q,"example-override":r,"super-args":t},x,u=null){if(!b)throw Error("Type does not have a name.");this.name=b;d&&(this.type=d);h?this.closureType=h:this.closureType=this.type;c&&(this.description=I(c));this.noToc=!!f;this.spread=!!g;this.noExpand=!!e;k&& | ||
(this.link=k);!0===l&&(this.isConstructor=l);!0===m&&(this.isInterface=m);!0===p&&(this.isRecord=p);n&&(this.extends=n);x&&(this.namespace=x);if(a){const {properties:w,constructor:Q}=na(a,u,this.g,this.fullName);Q&&(this.args=Q.args);this.properties=w}q&&(a={example:q},K(a,this.g),this.examples=M(a.example,r));t&&(this.superArgs=t)}h(a,b=new RegExp(`([!?])?${a}\\.`,"g")){this.type&&(this.type=this.type.replace(b,"$1"));this.extends&&(this.extends=this.extends.replace(b,"$1"));return b}get tag(){return this.isConstructor? | ||
"constructor":this.isInterface?"interface":this.isRecord?"record":""}get ns(){return this.namespace?`${this.namespace}.`:""}get fullName(){return`${this.ns}${this.name}`}toMarkdown(a=[],b={}){const {flatten:d,details:c=[]}=b,f=c.includes(this.name);var g=this.type?`\`${this.type}\``:"",e=g;this.link?e=`[${g}](${this.link})`:!this.import&&this.type&&(e=S(a,this.type,b),g=e!=this.type,e=V(e,g));g=V(this.fullName);g=this.import?`[${g}](l-type)`:this.noToc?`[${g}](l-type)`:`[${g}](t-type)`;const k=this.description? | ||
`: ${this.description}`:"";e=e?`${e} `:"";let h=/_/.test(g);if(this.extends){const l=ra(this.extends,a,b),n=` extends ${l}`;h=h||/_/.test(l);e=(h?e+"<strong>":e+"__")+(g+n);"function"==typeof d&&d(this.extends)}else e=(h?e+"<strong>":e+"__")+g;e=(h?e+"</strong>":e+"__")+k;a=pa(this,this.properties,a,b);return{LINE:e,table:a,displayInDetails:f}}}const V=(a,b=!1)=>`${b?"<code>":"`"}${a}${b?"</code>":"`"}`;class W extends U{constructor(){super();this.f=null;this.async=!1}get isMethod(){return!0}b(a,{async:b,"return":d,"void":c,...f},...g){this.description=I(a);super.b("",f,...g);d&&(this.f=d.replace(/\r?\n\s*/g," "));c&&(this.f="void");b&&(this.async=!0)}get return(){return this.f||"void"}h(a){a=super.h(a);this.f&&(this.f=this.f.replace(a,"$1"))}};class sa extends U{constructor(){super();this.from=""}get import(){return!0}b(a,{from:b,name:d,...c},f,g){if(!b)throw Error("From attribute of import is not given.");this.from=b;this.description=I(a);super.b("",{...c,noToc:!0,name:d,type:`import('${b}').${d}`},f!=g?f:null)}};const ta=(a,b)=>{const d=new RegExp(`([!?])?${a}\\.`,"g");b.properties.forEach(c=>{N(c,a,d)});b.h(a)},X=(a,b)=>{var {args:d=[]}=a,c=d.map(({s:g})=>g).join(", ");let f=`new: ${a.fullName}`;c.length&&(f=`${f}, `);c=`function(${f}${c})`;d=new P(d);d.isConstructor=!0;d.b("Constructor method.",{type:c,name:"constructor"});d.examples=a.examples;N(d,b);a.properties.unshift(d)},Y=(a,b,d,c,f=!1,g=null)=>{const e=f?new W:new U;e.g=g;g=a.search(/<(prop|function|fn|static|getter) /);let k="",h=a;1!=g&&(k=a.slice(0, | ||
g),h=a.slice(g));const {j:l,w:n}=L(k,c);e.b(f?n:h,b,d,c);({o:a}=J(b,l));f&&(e.closureType=a);e.args||(e.args=l);return e},Z=({content:a,props:b,ns:d,i:c,isMethod:f=!1,location:g=null})=>{const e=[],{alias:k,aliases:h,...l}=b;b=Y(a,b,d,c,f,g);e.push(b);(k?[k]:h?h.split(/, */):[]).forEach(n=>{n=Y(a,{...l,name:n},d,c,f,g);n.description=`${n.description}${n.description?" ":""}Alias of \`${l.name}\`.`;e.push(n)});return e};/* | ||
@@ -48,4 +49,4 @@ Typal: keep types information in XML files to embed as typedefs, | ||
*/ | ||
module.exports={_Type:U,_Property:P,_Method:W,_parseFile:(a,b,d=null)=>{a=G("types",a);if(!a.length)throw Error("XML file should contain root types element.");const [{content:c,props:{namespace:f,ns:g=f}}]=a,e=b==g?void 0:g;a=G(["embed"],c).map(({props:l})=>l);const k=[],h=G("type interface constructor method import record".split(" "),c).reduce((l,{content:n,props:m,tag:p})=>{"record"==p&&(p="type",m.record=!0);const {alias:q,aliases:r,...t}=m;d&&L(t,d);var z=q?[q]:r?r.split(/, */):[];switch(p){case "type":p= | ||
new U;d&&(p.g=d);p.b(n,m,e,b);l.push(p);z.forEach(u=>{const v=new U;d&&(v.g=d);v.b(n,{...t,name:u},e,b);l.push(v)});break;case "interface":m=Z({content:n,props:m,ns:e,i:b,location:d});m.forEach(u=>{u.properties.some(({isConstructor:v})=>v)||X(u,b);u.isInterface=!0});l.push(...m);break;case "constructor":m=Z({content:n,props:m,ns:e,i:b,location:d});m.forEach(u=>{u.properties.some(({isConstructor:v})=>v)||X(u,b);u.isConstructor=!0});l.push(...m);break;case "method":m=Z({content:n,props:m,ns:e,i:b,isMethod:!0, | ||
location:d});l.push(...m);break;case "import":z=new pa,z.b(n,m,m.ns||m.from,b),k.push(z)}return l},[]);b&&h.forEach(l=>qa(b,l));return{namespace:g,types:h,imports:k,embeds:a}},_getLinks:S}; | ||
module.exports={_Type:U,_Property:O,_Method:W,_parseFile:(a,b,d=null)=>{a=F("types",a);if(!a.length)return console.log("Skipping XML file %s which does not contain root `types` element.",d),{types:[],imports:[]};const [{content:c,props:{namespace:f,ns:g=f}}]=a,e=b==g?void 0:g;a=F(["embed"],c).map(({props:l})=>l);const k=[],h=F("type interface constructor method import record".split(" "),c).reduce((l,{content:n,props:m,tag:p})=>{"record"==p&&(p="type",m.record=!0);const {alias:q,aliases:r,...t}=m; | ||
d&&K(t,d);var x=q?[q]:r?r.split(/, */):[];switch(p){case "type":p=new U;d&&(p.g=d);p.b(n,m,e,b);l.push(p);x.forEach(u=>{const w=new U;d&&(w.g=d);w.b(n,{...t,name:u},e,b);l.push(w)});break;case "interface":m=Z({content:n,props:m,ns:e,i:b,location:d});m.forEach(u=>{u.properties.some(({isConstructor:w})=>w)||X(u,b);u.isInterface=!0});l.push(...m);break;case "constructor":m=Z({content:n,props:m,ns:e,i:b,location:d});m.forEach(u=>{u.properties.some(({isConstructor:w})=>w)||X(u,b);u.isConstructor=!0}); | ||
l.push(...m);break;case "method":m=Z({content:n,props:m,ns:e,i:b,isMethod:!0,location:d});l.push(...m);break;case "import":x=new sa,x.b(n,m,m.ns||m.from,b),k.push(x)}return l},[]);b&&h.forEach(l=>ta(b,l));return{namespace:g,types:h,imports:k,embeds:a}},_getLinks:S}; |
{ | ||
"name": "typal", | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"description": "Organises TypeDefs By Placing Them Into Types.Xml File To Be Embedded Into Source Code Compatible With VSCode And Google Closure Compiler, Generates Externs And Allows To Place Documentation In README Markdown.", | ||
@@ -5,0 +5,0 @@ "main": "compile/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
152057
483
7
1