biati-digital / nova-text-tools

Swiss Army knife for text manipulation and selection Sort, Transform, Filter, Delete Duplicates, Encode, Decode and much more...
16 stars 2 forks source link

Minify ? #25

Open yabdab opened 1 year ago

yabdab commented 1 year ago

Is there a way to "minify" ( remove all extra spaces and line-breaks ) from a selection using Text Tools?

biati-digital commented 1 year ago

Do you have an example? before and after of what you want to achieve?

yabdab commented 1 year ago

Before:

<svg xmlns="http://www.w3.org/2000/svg"
           height="1em"
           viewBox="0 0 512 512">
        <path
              d="M0 96C0 60.7 28.7 32 64 32H448c35.3 0 64 28.7 64 64V416c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64V96zM323.8 202.5c-4.5-6.6-11.9-10.5-19.8-10.5s-15.4 3.9-19.8 10.5l-87 127.6L170.7 297c-4.6-5.7-11.5-9-18.7-9s-14.2 3.3-18.7 9l-64 80c-5.8 7.2-6.9 17.1-2.9 25.4s12.4 13.6 21.6 13.6h96 32H424c8.9 0 17.1-4.9 21.2-12.8s3.6-17.4-1.4-24.7l-120-176zM112 192a48 48 0 1 0 0-96 48 48 0 1 0 0 96z" />
</svg>

After:

<svg xmlns="http://www.w3.org/2000/svg" height="1em" viewBox="0 0 512 512"><path d="M0 96C0 60.7 28.7 32 64 32H448c35.3 0 64 28.7 64 64V416c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64V96zM323.8 202.5c-4.5-6.6-11.9-10.5-19.8-10.5s-15.4 3.9-19.8 10.5l-87 127.6L170.7 297c-4.6-5.7-11.5-9-18.7-9s-14.2 3.3-18.7 9l-64 80c-5.8 7.2-6.9 17.1-2.9 25.4s12.4 13.6 21.6 13.6h96 32H424c8.9 0 17.1-4.9 21.2-12.8s3.6-17.4-1.4-24.7l-120-176zM112 192a48 48 0 1 0 0-96 48 48 0 1 0 0 96z"/></svg>
biati-digital commented 1 year ago

Thank's for the example, not possible for now but I'll see if it can be added in a future update.

yabdab commented 1 year ago

OK. All it needs to do is replace all the double spaces/tabs and line breaks with an empty string. Fingers crossed it makes it into a future update. Cheers.

yabdab commented 1 year ago

I added this to your extension and it works pretty well for what I needed. Feel free to include it in main build if you like?

minifySelection(text) {
    return text.replace(/>\s+</g, '><').replace(/\s+/g, ' ')
  }
biati-digital commented 1 year ago

Thank's for sharing that code but it's really specific to your needs, it will not work for many other cases for example CSS, Python, etc. If this is implemente it will require a lot of testing to make sure it works.