PluginProbe
Code Block Pro – Beautiful Syntax Highlighting / 1.27.7
Code Block Pro – Beautiful Syntax Highlighting v1.27.7
1.27.1 1.27.2 1.27.3 1.27.4 1.27.5 1.27.6 1.27.7 1.28.0 1.3.0 1.4.0 1.5.0 1.5.1 1.5.2 1.6.0 1.7.0 1.8.0 1.9.0 1.9.1 1.9.2 1.9.3 trunk 1.1.0 1.10.0 1.11.0 1.11.1 All 63 releases
code-block-pro / build / shiki / node_modules / jsonc-parser / lib / umd / impl / format.js

format.js in Code Block Pro – Beautiful Syntax Highlighting 1.27.7, at build/shiki/node_modules/jsonc-parser/lib/umd/impl/format.js

1 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 !function(e){if("object"==typeof module&&"object"==typeof module.exports){var n=e(require,exports);void 0!==n&&(module.exports=n)}else"function"==typeof define&&define.amd&&define(["require","exports","./scanner","./string-intern"],e)}((function(e,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.isEOL=n.format=void 0;const t=e("./scanner"),s=e("./string-intern");function c(e,n){let t="";for(let s=0;s<n;s++)t+=e;return t}function r(e,n){return-1!=="\r\n".indexOf(e.charAt(n))}n.format=function(e,n,a){let i,o,f,p,l;if(n){for(p=n.offset,l=p+n.length,f=p;f>0&&!r(e,f-1);)f--;let t=l;for(;t<e.length&&!r(e,t);)t++;o=e.substring(f,t),i=function(e,n){let t=0,c=0;const r=n.tabSize||4;for(;t<e.length;){let n=e.charAt(t);if(n===s.cachedSpaces[1])c++;else{if("\t"!==n)break;c+=r}t++}return Math.floor(c/r)}(o,a)}else o=e,i=0,f=0,p=0,l=e.length;const h=function(e,n){for(let e=0;e<n.length;e++){const t=n.charAt(e);if("\r"===t)return e+1<n.length&&"\n"===n.charAt(e+1)?"\r\n":"\r";if("\n"===t)return"\n"}return e&&e.eol||"\n"}(a,e),k=s.supportedEols.includes(h);let u,d=0,g=0;u=a.insertSpaces?s.cachedSpaces[a.tabSize||4]??c(s.cachedSpaces[1],a.tabSize||4):"\t";const L="\t"===u?"\t":" ";let S=(0,t.createScanner)(o,!1),b=!1;function O(){if(d>1)return c(h,d)+c(u,i+g);const e=u.length*(i+g);return!k||e>s.cachedBreakLinesWithSpaces[L][h].length?h+c(u,i+g):e<=0?h:s.cachedBreakLinesWithSpaces[L][h][e]}function T(){let e=S.scan();for(d=0;15===e||14===e;)14===e&&a.keepLines?d+=1:14===e&&(d=1),e=S.scan();return b=16===e||0!==S.getTokenError(),e}const m=[];function x(t,s,c){b||n&&!(s<l&&c>p)||e.substring(s,c)===t||m.push({offset:s,length:c-s,content:t})}let v=T();if(a.keepLines&&d>0&&x(c(h,d),0,0),17!==v){let e=S.getTokenOffset()+f;x(u.length*i<20&&a.insertSpaces?s.cachedSpaces[u.length*i]:c(u,i),f,e)}for(;17!==v;){let e=S.getTokenOffset()+S.getTokenLength()+f,n=T(),t="",c=!1;for(;0===d&&(12===n||13===n);){let r=S.getTokenOffset()+f;x(s.cachedSpaces[1],e,r),e=S.getTokenOffset()+S.getTokenLength()+f,c=12===n,t=c?O():"",n=T()}if(2===n)1!==v&&g--,a.keepLines&&d>0||!a.keepLines&&1!==v?t=O():a.keepLines&&(t=s.cachedSpaces[1]);else if(4===n)3!==v&&g--,a.keepLines&&d>0||!a.keepLines&&3!==v?t=O():a.keepLines&&(t=s.cachedSpaces[1]);else{switch(v){case 3:case 1:g++,t=a.keepLines&&d>0||!a.keepLines?O():s.cachedSpaces[1];break;case 5:t=a.keepLines&&d>0||!a.keepLines?O():s.cachedSpaces[1];break;case 12:t=O();break;case 13:d>0?t=O():c||(t=s.cachedSpaces[1]);break;case 6:a.keepLines&&d>0?t=O():c||(t=s.cachedSpaces[1]);break;case 10:a.keepLines&&d>0?t=O():6!==n||c||(t="");break;case 7:case 8:case 9:case 11:case 2:case 4:a.keepLines&&d>0?t=O():12!==n&&13!==n||c?5!==n&&17!==n&&(b=!0):t=s.cachedSpaces[1];break;case 16:b=!0}d>0&&(12===n||13===n)&&(t=O())}17===n&&(t=a.keepLines&&d>0?O():a.insertFinalNewline?h:""),x(t,e,S.getTokenOffset()+f),v=n}return m},n.isEOL=r}));