MCPcopy Create free account
hub / github.com/ChinaSiro/claude-code-sourcemap / s2K

Function s2K

package/cli.js:3119–3119  ·  view source on GitHub ↗
(q)

Source from the content-addressed store, hash-verified

3117
3118`+_+`
3119
3120`:_}};this.options=O8Y({},K,q),this.rules=new o2K(this.options)}$m8.prototype={turndown:function(q){if(!S8Y(q))throw TypeError(q+" is not a string, or an element/document/fragment node.");if(q==="")return"";var K=s2K.call(this,new G8Y(q,this.options));return R8Y.call(this,K)},use:function(q){if(Array.isArray(q))for(var K=0;K<q.length;K++)this.use(q[K]);else if(typeof q==="function")q(this);else throw TypeError("plugin must be a Function or an Array of Functions");return this},addRule:function(q,K){return this.rules.add(q,K),this},keep:function(q){return this.rules.keep(q),this},remove:function(q){return this.rules.remove(q),this},escape:function(q){return L8Y.reduce(function(K,_){return K.replace(_[0],_[1])},q)}};function s2K(q){var K=this;return E8Y.call(q.childNodes,function(_,z){z=new k8Y(z,K.options);var Y="";if(z.nodeType===3)Y=z.isCode?z.nodeValue:K.escape(z.nodeValue);else if(z.nodeType===1)Y=h8Y.call(K,z);return t2K(_,Y)},"")}function R8Y(q){var K=this;return this.rules.forEach(function(_){if(typeof _.append==="function")q=t2K(q,_.append(K.options))}),q.replace(/^[\t\r\n]+/,"").replace(/[\t\r\n\s]+$/,"")}function h8Y(q){var K=this.rules.forNode(q),_=s2K.call(this,q),z=q.flankingWhitespace;if(z.leading||z.trailing)_=_.trim();return z.leading+K.replacement(_,q,this.options)+z.trailing}function t2K(q,K){var _=j8Y(q),z=w8Y(K),Y=Math.max(q.length-_.length,K.length-z.length),$=`
3121
3122`.substring(0,Y);return _+$+z}function S8Y(q){return q!=null&&(typeof q==="string"||q.nodeType&&(q.nodeType===1||q.nodeType===9||q.nodeType===11))}e2K.exports=$m8});var AjK={};T8(AjK,{validateURL:()=>zjK,isPreapprovedUrl:()=>Pe1,isPermittedRedirect:()=>$jK,getWithPermittedRedirects:()=>We1,getURLMarkdownContent:()=>De1,clearWebFetchCache:()=>x8Y,checkDomainBlocklist:()=>YjK,applyPromptToMarkdown:()=>fe1,MAX_MARKDOWN_LENGTH:()=>y88});function x8Y(){Me1.clear(),Xe1.clear()}function u8Y(){return I8Y??=Promise.resolve().then(() => O6(qjK(),1)).then((q)=>{return new q.default})}function Pe1(q){try{let K=new URL(q);return Vu8(K.hostname,K.pathname)}catch{return!1}}function zjK(q){if(q.length>m8Y)return!1;let K;try{K=new URL(q)}catch{return!1}if(K.username||K.password)return!1;if(K.hostname.split(".").length<2)return!1;return!0}async function YjK(q){if(Xe1.has(q))return{status:"allowed"};try{let K=await $1.get(`https://api.anthropic.com/api/web/domain_info?domain=${encodeURIComponent(q)}`,{timeout:g8Y});if(K.status===200){if(K.data.can_fetch===!0)return Xe1.set(q,!0),{status:"allowed"};return{status:"blocked"}}return{status:"check_failed",error:Error(`Domain check returned status ${K.status}`)}}catch(K){return H6(K),{status:"check_failed",error:K}}}function $jK(q,K){try{let _=new URL(q),z=new URL(K);if(z.protocol!==_.protocol)return!1;if(z.port!==_.port)return!1;if(z.username||z.password)return!1;let Y=(O)=>O.replace(/^www\./,""),$=Y(_.hostname),A=Y(z.hostname);return $===A}catch(_){return!1}}async function We1(q,K,_,z=0){if(z>KjK)throw Error(`Too many redirects (exceeded ${KjK})`);try{return await $1.get(q,{signal:K,timeout:B8Y,maxRedirects:0,responseType:"arraybuffer",maxContentLength:p8Y,headers:{Accept:"text/markdown, text/html, */*","User-Agent":tCq()}})}catch(Y){if($1.isAxiosError(Y)&&Y.response&&[301,302,307,308].includes(Y.response.status)){let $=Y.response.headers.location;if(!$)throw Error("Redirect missing Location header");let A=new URL($,q).toString();if(_(q,A))return We1(A,K,_,z+1);else return{type:"redirect",originalUrl:q,redirectUrl:A,statusCode:Y.response.status}}if($1.isAxiosError(Y)&&Y.response?.status===403&&Y.response.headers["x-proxy-error"]==="blocked-by-allowlist"){let $=new URL(q).hostname;throw new _jK($)}throw Y}}function F8Y(q){return"type"in q&&q.type==="redirect"}async function De1(q,K){if(!zjK(q))throw Error("Invalid URL");let _=Me1.get(q);if(_)return{bytes:_.bytes,code:_.code,codeText:_.codeText,content:_.content,contentType:_.contentType,persistedPath:_.persistedPath,persistedSize:_.persistedSize};let z,Y=q;try{if(z=new URL(q),z.protocol==="http:")z.protocol="https:",Y=z.toString();let W=z.hostname;if(!Z7().skipWebFetchPreflight)switch((await YjK(W)).status){case"allowed":break;case"blocked":throw new He1(W);case"check_failed":throw new Je1(W)}}catch(W){if(W instanceof He1||W instanceof Je1)throw W;H6(W)}let $=await We1(Y,K.signal,$jK);if(F8Y($))return $;let A=Buffer.from($.data);$.data=null;let O=$.headers["content-type"]??"",w,j;if(_h4(O)){let W=`webfetch-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,D=await ZN6(A,O,W);if(!("error"in D))w=D.filepath,j=D.size}let H=A.length,J=A.toString("utf-8"),M,X;if(O.includes("text/html"))M=(await u8Y()).turndown(J),X=Buffer.byteLength(M);else M=J,X=H;let P={bytes:H,code:$.status,codeText:$.statusText,content:M,contentType:O,persistedPath:w,persistedSize:j};return Me1.set(q,P,{size:Math.max(1,X)}),P}async function fe1(q,K,_,z,Y){let $=K.length>y88?K.slice(0,y88)+`

Callers

nothing calls this directly

Calls 3

t2KFunction · 0.85
callMethod · 0.80
escapeMethod · 0.80

Tested by

no test coverage detected