@jam-comments/server-utilities 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,31 @@
1
+ (function(b,C){typeof exports=="object"&&typeof module<"u"?C(exports):typeof define=="function"&&define.amd?define(["exports"],C):(b=typeof globalThis<"u"?globalThis:b||self,C(b.JamComments={}))})(this,function(b){"use strict";var C=Object.defineProperty,ge=Object.defineProperties,be=Object.getOwnPropertyDescriptors,L=Object.getOwnPropertySymbols,ye=Object.prototype.hasOwnProperty,ve=Object.prototype.propertyIsEnumerable,T=(e,t,n)=>t in e?C(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,we=(e,t)=>{for(var n in t||(t={}))ye.call(t,n)&&T(e,n,t[n]);if(L)for(var n of L(t))ve.call(t,n)&&T(e,n,t[n]);return e},ke=(e,t)=>ge(e,be(t)),z={exports:{}},Ce={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50]};const O=Ce,G={};for(const e of Object.keys(O))G[O[e]]=e;const u={rgb:{channels:3,labels:"rgb"},hsl:{channels:3,labels:"hsl"},hsv:{channels:3,labels:"hsv"},hwb:{channels:3,labels:"hwb"},cmyk:{channels:4,labels:"cmyk"},xyz:{channels:3,labels:"xyz"},lab:{channels:3,labels:"lab"},lch:{channels:3,labels:"lch"},hex:{channels:1,labels:["hex"]},keyword:{channels:1,labels:["keyword"]},ansi16:{channels:1,labels:["ansi16"]},ansi256:{channels:1,labels:["ansi256"]},hcg:{channels:3,labels:["h","c","g"]},apple:{channels:3,labels:["r16","g16","b16"]},gray:{channels:1,labels:["gray"]}};var V=u;for(const e of Object.keys(u)){if(!("channels"in u[e]))throw new Error("missing channels property: "+e);if(!("labels"in u[e]))throw new Error("missing channel labels property: "+e);if(u[e].labels.length!==u[e].channels)throw new Error("channel and label counts mismatch: "+e);const{channels:t,labels:n}=u[e];delete u[e].channels,delete u[e].labels,Object.defineProperty(u[e],"channels",{value:t}),Object.defineProperty(u[e],"labels",{value:n})}u.rgb.hsl=function(e){const t=e[0]/255,n=e[1]/255,r=e[2]/255,o=Math.min(t,n,r),s=Math.max(t,n,r),i=s-o;let l,c;s===o?l=0:t===s?l=(n-r)/i:n===s?l=2+(r-t)/i:r===s&&(l=4+(t-n)/i),l=Math.min(l*60,360),l<0&&(l+=360);const h=(o+s)/2;return s===o?c=0:h<=.5?c=i/(s+o):c=i/(2-s-o),[l,c*100,h*100]},u.rgb.hsv=function(e){let t,n,r,o,s;const i=e[0]/255,l=e[1]/255,c=e[2]/255,h=Math.max(i,l,c),f=h-Math.min(i,l,c),a=function(p){return(h-p)/6/f+1/2};return f===0?(o=0,s=0):(s=f/h,t=a(i),n=a(l),r=a(c),i===h?o=r-n:l===h?o=1/3+t-r:c===h&&(o=2/3+n-t),o<0?o+=1:o>1&&(o-=1)),[o*360,s*100,h*100]},u.rgb.hwb=function(e){const t=e[0],n=e[1];let r=e[2];const o=u.rgb.hsl(e)[0],s=1/255*Math.min(t,Math.min(n,r));return r=1-1/255*Math.max(t,Math.max(n,r)),[o,s*100,r*100]},u.rgb.cmyk=function(e){const t=e[0]/255,n=e[1]/255,r=e[2]/255,o=Math.min(1-t,1-n,1-r),s=(1-t-o)/(1-o)||0,i=(1-n-o)/(1-o)||0,l=(1-r-o)/(1-o)||0;return[s*100,i*100,l*100,o*100]};function Oe(e,t){return(e[0]-t[0])**2+(e[1]-t[1])**2+(e[2]-t[2])**2}u.rgb.keyword=function(e){const t=G[e];if(t)return t;let n=1/0,r;for(const o of Object.keys(O)){const s=O[o],i=Oe(e,s);i<n&&(n=i,r=o)}return r},u.keyword.rgb=function(e){return O[e]},u.rgb.xyz=function(e){let t=e[0]/255,n=e[1]/255,r=e[2]/255;t=t>.04045?((t+.055)/1.055)**2.4:t/12.92,n=n>.04045?((n+.055)/1.055)**2.4:n/12.92,r=r>.04045?((r+.055)/1.055)**2.4:r/12.92;const o=t*.4124+n*.3576+r*.1805,s=t*.2126+n*.7152+r*.0722,i=t*.0193+n*.1192+r*.9505;return[o*100,s*100,i*100]},u.rgb.lab=function(e){const t=u.rgb.xyz(e);let n=t[0],r=t[1],o=t[2];n/=95.047,r/=100,o/=108.883,n=n>.008856?n**(1/3):7.787*n+16/116,r=r>.008856?r**(1/3):7.787*r+16/116,o=o>.008856?o**(1/3):7.787*o+16/116;const s=116*r-16,i=500*(n-r),l=200*(r-o);return[s,i,l]},u.hsl.rgb=function(e){const t=e[0]/360,n=e[1]/100,r=e[2]/100;let o,s,i;if(n===0)return i=r*255,[i,i,i];r<.5?o=r*(1+n):o=r+n-r*n;const l=2*r-o,c=[0,0,0];for(let h=0;h<3;h++)s=t+1/3*-(h-1),s<0&&s++,s>1&&s--,6*s<1?i=l+(o-l)*6*s:2*s<1?i=o:3*s<2?i=l+(o-l)*(2/3-s)*6:i=l,c[h]=i*255;return c},u.hsl.hsv=function(e){const t=e[0];let n=e[1]/100,r=e[2]/100,o=n;const s=Math.max(r,.01);r*=2,n*=r<=1?r:2-r,o*=s<=1?s:2-s;const i=(r+n)/2,l=r===0?2*o/(s+o):2*n/(r+n);return[t,l*100,i*100]},u.hsv.rgb=function(e){const t=e[0]/60,n=e[1]/100;let r=e[2]/100;const o=Math.floor(t)%6,s=t-Math.floor(t),i=255*r*(1-n),l=255*r*(1-n*s),c=255*r*(1-n*(1-s));switch(r*=255,o){case 0:return[r,c,i];case 1:return[l,r,i];case 2:return[i,r,c];case 3:return[i,l,r];case 4:return[c,i,r];case 5:return[r,i,l]}},u.hsv.hsl=function(e){const t=e[0],n=e[1]/100,r=e[2]/100,o=Math.max(r,.01);let s,i;i=(2-n)*r;const l=(2-n)*o;return s=n*o,s/=l<=1?l:2-l,s=s||0,i/=2,[t,s*100,i*100]},u.hwb.rgb=function(e){const t=e[0]/360;let n=e[1]/100,r=e[2]/100;const o=n+r;let s;o>1&&(n/=o,r/=o);const i=Math.floor(6*t),l=1-r;s=6*t-i,(i&1)!==0&&(s=1-s);const c=n+s*(l-n);let h,f,a;switch(i){default:case 6:case 0:h=l,f=c,a=n;break;case 1:h=c,f=l,a=n;break;case 2:h=n,f=l,a=c;break;case 3:h=n,f=c,a=l;break;case 4:h=c,f=n,a=l;break;case 5:h=l,f=n,a=c;break}return[h*255,f*255,a*255]},u.cmyk.rgb=function(e){const t=e[0]/100,n=e[1]/100,r=e[2]/100,o=e[3]/100,s=1-Math.min(1,t*(1-o)+o),i=1-Math.min(1,n*(1-o)+o),l=1-Math.min(1,r*(1-o)+o);return[s*255,i*255,l*255]},u.xyz.rgb=function(e){const t=e[0]/100,n=e[1]/100,r=e[2]/100;let o,s,i;return o=t*3.2406+n*-1.5372+r*-.4986,s=t*-.9689+n*1.8758+r*.0415,i=t*.0557+n*-.204+r*1.057,o=o>.0031308?1.055*o**(1/2.4)-.055:o*12.92,s=s>.0031308?1.055*s**(1/2.4)-.055:s*12.92,i=i>.0031308?1.055*i**(1/2.4)-.055:i*12.92,o=Math.min(Math.max(0,o),1),s=Math.min(Math.max(0,s),1),i=Math.min(Math.max(0,i),1),[o*255,s*255,i*255]},u.xyz.lab=function(e){let t=e[0],n=e[1],r=e[2];t/=95.047,n/=100,r/=108.883,t=t>.008856?t**(1/3):7.787*t+16/116,n=n>.008856?n**(1/3):7.787*n+16/116,r=r>.008856?r**(1/3):7.787*r+16/116;const o=116*n-16,s=500*(t-n),i=200*(n-r);return[o,s,i]},u.lab.xyz=function(e){const t=e[0],n=e[1],r=e[2];let o,s,i;s=(t+16)/116,o=n/500+s,i=s-r/200;const l=s**3,c=o**3,h=i**3;return s=l>.008856?l:(s-16/116)/7.787,o=c>.008856?c:(o-16/116)/7.787,i=h>.008856?h:(i-16/116)/7.787,o*=95.047,s*=100,i*=108.883,[o,s,i]},u.lab.lch=function(e){const t=e[0],n=e[1],r=e[2];let o;o=Math.atan2(r,n)*360/2/Math.PI,o<0&&(o+=360);const i=Math.sqrt(n*n+r*r);return[t,i,o]},u.lch.lab=function(e){const t=e[0],n=e[1],o=e[2]/360*2*Math.PI,s=n*Math.cos(o),i=n*Math.sin(o);return[t,s,i]},u.rgb.ansi16=function(e,t=null){const[n,r,o]=e;let s=t===null?u.rgb.hsv(e)[2]:t;if(s=Math.round(s/50),s===0)return 30;let i=30+(Math.round(o/255)<<2|Math.round(r/255)<<1|Math.round(n/255));return s===2&&(i+=60),i},u.hsv.ansi16=function(e){return u.rgb.ansi16(u.hsv.rgb(e),e[2])},u.rgb.ansi256=function(e){const t=e[0],n=e[1],r=e[2];return t===n&&n===r?t<8?16:t>248?231:Math.round((t-8)/247*24)+232:16+36*Math.round(t/255*5)+6*Math.round(n/255*5)+Math.round(r/255*5)},u.ansi16.rgb=function(e){let t=e%10;if(t===0||t===7)return e>50&&(t+=3.5),t=t/10.5*255,[t,t,t];const n=(~~(e>50)+1)*.5,r=(t&1)*n*255,o=(t>>1&1)*n*255,s=(t>>2&1)*n*255;return[r,o,s]},u.ansi256.rgb=function(e){if(e>=232){const s=(e-232)*10+8;return[s,s,s]}e-=16;let t;const n=Math.floor(e/36)/5*255,r=Math.floor((t=e%36)/6)/5*255,o=t%6/5*255;return[n,r,o]},u.rgb.hex=function(e){const n=(((Math.round(e[0])&255)<<16)+((Math.round(e[1])&255)<<8)+(Math.round(e[2])&255)).toString(16).toUpperCase();return"000000".substring(n.length)+n},u.hex.rgb=function(e){const t=e.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);if(!t)return[0,0,0];let n=t[0];t[0].length===3&&(n=n.split("").map(l=>l+l).join(""));const r=parseInt(n,16),o=r>>16&255,s=r>>8&255,i=r&255;return[o,s,i]},u.rgb.hcg=function(e){const t=e[0]/255,n=e[1]/255,r=e[2]/255,o=Math.max(Math.max(t,n),r),s=Math.min(Math.min(t,n),r),i=o-s;let l,c;return i<1?l=s/(1-i):l=0,i<=0?c=0:o===t?c=(n-r)/i%6:o===n?c=2+(r-t)/i:c=4+(t-n)/i,c/=6,c%=1,[c*360,i*100,l*100]},u.hsl.hcg=function(e){const t=e[1]/100,n=e[2]/100,r=n<.5?2*t*n:2*t*(1-n);let o=0;return r<1&&(o=(n-.5*r)/(1-r)),[e[0],r*100,o*100]},u.hsv.hcg=function(e){const t=e[1]/100,n=e[2]/100,r=t*n;let o=0;return r<1&&(o=(n-r)/(1-r)),[e[0],r*100,o*100]},u.hcg.rgb=function(e){const t=e[0]/360,n=e[1]/100,r=e[2]/100;if(n===0)return[r*255,r*255,r*255];const o=[0,0,0],s=t%1*6,i=s%1,l=1-i;let c=0;switch(Math.floor(s)){case 0:o[0]=1,o[1]=i,o[2]=0;break;case 1:o[0]=l,o[1]=1,o[2]=0;break;case 2:o[0]=0,o[1]=1,o[2]=i;break;case 3:o[0]=0,o[1]=l,o[2]=1;break;case 4:o[0]=i,o[1]=0,o[2]=1;break;default:o[0]=1,o[1]=0,o[2]=l}return c=(1-n)*r,[(n*o[0]+c)*255,(n*o[1]+c)*255,(n*o[2]+c)*255]},u.hcg.hsv=function(e){const t=e[1]/100,n=e[2]/100,r=t+n*(1-t);let o=0;return r>0&&(o=t/r),[e[0],o*100,r*100]},u.hcg.hsl=function(e){const t=e[1]/100,r=e[2]/100*(1-t)+.5*t;let o=0;return r>0&&r<.5?o=t/(2*r):r>=.5&&r<1&&(o=t/(2*(1-r))),[e[0],o*100,r*100]},u.hcg.hwb=function(e){const t=e[1]/100,n=e[2]/100,r=t+n*(1-t);return[e[0],(r-t)*100,(1-r)*100]},u.hwb.hcg=function(e){const t=e[1]/100,n=e[2]/100,r=1-n,o=r-t;let s=0;return o<1&&(s=(r-o)/(1-o)),[e[0],o*100,s*100]},u.apple.rgb=function(e){return[e[0]/65535*255,e[1]/65535*255,e[2]/65535*255]},u.rgb.apple=function(e){return[e[0]/255*65535,e[1]/255*65535,e[2]/255*65535]},u.gray.rgb=function(e){return[e[0]/100*255,e[0]/100*255,e[0]/100*255]},u.gray.hsl=function(e){return[0,0,e[0]]},u.gray.hsv=u.gray.hsl,u.gray.hwb=function(e){return[0,100,e[0]]},u.gray.cmyk=function(e){return[0,0,0,e[0]]},u.gray.lab=function(e){return[e[0],0,0]},u.gray.hex=function(e){const t=Math.round(e[0]/100*255)&255,r=((t<<16)+(t<<8)+t).toString(16).toUpperCase();return"000000".substring(r.length)+r},u.rgb.gray=function(e){return[(e[0]+e[1]+e[2])/3/255*100]};const E=V;function xe(){const e={},t=Object.keys(E);for(let n=t.length,r=0;r<n;r++)e[t[r]]={distance:-1,parent:null};return e}function Ee(e){const t=xe(),n=[e];for(t[e].distance=0;n.length;){const r=n.pop(),o=Object.keys(E[r]);for(let s=o.length,i=0;i<s;i++){const l=o[i],c=t[l];c.distance===-1&&(c.distance=t[r].distance+1,c.parent=r,n.unshift(l))}}return t}function Pe(e,t){return function(n){return t(e(n))}}function je(e,t){const n=[t[e].parent,e];let r=E[t[e].parent][e],o=t[e].parent;for(;t[o].parent;)n.unshift(t[o].parent),r=Pe(E[t[o].parent][o],r),o=t[o].parent;return r.conversion=n,r}var _e=function(e){const t=Ee(e),n={},r=Object.keys(t);for(let o=r.length,s=0;s<o;s++){const i=r[s];t[i].parent!==null&&(n[i]=je(i,t))}return n};const $=V,Me=_e,v={},qe=Object.keys($);function $e(e){const t=function(...n){const r=n[0];return r==null?r:(r.length>1&&(n=r),e(n))};return"conversion"in e&&(t.conversion=e.conversion),t}function Se(e){const t=function(...n){const r=n[0];if(r==null)return r;r.length>1&&(n=r);const o=e(n);if(typeof o=="object")for(let s=o.length,i=0;i<s;i++)o[i]=Math.round(o[i]);return o};return"conversion"in e&&(t.conversion=e.conversion),t}qe.forEach(e=>{v[e]={},Object.defineProperty(v[e],"channels",{value:$[e].channels}),Object.defineProperty(v[e],"labels",{value:$[e].labels});const t=Me(e);Object.keys(t).forEach(r=>{const o=t[r];v[e][r]=Se(o),v[e][r].raw=$e(o)})});var Ae=v;(function(e){const t=(f,a)=>(...p)=>`\x1B[${f(...p)+a}m`,n=(f,a)=>(...p)=>{const m=f(...p);return`\x1B[${38+a};5;${m}m`},r=(f,a)=>(...p)=>{const m=f(...p);return`\x1B[${38+a};2;${m[0]};${m[1]};${m[2]}m`},o=f=>f,s=(f,a,p)=>[f,a,p],i=(f,a,p)=>{Object.defineProperty(f,a,{get:()=>{const m=p();return Object.defineProperty(f,a,{value:m,enumerable:!0,configurable:!0}),m},enumerable:!0,configurable:!0})};let l;const c=(f,a,p,m)=>{l===void 0&&(l=Ae);const k=m?10:0,y={};for(const[F,me]of Object.entries(l)){const de=F==="ansi16"?"ansi":F;F===a?y[de]=f(p,k):typeof me=="object"&&(y[de]=f(me[a],k))}return y};function h(){const f=new Map,a={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}};a.color.gray=a.color.blackBright,a.bgColor.bgGray=a.bgColor.bgBlackBright,a.color.grey=a.color.blackBright,a.bgColor.bgGrey=a.bgColor.bgBlackBright;for(const[p,m]of Object.entries(a)){for(const[k,y]of Object.entries(m))a[k]={open:`\x1B[${y[0]}m`,close:`\x1B[${y[1]}m`},m[k]=a[k],f.set(y[0],y[1]);Object.defineProperty(a,p,{value:m,enumerable:!1})}return Object.defineProperty(a,"codes",{value:f,enumerable:!1}),a.color.close="\x1B[39m",a.bgColor.close="\x1B[49m",i(a.color,"ansi",()=>c(t,"ansi16",o,!1)),i(a.color,"ansi256",()=>c(n,"ansi256",o,!1)),i(a.color,"ansi16m",()=>c(r,"rgb",s,!1)),i(a.bgColor,"ansi",()=>c(t,"ansi16",o,!0)),i(a.bgColor,"ansi256",()=>c(n,"ansi256",o,!0)),i(a.bgColor,"ansi16m",()=>c(r,"rgb",s,!0)),a}Object.defineProperty(e,"exports",{enumerable:!0,get:h})})(z);var Ie={stdout:!1,stderr:!1},Be={stringReplaceAll:(e,t,n)=>{let r=e.indexOf(t);if(r===-1)return e;const o=t.length;let s=0,i="";do i+=e.substr(s,r-s)+t+n,s=r+o,r=e.indexOf(t,s);while(r!==-1);return i+=e.substr(s),i},stringEncaseCRLFWithFirstIndex:(e,t,n,r)=>{let o=0,s="";do{const i=e[r-1]==="\r";s+=e.substr(o,(i?r-1:r)-o)+t+(i?`\r
2
+ `:`
3
+ `)+n,o=r+1,r=e.indexOf(`
4
+ `,o)}while(r!==-1);return s+=e.substr(o),s}};const Re=/(?:\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi,J=/(?:^|\.)(\w+)(?:\(([^)]*)\))?/g,Ne=/^(['"])((?:\\.|(?!\1)[^\\])*)\1$/,Ue=/\\(u(?:[a-f\d]{4}|{[a-f\d]{1,6}})|x[a-f\d]{2}|.)|([^\\])/gi,De=new Map([["n",`
5
+ `],["r","\r"],["t"," "],["b","\b"],["f","\f"],["v","\v"],["0","\0"],["\\","\\"],["e","\x1B"],["a","\x07"]]);function W(e){const t=e[0]==="u",n=e[1]==="{";return t&&!n&&e.length===5||e[0]==="x"&&e.length===3?String.fromCharCode(parseInt(e.slice(1),16)):t&&n?String.fromCodePoint(parseInt(e.slice(2,-1),16)):De.get(e)||e}function Fe(e,t){const n=[],r=t.trim().split(/\s*,\s*/g);let o;for(const s of r){const i=Number(s);if(!Number.isNaN(i))n.push(i);else if(o=s.match(Ne))n.push(o[2].replace(Ue,(l,c,h)=>c?W(c):h));else throw new Error(`Invalid Chalk template style argument: ${s} (in style '${e}')`)}return n}function Le(e){J.lastIndex=0;const t=[];let n;for(;(n=J.exec(e))!==null;){const r=n[1];if(n[2]){const o=Fe(r,n[2]);t.push([r].concat(o))}else t.push([r])}return t}function H(e,t){const n={};for(const o of t)for(const s of o.styles)n[s[0]]=o.inverse?null:s.slice(1);let r=e;for(const[o,s]of Object.entries(n))if(!!Array.isArray(s)){if(!(o in r))throw new Error(`Unknown Chalk style: ${o}`);r=s.length>0?r[o](...s):r[o]}return r}var Te=(e,t)=>{const n=[],r=[];let o=[];if(t.replace(Re,(s,i,l,c,h,f)=>{if(i)o.push(W(i));else if(c){const a=o.join("");o=[],r.push(n.length===0?a:H(e,n)(a)),n.push({inverse:l,styles:Le(c)})}else if(h){if(n.length===0)throw new Error("Found extraneous } in Chalk template literal");r.push(H(e,n)(o.join(""))),o=[],n.pop()}else o.push(f)}),r.push(o.join("")),n.length>0){const s=`Chalk template literal is missing ${n.length} closing bracket${n.length===1?"":"s"} (\`}\`)`;throw new Error(s)}return r.join("")};const x=z.exports,{stdout:S,stderr:A}=Ie,{stringReplaceAll:ze,stringEncaseCRLFWithFirstIndex:Ge}=Be,{isArray:P}=Array,K=["ansi","ansi","ansi256","ansi16m"],w=Object.create(null),Ve=(e,t={})=>{if(t.level&&!(Number.isInteger(t.level)&&t.level>=0&&t.level<=3))throw new Error("The `level` option should be an integer from 0 to 3");const n=S?S.level:0;e.level=t.level===void 0?n:t.level};class Je{constructor(t){return X(t)}}const X=e=>{const t={};return Ve(t,e),t.template=(...n)=>Z(t.template,...n),Object.setPrototypeOf(t,j.prototype),Object.setPrototypeOf(t.template,t),t.template.constructor=()=>{throw new Error("`chalk.constructor()` is deprecated. Use `new chalk.Instance()` instead.")},t.template.Instance=Je,t.template};function j(e){return X(e)}for(const[e,t]of Object.entries(x))w[e]={get(){const n=_(this,I(t.open,t.close,this._styler),this._isEmpty);return Object.defineProperty(this,e,{value:n}),n}};w.visible={get(){const e=_(this,this._styler,!0);return Object.defineProperty(this,"visible",{value:e}),e}};const Y=["rgb","hex","keyword","hsl","hsv","hwb","ansi","ansi256"];for(const e of Y)w[e]={get(){const{level:t}=this;return function(...n){const r=I(x.color[K[t]][e](...n),x.color.close,this._styler);return _(this,r,this._isEmpty)}}};for(const e of Y){const t="bg"+e[0].toUpperCase()+e.slice(1);w[t]={get(){const{level:n}=this;return function(...r){const o=I(x.bgColor[K[n]][e](...r),x.bgColor.close,this._styler);return _(this,o,this._isEmpty)}}}}const We=Object.defineProperties(()=>{},ke(we({},w),{level:{enumerable:!0,get(){return this._generator.level},set(e){this._generator.level=e}}})),I=(e,t,n)=>{let r,o;return n===void 0?(r=e,o=t):(r=n.openAll+e,o=t+n.closeAll),{open:e,close:t,openAll:r,closeAll:o,parent:n}},_=(e,t,n)=>{const r=(...o)=>P(o[0])&&P(o[0].raw)?Q(r,Z(r,...o)):Q(r,o.length===1?""+o[0]:o.join(" "));return Object.setPrototypeOf(r,We),r._generator=e,r._styler=t,r._isEmpty=n,r},Q=(e,t)=>{if(e.level<=0||!t)return e._isEmpty?"":t;let n=e._styler;if(n===void 0)return t;const{openAll:r,closeAll:o}=n;if(t.indexOf("\x1B")!==-1)for(;n!==void 0;)t=ze(t,n.close,n.open),n=n.parent;const s=t.indexOf(`
6
+ `);return s!==-1&&(t=Ge(t,o,r,s)),r+t+o};let B;const Z=(e,...t)=>{const[n]=t;if(!P(n)||!P(n.raw))return t.join(" ");const r=t.slice(1),o=[n.raw[0]];for(let s=1;s<n.length;s++)o.push(String(r[s-1]).replace(/[{}\\]/g,"\\$&"),String(n.raw[s]));return B===void 0&&(B=Te),B(e,o.join(""))};Object.defineProperties(j.prototype,w);const M=j();M.supportsColor=S,M.stderr=j({level:A?A.level:0}),M.stderr.supportsColor=A;var He=M,Ke=e=>{console.log(`${He.magenta("JamComments:")} ${e}`)},Xe=()=>(typeof process<"u"&&process.env&&process.env.NODE_ENV&&process.env.NODE_ENV.toLowerCase())!=="production";const Ye="https://service.jamcomments.com",ee="http://localhost:4000";var Qe=(e=null)=>typeof window<"u"&&window.jcForceLocal?ee:e||(process.env.NODE_ENV==="production"?Ye:ee),Ze=Object.defineProperty,te=Object.getOwnPropertySymbols,et=Object.prototype.hasOwnProperty,tt=Object.prototype.propertyIsEnumerable,ne=(e,t,n)=>t in e?Ze(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,nt=(e,t)=>{for(var n in t||(t={}))et.call(t,n)&&ne(e,n,t[n]);if(te)for(var n of te(t))tt.call(t,n)&&ne(e,n,t[n]);return e};function rt(e,t){const n=new URL(e);for(const r in t)n.searchParams.append(r,t[r]);return n.toString()}async function ot({endpoint:e,fetchOptions:t,query:n,variables:r}){const o={query:n,variables:JSON.stringify(r)},{method:s="POST",headers:i={}}=t,l=/get/i.test(s),c=l?rt(e,o):e;try{const h=await fetch(c,{method:s.toUpperCase(),headers:nt({"Content-Type":`application/${l?"x-www-form-urlencoded":"json"}`},i),body:l?null:JSON.stringify(o)}),{data:f,errors:a}=await h.json(),p={data:f};return a&&(p.errors=a),p}catch(h){return{errors:[h]}}}function st({endpoint:e,method:t,headers:n}){return{send:async(o,s={})=>ot({endpoint:e,query:o,variables:s,fetchOptions:{method:t,headers:n}})}}var re=[{id:"1",name:"Joanne King",emailAddress:"joanne@example.com",content:"<blockquote>This is some random quote.</blockquote><p>That's good stuff! Thanks for posting.</p>",path:null,createdAt:"1620462061499",status:"approved"},{id:"2",name:"Jennyfer Abbott",emailAddress:"jennyfer@example.com",content:`Animi voluptatem quae quas eius et error id. Ipsum amet corporis. Non corrupti eum et vel harum ut mollitia rerum laborum. Sunt est id et. Beatae nobis sit id qui ut ducimus sapiente placeat. Minus atque rerum natus et. Libero velit corporis. Blanditiis enim aut enim est ex qui omnis nemo dolorem.
7
+
8
+ Vel asperiores molestias qui accusamus est libero voluptas. Blanditiis doloremque sint qui facere voluptatum et possimus aliquid. Eos enim iste qui aliquid suscipit a. Et nemo rerum voluptatem quia. Accusantium non sunt velit et temporibus beatae numquam omnis magnam. Nulla facere exercitationem est fugiat incidunt architecto corporis beatae et. Modi error quod qui rem aut.`,path:null,createdAt:"1586054668000",status:"approved"},{id:"3",name:"Carmella Gutkowski",emailAddress:"carmella@example.com",content:"Dolores delectus qui id rem aut. Modi voluptate laborum dolorum suscipit optio eaque. Cum est non temporibus voluptas incidunt.",path:null,createdAt:"1578537868000",status:"approved"},{id:"4",name:"Coby Sawayn",emailAddress:"coby@example.com",content:"Occaecati necessitatibus assumenda quia. Quam esse voluptas necessitatibus tenetur similique deleniti voluptas. Est voluptas nobis. Necessitatibus eum repellendus et commodi quasi corrupti. Cupiditate tempore quasi labore.",path:null,createdAt:"1602254668000",status:"approved"},{id:"5",name:"Florence Wolf",emailAddress:"florence@example.com",content:"Possimus vitae adipisci dolorum adipisci quaerat ut itaque. Dolorem delectus pariatur maxime qui voluptatem.",path:null,createdAt:"1591713868000",status:"approved"}],oe=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},it=function(t,n){if(n=n.split(":")[0],t=+t,!t)return!1;switch(n){case"http":case"ws":return t!==80;case"https":case"wss":return t!==443;case"ftp":return t!==21;case"gopher":return t!==70;case"file":return!1}return t!==0},R={},at=Object.prototype.hasOwnProperty,lt;function se(e){try{return decodeURIComponent(e.replace(/\+/g," "))}catch{return null}}function ie(e){try{return encodeURIComponent(e)}catch{return null}}function ct(e){for(var t=/([^=?#&]+)=?([^&]*)/g,n={},r;r=t.exec(e);){var o=se(r[1]),s=se(r[2]);o===null||s===null||o in n||(n[o]=s)}return n}function ut(e,t){t=t||"";var n=[],r,o;typeof t!="string"&&(t="?");for(o in e)if(at.call(e,o)){if(r=e[o],!r&&(r===null||r===lt||isNaN(r))&&(r=""),o=ie(o),r=ie(r),o===null||r===null)continue;n.push(o+"="+r)}return n.length?t+n.join("&"):""}R.stringify=ut,R.parse=ct;var ae=it,q=R,ht=/^[\x00-\x20\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]+/,le=/[\n\r\t]/g,ft=/^[A-Za-z][A-Za-z0-9+-.]*:\/\//,ce=/:\d+$/,pt=/^([a-z][a-z0-9.+-]*:)?(\/\/)?([\\/]+)?([\S\s]*)/i,mt=/^[a-zA-Z]:/;function N(e){return(e||"").toString().replace(ht,"")}var U=[["#","hash"],["?","query"],function(t,n){return d(n.protocol)?t.replace(/\\/g,"/"):t},["/","pathname"],["@","auth",1],[NaN,"host",void 0,1,1],[/:(\d*)$/,"port",void 0,1],[NaN,"hostname",void 0,1,1]],ue={hash:1,query:1};function he(e){var t;typeof window<"u"?t=window:typeof oe<"u"?t=oe:typeof self<"u"?t=self:t={};var n=t.location||{};e=e||n;var r={},o=typeof e,s;if(e.protocol==="blob:")r=new g(unescape(e.pathname),{});else if(o==="string"){r=new g(e,{});for(s in ue)delete r[s]}else if(o==="object"){for(s in e)s in ue||(r[s]=e[s]);r.slashes===void 0&&(r.slashes=ft.test(e.href))}return r}function d(e){return e==="file:"||e==="ftp:"||e==="http:"||e==="https:"||e==="ws:"||e==="wss:"}function fe(e,t){e=N(e),e=e.replace(le,""),t=t||{};var n=pt.exec(e),r=n[1]?n[1].toLowerCase():"",o=!!n[2],s=!!n[3],i=0,l;return o?s?(l=n[2]+n[3]+n[4],i=n[2].length+n[3].length):(l=n[2]+n[4],i=n[2].length):s?(l=n[3]+n[4],i=n[3].length):l=n[4],r==="file:"?i>=2&&(l=l.slice(2)):d(r)?l=n[4]:r?o&&(l=l.slice(2)):i>=2&&d(t.protocol)&&(l=n[4]),{protocol:r,slashes:o||d(r),slashesCount:i,rest:l}}function dt(e,t){if(e==="")return t;for(var n=(t||"/").split("/").slice(0,-1).concat(e.split("/")),r=n.length,o=n[r-1],s=!1,i=0;r--;)n[r]==="."?n.splice(r,1):n[r]===".."?(n.splice(r,1),i++):i&&(r===0&&(s=!0),n.splice(r,1),i--);return s&&n.unshift(""),(o==="."||o==="..")&&n.push(""),n.join("/")}function g(e,t,n){if(e=N(e),e=e.replace(le,""),!(this instanceof g))return new g(e,t,n);var r,o,s,i,l,c,h=U.slice(),f=typeof t,a=this,p=0;for(f!=="object"&&f!=="string"&&(n=t,t=null),n&&typeof n!="function"&&(n=q.parse),t=he(t),o=fe(e||"",t),r=!o.protocol&&!o.slashes,a.slashes=o.slashes||r&&t.slashes,a.protocol=o.protocol||t.protocol||"",e=o.rest,(o.protocol==="file:"&&(o.slashesCount!==2||mt.test(e))||!o.slashes&&(o.protocol||o.slashesCount<2||!d(a.protocol)))&&(h[3]=[/(.*)/,"pathname"]);p<h.length;p++){if(i=h[p],typeof i=="function"){e=i(e,a);continue}s=i[0],c=i[1],s!==s?a[c]=e:typeof s=="string"?(l=s==="@"?e.lastIndexOf(s):e.indexOf(s),~l&&(typeof i[2]=="number"?(a[c]=e.slice(0,l),e=e.slice(l+i[2])):(a[c]=e.slice(l),e=e.slice(0,l)))):(l=s.exec(e))&&(a[c]=l[1],e=e.slice(0,l.index)),a[c]=a[c]||r&&i[3]&&t[c]||"",i[4]&&(a[c]=a[c].toLowerCase())}n&&(a.query=n(a.query)),r&&t.slashes&&a.pathname.charAt(0)!=="/"&&(a.pathname!==""||t.pathname!=="")&&(a.pathname=dt(a.pathname,t.pathname)),a.pathname.charAt(0)!=="/"&&d(a.protocol)&&(a.pathname="/"+a.pathname),ae(a.port,a.protocol)||(a.host=a.hostname,a.port=""),a.username=a.password="",a.auth&&(l=a.auth.indexOf(":"),~l?(a.username=a.auth.slice(0,l),a.username=encodeURIComponent(decodeURIComponent(a.username)),a.password=a.auth.slice(l+1),a.password=encodeURIComponent(decodeURIComponent(a.password))):a.username=encodeURIComponent(decodeURIComponent(a.auth)),a.auth=a.password?a.username+":"+a.password:a.username),a.origin=a.protocol!=="file:"&&d(a.protocol)&&a.host?a.protocol+"//"+a.host:"null",a.href=a.toString()}function gt(e,t,n){var r=this;switch(e){case"query":typeof t=="string"&&t.length&&(t=(n||q.parse)(t)),r[e]=t;break;case"port":r[e]=t,ae(t,r.protocol)?t&&(r.host=r.hostname+":"+t):(r.host=r.hostname,r[e]="");break;case"hostname":r[e]=t,r.port&&(t+=":"+r.port),r.host=t;break;case"host":r[e]=t,ce.test(t)?(t=t.split(":"),r.port=t.pop(),r.hostname=t.join(":")):(r.hostname=t,r.port="");break;case"protocol":r.protocol=t.toLowerCase(),r.slashes=!n;break;case"pathname":case"hash":if(t){var o=e==="pathname"?"/":"#";r[e]=t.charAt(0)!==o?o+t:t}else r[e]=t;break;case"username":case"password":r[e]=encodeURIComponent(t);break;case"auth":var s=t.indexOf(":");~s?(r.username=t.slice(0,s),r.username=encodeURIComponent(decodeURIComponent(r.username)),r.password=t.slice(s+1),r.password=encodeURIComponent(decodeURIComponent(r.password))):r.username=encodeURIComponent(decodeURIComponent(t))}for(var i=0;i<U.length;i++){var l=U[i];l[4]&&(r[l[1]]=r[l[1]].toLowerCase())}return r.auth=r.password?r.username+":"+r.password:r.username,r.origin=r.protocol!=="file:"&&d(r.protocol)&&r.host?r.protocol+"//"+r.host:"null",r.href=r.toString(),r}function bt(e){(!e||typeof e!="function")&&(e=q.stringify);var t,n=this,r=n.host,o=n.protocol;o&&o.charAt(o.length-1)!==":"&&(o+=":");var s=o+(n.protocol&&n.slashes||d(n.protocol)?"//":"");return n.username?(s+=n.username,n.password&&(s+=":"+n.password),s+="@"):n.password?(s+=":"+n.password,s+="@"):n.protocol!=="file:"&&d(n.protocol)&&!r&&n.pathname!=="/"&&(s+="@"),(r[r.length-1]===":"||ce.test(n.hostname)&&!n.port)&&(r+=":"),s+=r+n.pathname,t=typeof n.query=="object"?e(n.query):n.query,t&&(s+=t.charAt(0)!=="?"?"?"+t:t),n.hash&&(s+=n.hash),s}g.prototype={set:gt,toString:bt},g.extractProtocol=fe,g.location=he,g.trimLeft=N,g.qs=q;var yt=g;const D=e=>(new yt(e).pathname||"").replace(/^(\/{1,})|\/{1,}$/g,""),vt=(e,t)=>{const n=D(t);return e.filter(r=>r.path?D(r.path)===n:!1)},pe=e=>/(^<[a-z]+>)(.*)(<\/[a-z]+>)$/.test(e)?e:e.split(/(?:\r\n|\r|\n)/).filter(t=>!!t).map(t=>`<p>${t.trim()}</p>`).join(""),wt=50,kt=`
9
+ fragment commentFields on Comment {
10
+ createdAt
11
+ name
12
+ content
13
+ path
14
+ id
15
+ }
16
+
17
+ query Comments($domain: String!, $status: String, $skip: Int, $perPage: Int, $path: String){
18
+ comments(domain: $domain, status: $status, skip: $skip, perPage: $perPage, path: $path) {
19
+ items {
20
+ ...commentFields
21
+ children {
22
+ ...commentFields
23
+ }
24
+ }
25
+ meta {
26
+ hasMore
27
+ }
28
+ }
29
+ }`;class Ct{constructor({domain:t,apiKey:n,isDev:r=Xe()}){this.isDev=r,this.domain=t,this.client=st({endpoint:`${Qe()}/graphql`,headers:{"x-api-key":n}})}async _getBatchOfComments({skip:t=0,path:n=""}){const{data:r,errors:o}=await this.client.send(kt,{domain:this.domain,status:"approved",perPage:wt,path:n,skip:t});if(!r&&o&&o.length)throw new Error(`Something went wrong with JamComments! Here's the error:
30
+
31
+ ${JSON.stringify(o)}`);const{items:s,meta:i}=r.comments;if(o&&o.length)throw new Error(o[0].message);return Ke(`Fetched a batch of ${s.length} comments.`),{comments:s,hasMore:i.hasMore}}_prepareDummyComments(){const t=re.map(n=>n.createdAt).sort().reverse();return re.map((n,r)=>(n.createdAt=t[r],delete n.emailAddress,n))}_prepareContent(t){return t.map(n=>(n.content=pe(n.content),n))}async getAllComments(t=""){if(this.isDev)return this._prepareContent(this._prepareDummyComments());let n=[],r=0,o=!1;do{const s=await this._getBatchOfComments({skip:r,path:t});o=s.hasMore,r=r+s.comments.length,n=[...n,...s.comments]}while(o);return this._prepareContent(n)}}var Ot=Ct;b.CommentFetcher=Ot,b.filterByUrl=vt,b.makeHtmlReady=pe,b.parsePath=D,Object.defineProperties(b,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Gets the path from a URL with no leading or trailing slashes.
3
+ */
4
+ export declare const parsePath: (urlOrPath: string) => string;
5
+ /**
6
+ * Filter out the comments that don't belong to a certain URL.
7
+ */
8
+ export declare const filterByUrl: (comments: any[], urlOrPath: string) => any[];
9
+ export declare const makeHtmlReady: (content: string) => string;
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@jam-comments/server-utilities",
3
+ "version": "0.0.1",
4
+ "description": "Various JavaScript utilities for JamComments.",
5
+ "main": "dist/index.umd.js",
6
+ "module": "dist/index.es.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist/"
10
+ ],
11
+ "exports": {
12
+ "./*": {
13
+ "import": "./dist/index.es.js",
14
+ "require": "./dist/index.umd.js"
15
+ }
16
+ },
17
+ "scripts": {
18
+ "watch": "npm run build -- --watch",
19
+ "build": "vite build && tsc",
20
+ "test": "jest --config ./jest.config.js",
21
+ "prettify": "prettier ./**/*.{js,md,ts} --write"
22
+ },
23
+ "keywords": [],
24
+ "author": "Alex MacArthur <alex@macarthur.me> (https://macarthur.me)",
25
+ "homepage": "https://jamcomments.com",
26
+ "license": "GPL-2.0",
27
+ "dependencies": {
28
+ "@jam-comments/shared-utilities": "^0.0.1",
29
+ "graphql-quest": "^1.1.2",
30
+ "typescript": "^4.6.4",
31
+ "url-parse": "^1.5.3"
32
+ },
33
+ "devDependencies": {
34
+ "@babel/preset-env": "^7.15.8",
35
+ "@babel/preset-typescript": "^7.15.0",
36
+ "@types/jest": "^27.0.2",
37
+ "@types/node": "^16.11.4",
38
+ "concurrently": "^6.3.0",
39
+ "jest": "^27.2.1",
40
+ "jest-cli": "^27.2.1",
41
+ "prettier": "^2.2.1",
42
+ "ts-jest": "^27.0.5",
43
+ "vite": "^2.6.10"
44
+ },
45
+ "publishConfig": {
46
+ "access": "public"
47
+ }
48
+ }