Sorting CSS <time> values
In the previous blog post I announced that Project Wallace now supports analysis of animation-duration
and transition-duration
. One of the neat things about Project Wallace is that it always shows all your values sorted in a sensible way. For example, font-sizes are sorted from small to large, colors are sorted by hue, etc. So it only makes sense to sort CSS from short to long. Enter css-time-sort.
The functional requirements
- Sort durations from short to long
- If a
ms
value is the same as as
value, sort thems
value first - Be able to sort an array of
['1s', '200ms']
with the native.sort()
method
With this relatively simple piece of code it’s possible to sort an array of CSS durations like so:
const { sortFn } = require('css-time-sort')
const sorted = ['1s', '200ms'].sort(sortFn)
// RESULT:
// => ['200ms', '1s']
Check out the source code on GitHub.
Popular posts
Making Analyze CSS render 6 times faster
A deep-dive in how the Analyze CSS page renders 6 times faster by applying 2 basic principles.
CSS complexity: it's complicated
There's lots of places in CSS to have complexity, but we tend to focus on selectors most of the time. Let's have a look at other places too.