input-format
Version:
Formatting user's text input on-the-fly
1 lines • 1.65 kB
Source Map (JSON)
{"version":3,"file":"closeBraces.js","names":["count_occurences","closeBraces","retained_template","template","placeholder","empty_placeholder","cut_before","length","opening_braces","closing_braces","dangling_braces","replace"],"sources":["../source/closeBraces.js"],"sourcesContent":["import { count_occurences } from './helpers.js'\r\n\r\nexport default function closeBraces(retained_template, template, placeholder = 'x', empty_placeholder = ' ')\r\n{\r\n\tlet cut_before = retained_template.length\r\n\r\n\tconst opening_braces = count_occurences('(', retained_template)\r\n\tconst closing_braces = count_occurences(')', retained_template)\r\n\r\n\tlet dangling_braces = opening_braces - closing_braces\r\n\r\n\twhile (dangling_braces > 0 && cut_before < template.length)\r\n\t{\r\n\t\tretained_template += template[cut_before].replace(placeholder, empty_placeholder)\r\n\r\n\t\tif (template[cut_before] === ')')\r\n\t\t{\r\n\t\t\tdangling_braces--\r\n\t\t}\r\n\r\n\t\tcut_before++\r\n\t}\r\n\r\n\treturn retained_template\r\n}\r\n"],"mappings":"AAAA,SAASA,gBAAT,QAAiC,cAAjC;AAEA,eAAe,SAASC,WAAT,CAAqBC,iBAArB,EAAwCC,QAAxC,EACf;EAAA,IADiEC,WACjE,uEAD+E,GAC/E;EAAA,IADoFC,iBACpF,uEADwG,GACxG;EACC,IAAIC,UAAU,GAAGJ,iBAAiB,CAACK,MAAnC;EAEA,IAAMC,cAAc,GAAGR,gBAAgB,CAAC,GAAD,EAAME,iBAAN,CAAvC;EACA,IAAMO,cAAc,GAAGT,gBAAgB,CAAC,GAAD,EAAME,iBAAN,CAAvC;EAEA,IAAIQ,eAAe,GAAGF,cAAc,GAAGC,cAAvC;;EAEA,OAAOC,eAAe,GAAG,CAAlB,IAAuBJ,UAAU,GAAGH,QAAQ,CAACI,MAApD,EACA;IACCL,iBAAiB,IAAIC,QAAQ,CAACG,UAAD,CAAR,CAAqBK,OAArB,CAA6BP,WAA7B,EAA0CC,iBAA1C,CAArB;;IAEA,IAAIF,QAAQ,CAACG,UAAD,CAAR,KAAyB,GAA7B,EACA;MACCI,eAAe;IACf;;IAEDJ,UAAU;EACV;;EAED,OAAOJ,iBAAP;AACA"}