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.

Provide an example about how to provide a custom order

See original GitHub issue

Hi! I have a small question regarding the function that can be passed to order option. Now, as mentioned in the documentation:

Provide the name of one of the built-in sort orders or a comparison function that is passed to (Array.sort). This function receives two declaration names and is expected to return -1, 0 or 1 depending on the wanted order.

I think that Is pretty clear, however I have hard time figure out how to to do this mainly because I don’t know Js, and maybe some peoples can be in my situation too.

It wouldn’t be useful to include an example in the readme.md on how to do this?

Thank you very much! 🙏

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ghostcommented, May 28, 2020

Yes, working, and it is pretty clear! I think that this can bee a good example to include in the documentation, maybe adding another property to the array:

const postcss = require('postcss');
const cssDeclarationSorter = require('css-declaration-sorter');

const myOrder = ['margin', 'border', 'padding'];

const myCompareFunction = (a, b) => myOrder.indexOf(a) - myOrder.indexOf(b);

postcss([cssDeclarationSorter({order: myCompareFunction})])
  .process('a { padding: 0; border: 0; margin: 0; }')
  .then(result =>
    console.log(result.css === 'a { margin: 0; border: 0; padding: 0 }')
  );
1reaction
ghostcommented, May 26, 2020

👋, I want to provide a custom order for sort my CSS properties, as mentioned in the documentation is possibile with the order: option, but I had hard time figure out how to do this (I’m very begginer in js), for that It will be very useful to provide an example of how to to this (maybe I am not the only who don’t well js, and also It will be probably a small time saver for all).

Thank you very much!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sort data using a custom list - Microsoft Support
In the ribbon, click Data > Sort. In the Sort popup window, in the Sort by drop-down, choose the column on which you...
Read more >
How to create a custom sort when a regular sort won't do in ...
On the Home tab, click Sort in the Editing group and click Custom Sort. On the Data tab, click Sort in the Sort...
Read more >
Sort a Column with a Custom Order in Power BI - RADACAD
In this post, I am going to show you how to do a custom sort order for a column in Power BI. Sample...
Read more >
How to Custom Sort in Excel - Tutorial - YouTube
Doing a custom sort allows you to specify the order in which your list will ... For example, you can create a custom...
Read more >
How to Custom Sort in SQL ORDER BY Clause?
Step 1: We are creating a Database. For this use the below command to create a database named GeeksforGeeks. Query: CREATE DATABASE ...
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