FlorianWendelborn / atom-sorter

:signal_strength: :atom: package to sort things.
https://atom.io/packages/sorter
MIT License
5 stars 1 forks source link

Sorting inline stuff (html attributes, javascript object keys, css) #2

Open Noitidart opened 7 years ago

Noitidart commented 7 years ago

This is just such an awesome plugin. Thank you for it. I use it regularly to sort keys in javascript objects:

{z:true, b:false} => {b:false, z:true}

But I was hoping to use it on html attributes as well, but it splits on the = so it doesnt work. Is it possible to make it not split on =?

Like:

zid="body" key="body"

Should sort to:

key="body" zid="body"

Also some time in my js objects I have a space between the colon so like this:

{z: true, b: false}

And this fails to sort, is it possible to ignore the first space after a colon?

Example of inline css:

position: absolute; top: 1; bottom: 3;

A regex split that would work for this is /\:\w*/ or for equals sign: /\=\w*/

FlorianWendelborn commented 7 years ago

@Noitidart I'll look into it as I'm using this a lot too. I actually planned to (some day) implement an object-sorting mechanism that actually detects objects. I guess that'd fix part of this issue.

in my js objects I have a space between the colon

{z: true, b: false} => {b: false, z: true}

Works for me. What's the part you don't expect?

v0.1.3 should properly sort inline CSS. Let me know if there's anything unexpected happening.

FlorianWendelborn commented 7 years ago

v0.1.4 sorts b="B" a="A" to a="A" b="B"

FlorianWendelborn commented 7 years ago

v0.1.8 sorts style="top: 1px; bottom: 2px;" a="test" to a="test" style="top: 1px; bottom: 2px;"

Noitidart commented 7 years ago

Thank you sir so much!! You thought of common cases that I didn't even consider! Too great! :)

FlorianWendelborn commented 7 years ago

v1.0.0 should sort JSON properly. Doesn't work for plain objects though. :/

Noitidart commented 7 years ago

Thank you sooo much for keeping us updated, especially the to do style task list you edited into the OP. JSON sorting is so awesome! Just tested it!