question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use natural sort for sorting selectors

See original GitHub issue

It appears that clean-css now sorts selectors, whereas it didn’t previously. It seems to be using a simple naive sort, which has somewhat unpleasant results when the selectors have numbers in them. For example:

.col-lg-1,.col-lg-10,.col-lg-11,.col-lg-12,.col-lg-2,.col-lg-3,.col-lg-4,.col-lg-5,.col-lg-6,.col-lg-7,.col-lg-8,.col-lg-9 {...}

Would it be possible to use natural sorting instead, to obtain more pleasant results? For example:

.col-lg-1,.col-lg-2,.col-lg-3,.col-lg-4,.col-lg-5,.col-lg-6,.col-lg-7,.col-lg-8,.col-lg-9,.col-lg-10,.col-lg-11,.col-lg-12 {...}

Here are a couple libs I found on npm that might do the job:

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
jakubpawlowiczcommented, Jan 11, 2017

Ready on master and soon in 4.0. Available via:

// API
new CleanCSS({ level: { 1: { selectorsSortingMethod: 'natural' } } }).minify(...)
# CLI
%> cleancss -O1 selectorsSortingMethod:natural ...
0reactions
jakubpawlowiczcommented, Dec 19, 2015

Thanks @jessehouchins for your input. I’m still considering it and leaving it open as an enhancement.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Use natural sort for sorting selectors · Issue #425 · clean-css ...
It seems to be using a simple naive sort, which has somewhat unpleasant results when the selectors have numbers in them.
Read more >
Natural Sort Order in C# - Stack Overflow
The easiest thing to do is just P/Invoke the built-in function in Windows, and use it as the comparison function in your IComparer...
Read more >
Natural sorting - Rosetta Code
1. Ignore leading, trailing and multiple adjacent spaces · 2. Make all whitespace characters equivalent. · 3. Sorting without regard to case. ·...
Read more >
Natural-Order Filename Sort - File Exchange - MATLAB Central
Alphanumeric sort of filenames or filepaths, with customizable number format. ... To sort the elements of a string/cell array use NATSORT:.
Read more >
Collection processing in Kotlin: Sorting, shuffling and reversing
sorted can only be used on a list of elements with natural order for elements that implement the Comparable interface. The most important...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found