-
Notifications
You must be signed in to change notification settings - Fork 1
/
pairify.min.js
1 lines (1 loc) · 2.53 KB
/
pairify.min.js
1
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).Pairify=e()}}((function(){return function e(t,n,o){function r(l,s){if(!n[l]){if(!t[l]){var c="function"==typeof require&&require;if(!s&&c)return c(l,!0);if(i)return i(l,!0);var f=new Error("Cannot find module '"+l+"'");throw f.code="MODULE_NOT_FOUND",f}var u=n[l]={exports:{}};t[l][0].call(u.exports,(function(e){return r(t[l][1][e]||e)}),u,u.exports,e,t,n,o)}return n[l].exports}for(var i="function"==typeof require&&require,l=0;l<o.length;l++)r(o[l]);return r}({1:[function(e,t,n){const o=[{type:"comment-single-line",start:"//",end:"\n ",category:"comment"},{type:"comment-block",start:"/*",end:"*/",category:"comment"}].concat([{type:"single-quotes",start:"'",end:"'",category:"string"},{type:"double-quotes",start:'"',end:'"',category:"string"},{type:"template-literal",start:"`",end:"`",category:"string"}],[{type:"round",start:"(",end:")",category:"block"},{type:"curly",start:"{",end:"}",category:"block"},{type:"square",start:"[",end:"]",category:"block"},{type:"angle",start:"<",end:">",category:"block"}]);function r(e,t,n,o){return{token:e,line:t,position:n,cursor:o}}function i(e,t,n,o){return{type:e,from:[t.line,t.position],to:[n.line,n.position],body:[o[0],o[1]-o[0]]}}function l(e){let t=1,n=[],l=[],s=o.reduce((e,t)=>(e[t.start]=t,e),{}),c=o.reduce((e,t)=>(e[t.end]=t,e),{}),f=0;for(let o=0;o<e.length;o++){const u=e[o],p=e[o+1],a=e[o-1],y=s[u]||s[u+p]||null,d=c[u]||c[u+p]||null;if("\n"===u){for(let e=n.length-1;e>=0;e--)if("comment-single-line"===n[e].token.type){const r=n[e];n.splice(e),l.push(i("comment-single-line",{line:r.line,position:r.position},{line:t,position:f+1},[r.cursor,o+1]));break}t+=1,f=0}else if(f+=1,n.length>0)if(d){let e=!1,s=!1;for(let r=n.length-1;r>=0&&("comment"!==n[r].token.category&&"string"!==n[r].token.category||(s=!0),"angle"!==d.type||"="!==a);r--)if(d.type===n[r].token.type){if(e=!0,"block"===d.category&&s)break;const c=n[r];n.splice(r),l.push(i(d.type,{line:c.line,position:c.position},{line:t,position:f+d.end.length},[c.cursor,o+1]));break}e||null===y||n.push(r(y,t,f,o))}else null!==y&&n.push(r(y,t,f,o));else null!==y&&n.push(r(y,t,f,o))}return l}t.exports={analyze:l,match:function(e,t,n){return l(e).filter(e=>t>e.from[0]&&t<e.to[0]||(e.from[0]===e.to[0]&&e.from[0]===t?n>e.from[1]&&n<=e.to[1]:t===e.from[0]?n>=e.from[1]:t===e.to[0]&&n<e.to[1]))}}},{}]},{},[1])(1)}));