Skip to content

Instantly share code, notes, and snippets.

@guillemcanal
Created June 3, 2022 11:36
Show Gist options
  • Save guillemcanal/cb4dcc2a8833bb48fc764f0b7ee2c6cf to your computer and use it in GitHub Desktop.
Save guillemcanal/cb4dcc2a8833bb48fc764f0b7ee2c6cf to your computer and use it in GitHub Desktop.
theredoc
!function(){"use sctrict";function n(n){return/^\s*$/.test(n)}window.theredoc=function(t,...e){const c=function(t){const e=n(t[0]),c=n(t[t.length-1]);return e||c?t.slice(e?1:0,c?t.length-1:t.length):t}(function(n,t){let e="";return n.forEach((n,c)=>{e+=n+(t[c]||"")}),e}(t,e).split("\n"));return function(n,t){const e=new RegExp(`^ {${t}}`);return n.map(n=>e.test(n)?n.replace(e,""):n)}(c,function(n){let t=null;return n.forEach(n=>{const e=n.search(/[^ ]/);-1!==e&&(null===t||e<t)&&(t=e)}),t}(c)).join("\n")}}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment