UNPKG

projen

Version:

CDK for software projects

1 lines 2.05 kB
import{escapeKey,escapeValue}from"../escape/index.js";var BOM="\ufeff",wrapAtWidth=function(e,a){if(e.length<=a)return e;for(var r=[],i=0,t=e.length;i<t;){var o=Math.min(i+a,t);if(o<t)for(var n=0;n<6&&o-n>i;n++){var p=o-n;if(p+5<=t&&"\\"===e[p]&&"u"===e[p+1]){o=p;break}}r.push(e.slice(i,o)),i=o}return r.join("\\\n ")},rebuildPropertyLine=function(e,a){var r,i,t,o,n,p=!0===a.escapeUnicode,s=a.removeLeadingWhitespace?"":e.leadingWhitespace,c=p?escapeKey(e.key,!0):e.escapedKey,d=null!==(r=a.separatorLeading)&&void 0!==r?r:e.separatorLeading,l=null!==(i=a.separatorTrailing)&&void 0!==i?i:e.separatorTrailing;void 0!==a.separatorChar?(n=" "===a.separatorChar?"":a.separatorChar," "===a.separatorChar&&(d=null!==(t=a.separatorLeading)&&void 0!==t?t:" ")):n=null!==(o=e.separatorChar)&&void 0!==o?o:"";var u=p?escapeValue(e.value,!0):e.escapedValue;return void 0!==a.wrapKeysAt&&a.wrapKeysAt>0&&(c=wrapAtWidth(c,a.wrapKeysAt)),void 0!==a.wrapValuesAt&&a.wrapValuesAt>0&&(u=wrapAtWidth(u,a.wrapValuesAt)),"".concat(s).concat(c).concat(d).concat(n).concat(l).concat(u)};export var formatNormalized=function(e,a,r,i){var t,o,n=null!==(t=i.endOfLineCharacter)&&void 0!==t?t:r,p=void 0!==i.separatorChar||void 0!==i.separatorLeading||void 0!==i.separatorTrailing||!0===i.escapeUnicode||!0===i.collapseMultiline||void 0!==i.wrapKeysAt||void 0!==i.wrapValuesAt||!0===i.removeLeadingWhitespace;if(i.deduplicateKeys){for(var s={},c=[],d=e.length-1;d>=0;d--){var l=e[d];"property"===l.type&&(s[l.key]?c.push(d):s[l.key]=!0)}o={};for(var u=0;u<c.length;u++){var v=c[u];if(o[v]=!0,!i.deduplicateKeysKeepLeadingNodes)for(var h=v-1;h>=0&&"property"!==e[h].type;h--)o[h]=!0}}for(var f=[],y=0;y<e.length;y++)if(!(null==o?void 0:o[y])){var g=e[y];switch(g.type){case"comment":if(i.removeComments)continue;f.push(i.removeLeadingWhitespace?"".concat(g.delimiter).concat(g.body):g.rawLine);break;case"blank":if(i.removeBlankLines)continue;f.push(g.rawLine);break;case"property":p?f.push(rebuildPropertyLine(g,i)):f.push(g.rawLines.join(n))}}return(a?BOM:"")+f.join(n)};